标题: 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函数在初始串口三时,管脚是否正确!(手册中是B0和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.51hei.com/bbs/) Powered by Discuz! X3.1