標題: STM32F103CT6 ADC(DMA)USB通訊(HID模式) 3串口通信調試完整工程代碼 [打印本頁]

作者: youfulan    時間: 2019-1-23 08:48
標題: STM32F103CT6 ADC(DMA)USB通訊(HID模式) 3串口通信調試完整工程代碼
在公司做的第一個項目,希望能幫助需要這些東西的人。
主要是USB通信我調試了4天,用的STM最新的USB固件,我們公司有老員工的USB通信實列因為太老我沒用直接自己寫的。
電路板是淘寶買的C8T6核心板,最簡單的好像是10塊錢

單片機源程序如下:
  1. #include "hw_config.h"
  2. #include "usb_lib.h"
  3. #include "usb_pwr.h"
  4. #include "stm32f10x_it.h"
  5. #include "usart.h"
  6. #include "myusb.h"
  7. #include "adc.h"

  8. #define LED  PBout(12)
  9. uint32_t  nMSGNum=0;
  10. uint32_t        pMSG[64];
  11. uint8_t                nCurIndex=0;
  12. void outputdebug()
  13. {
  14. #ifdef DEBUG
  15.         uint32_t  nMSGNumCur=nMSGNum;
  16.         uint8_t nStopIndex=nMSGNumCur%64;
  17.         uint8_t nCount=0;
  18.         for(;nCurIndex!=nStopIndex;)
  19.         {
  20.                         nCount=nCurIndex<nStopIndex?(nStopIndex-nCurIndex):(nStopIndex+64-nCurIndex);
  21.                
  22.                         printf("%d\t%x\n",nMSGNumCur-nCount,pMSG[nCurIndex]);
  23.        
  24.                         nCurIndex=(nCurIndex+1)%64;
  25.         }
  26. #endif
  27. }

  28. int main(void)
  29. {
  30.         u8 bLed=0;   
  31.   Set_System();       
  32.         delay_init();
  33.   while (1)
  34.   {
  35.                 HW_Proc();
  36.                 outputdebug();
  37.                 bLed=bLed==0?1:0;
  38.                 LED=bLed;
  39.                 delay_ms(100);
  40.   }
  41. }
復制代碼

所有資料51hei提供下載:
STM32_HIDBattery.7z (193.9 KB, 下載次數: 274)



作者: youfulan    時間: 2019-1-23 08:53
1 ADC用的是DMA方式
2 USB用的是HID
3 一共3個串口其中串口1 是調試打印用的 用重寫Printf函數,嗲用printf函數會在串口1輸出信息
4 使用了RTC模塊用來定時中斷
作者: lele5211314    時間: 2019-3-4 17:46
功能可以啊
作者: 墨葬玉    時間: 2019-4-3 15:04
你好!代碼中有一點疑問!就是usart.c文件下的usart_init函數在初始串口三時,管腳是否正確。ㄊ謨灾惺荁0和B11,代碼中是(B9,B10)
作者: chhui123456    時間: 2021-7-2 14:12
通信速率怎么樣
作者: chhui123456    時間: 2021-7-2 14:19
收藏先,有空下載測試一下通信速率
作者: chui0123    時間: 2021-7-2 16:37
貌似不行哦,無法識別
作者: 單片機愛好者223    時間: 2021-7-14 20:07
暫時用不到。。。留下腳印
作者: yangbin2314078    時間: 2021-9-7 15:45
識別不到啊,main函數中也沒看到USB相關的初始化
作者: yangbin2314078    時間: 2021-9-7 15:47
看到USB初始化了,不過電腦無法識別,啥都沒顯示
作者: yangbin2314078    時間: 2021-9-7 15:53
電腦識別了,剛開始沒識別居然是因為沒插USB插頭
作者: Duzuiya    時間: 2021-9-13 16:10
暫時打個斷點  希望以后用到能夠找到
作者: Liangzhongjie    時間: 2021-9-18 21:17
還沒學習到,在大佬這留個評論
作者: tarchen    時間: 2024-10-21 11:30
謝謝分享,有空看看了.
作者: wenhuaxiao    時間: 2024-10-22 09:57
USB   HID




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1