欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 13892|回復: 10
打印 上一主題 下一主題
收起左側

安卓通過USBHost和stm32通信源代碼,包括安卓端和stm32端

  [復制鏈接]
跳轉到指定樓層
樓主
以前的學習結果,為了f429,現貢獻給大家,大家可以直接用我這程序當做安卓的串口調試助手,望大家喜歡,幫我加油頂貼啊!
給大家一個提示,這個安卓程序要求你的安卓設備支持Host功能,并且root,打開了usbhost權限哈。




  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  MCD Application Team
  5.   * @version V4.0.0
  6.   * @date    21-January-2013
  7.   * @brief   Virtual Com Port Demo main file
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   * [b]© COPYRIGHT 2013 STMicroelectronics[/b]
  12.   *
  13.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14.   * You may not use this file except in compliance with the License.
  15.   * You may obtain a copy of the License at:
  16.   *
  17.   *        [url]http://www.st.com/software_license_agreement_liberty_v2[/url]
  18.   *
  19.   * Unless required by applicable law or agreed to in writing, software
  20.   * distributed under the License is distributed on an "AS IS" BASIS,
  21.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22.   * See the License for the specific language governing permissions and
  23.   * limitations under the License.
  24.   *
  25.   ******************************************************************************
  26.   */


  27. /* Includes ------------------------------------------------------------------*/
  28. #include "hw_config.h"
  29. #include "usb_lib.h"
  30. #include "usb_desc.h"
  31. #include "usb_pwr.h"

  32. /* Private typedef -----------------------------------------------------------*/
  33. /* Private define ------------------------------------------------------------*/
  34. /* Private macro -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Extern variables ----------------------------------------------------------*/
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* Private functions ---------------------------------------------------------*/

  39. /*******************************************************************************
  40. * Function Name  : main.
  41. * Description    : Main routine.
  42. * Input          : None.
  43. * Output         : None.
  44. * Return         : None.
  45. *******************************************************************************/
  46. void delay_ms(unsigned int m)
  47. {
  48.         while(m--);
  49. }
  50. /*******************************************************************************
  51. * Function Name  : USB_To_USART_Send_Data.
  52. * Description    : send the received data from USB to the UART 0.
  53. * Input          : data_buffer: data address.
  54.                    Nb_bytes: number of bytes to send.
  55. * Return         : none.
  56. *******************************************************************************/
  57. void USB_To_USART_Send_Data(uint8_t* data_buffer, uint8_t Nb_bytes)
  58. {
  59. //在此處處理用戶數據接收。
  60. }
  61. int main(void)
  62. {
  63.   Set_System();
  64.   Set_USBClock();
  65.   USB_Interrupts_Config();
  66.   USB_Init();
  67.   while (1)
  68.   {
  69.                 delay_ms(50);
  70.                 USART_To_USB_Send_Data((unsigned char *)"Hello",6);
  71.   }
  72. }
  73. #ifdef USE_FULL_ASSERT
  74. /*******************************************************************************
  75. * Function Name  : assert_failed
  76. * Description    : Reports the name of the source file and the source line number
  77. *                  where the assert_param error has occurred.
  78. * Input          : - file: pointer to the source file name
  79. *                  - line: assert_param error line source number
  80. * Output         : None
  81. * Return         : None
  82. *******************************************************************************/
  83. void assert_failed(uint8_t* file, uint32_t line)
  84. {
  85.   /* User can add his own implementation to report the file name and line number,
  86.      ex: printf("Wrong parameters value: file %s on line %d", file, line) */

  87.   /* Infinite loop */
  88.   while (1)
  89.   {}
  90. }
  91. #endif

  92. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復制代碼

stm32f103虛擬串口程序.zip (368.2 KB, 下載次數: 73)

安卓端Host程序.zip (1.33 MB, 下載次數: 62)





分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:127084 發表于 2016-6-17 15:32 | 只看該作者
回復
求解,怎么實現的。從前看到有人用藍牙當串口就感覺很高端~

隨著USB的普及,串口的局限性,串口在產品設計中使用的越來越少,甚至在近幾年的一部分臺式機和絕大多數筆記本電腦都不帶串口接口了。不過老一代的設備還沒有淘汰,比如串口打印機,還有各種工業的控制器等等,它們還是用的串口接口,那么就導致了老設備在新計算機上面無法使用,為了解決這一尷尬情況,USB協會制定了CDC標準,即:用USB通信來模擬串口通信,在計算機端就會直接識別為串口,原來開發的軟件不用做任何修改就可以繼續使用。
回復

使用道具 舉報

板凳
ID:130178 發表于 2016-7-12 15:16 | 只看該作者
您好,這個很棒 謝謝
回復

使用道具 舉報

地板
ID:123924 發表于 2018-1-10 11:38 | 只看該作者
如何收藏??只好回復保存
回復

使用道具 舉報

5#
ID:282409 發表于 2018-2-5 17:30 | 只看該作者
51hei大小 發表于 2016-6-17 15:32
回復
求解,怎么實現的。從前看到有人用藍牙當串口就感覺很高端~

可以直接使用USB轉串口芯片,比如CH340來實現,CH340也是支持安卓系統的,接上就可以直接使用,給安卓手機擴展出一個串口來。
還有一種應用方式是安卓手機作為設備端,需要使用到USB 安卓HOST芯片,可以參考CH559這類單片機來做,也就是單片機的USB做主機,安卓的USB做設備,這樣通信。
回復

使用道具 舉報

6#
ID:135990 發表于 2018-9-11 17:25 | 只看該作者
需要使用otg線嗎
回復

使用道具 舉報

7#
ID:184314 發表于 2019-6-11 15:18 | 只看該作者
支持一下,剛好再看這方面的
回復

使用道具 舉報

8#
無效樓層,該帖已經被刪除
9#
ID:434018 發表于 2019-6-17 12:58 | 只看該作者
It is very good!Thanks!
回復

使用道具 舉報

10#
ID:434018 發表于 2019-6-17 16:50 | 只看該作者
It is a good reference.Thanks!
回復

使用道具 舉報

11#
ID:734898 發表于 2020-4-22 15:46 來自觸屏版 | 只看該作者
在小米5 MIUI8 安卓6.0上,以及紅米k20pro MIUI11 安卓10上,都是打開之后直接閃退,提示拔出了usb設備。。。連接的時候也的確是彈出了應用請求的,不知道是我單片機的問題還是安卓版本不兼容
回復

使用道具 舉報

12#
無效樓層,該帖已經被刪除
13#
ID:1014633 發表于 2022-3-31 16:22 | 只看該作者
學藝一下 難得看待
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表