久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4207|回復: 5
收起左側

stm32f105例程 CAN500K USART_LED

[復制鏈接]
回帖獎勵 2 黑幣 回復本帖可獲得 2 黑幣獎勵! 每人限 1 次
ID:397541 發表于 2018-9-28 09:38 | 顯示全部樓層 |閱讀模式
stm32f105例程

單片機源程序如下:


  1. /*
  2.         CAN1
  3.         USART1

  4.     CAN波特率、收發器 配置見CAN.h

  5.         stm32f10x.h中修改了外部晶振值8MHz
  6.        

  7. */

  8. /* Includes ------------------------------------------------------------------*/
  9. #include "stm32f10x.h"
  10. #include "stm32f10x_rcc.h"
  11. #include "stm32f10x_flash.h"
  12. #include "stm32f10x_can.h"
  13. #include "usart.h"
  14. #include "CAN.h"
  15. #include <stdio.h>

  16. void RCC_Configuration(void);
  17. void LED_Config(void);
  18. void Delay(__IO uint32_t nCount);


  19. CanTxMsg TxMsg1={0xAB,0,CAN_ID_STD,CAN_RTR_DATA,8,{0xAB,0,0,0,0,0,0,0}};
  20. CanTxMsg TxMsg2={0xCD,0,CAN_ID_STD,CAN_RTR_DATA,8,{0xCD,0,0,0,0,0,0,0}};


  21. int main(void)
  22. {
  23.                           
  24.   /* System Clocks Configuration **********************************************/
  25.   RCC_Configuration();   
  26.   LED_Config();

  27.   // 串口配置                                                                                                               
  28.   USART_Configuration();

  29.   USART_STR(USART2,"++++++++++++++++++++++++\r\n");
  30.   USART_STR(USART2,"  CAN Study Board\r\n");
  31.   USART_STR(USART2,"++++++++++++++++++++++++\r\n");       
  32.                                                                                                                   
  33.                                                                                                   
  34.   // CAN1 配置
  35.   CAN1_Config(SET_CAN_SJW,SET_CAN_BS1,SET_CAN_BS2,SET_CAN_PRES);  
  36.                                                                                                               
  37.   Delay(2000);
  38.                                                          
  39.   // CAN2 配置
  40.   CAN2_Config(SET_CAN_SJW,SET_CAN_BS1,SET_CAN_BS2,SET_CAN_PRES);                                                                                          
  41.                                    
  42.                                                   
  43.   while (1)
  44.   {     
  45.           GPIO_ResetBits(GPIOC,GPIO_Pin_0);
  46.           GPIO_SetBits(GPIOC,GPIO_Pin_1);
  47.           GPIO_SetBits(GPIOC,GPIO_Pin_14);
  48.           GPIO_SetBits(GPIOC,GPIO_Pin_15);
  49.       Delay(5000);
  50.           Delay(5000);          
  51.           GPIO_SetBits(GPIOC,GPIO_Pin_0);
  52.           GPIO_ResetBits(GPIOC,GPIO_Pin_1);
  53.           GPIO_SetBits(GPIOC,GPIO_Pin_14);
  54.           GPIO_SetBits(GPIOC,GPIO_Pin_15);

  55.           CAN_SendData(CAN1,&TxMsg1);

  56.           Delay(5000);
  57.           Delay(5000);          
  58.           GPIO_SetBits(GPIOC,GPIO_Pin_0);
  59.           GPIO_SetBits(GPIOC,GPIO_Pin_1);
  60.           GPIO_ResetBits(GPIOC,GPIO_Pin_14);
  61.           GPIO_SetBits(GPIOC,GPIO_Pin_15);
  62.           Delay(5000);
  63.           Delay(5000);          
  64.           GPIO_SetBits(GPIOC,GPIO_Pin_0);
  65.           GPIO_SetBits(GPIOC,GPIO_Pin_1);
  66.           GPIO_SetBits(GPIOC,GPIO_Pin_14);
  67.           GPIO_ResetBits(GPIOC,GPIO_Pin_15);
  68.           Delay(5000);
  69.           Delay(5000);                                                                                       
  70.        
  71.           CAN_SendData(CAN2,&TxMsg2);                                                                                                                                     
  72.   }
  73. }


  74. void RCC_Configuration(void)
  75. {   
  76.   /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
  77.      initialize the PLL and update the SystemFrequency variable. */
  78.   SystemInit();
  79.                                                                                            
  80. }


  81. void Delay(__IO uint32_t nCount)
  82. {
  83.     uint8_t x;
  84.     for(; nCount != 0; nCount--)
  85.             for(x=0;x<100;x++);
  86. }

  87. void LED_Config(void)
  88. {
  89.   GPIO_InitTypeDef GPIO_InitStructure;

  90.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  91.   
  92.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_14|GPIO_Pin_15;                                  
  93.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  94.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  95.   GPIO_Init(GPIOC, &GPIO_InitStructure);                                         
  96. }


  97. #ifdef  USE_FULL_ASSERT

  98. /**
  99.   * @brief  Reports the name of the source file and the source line number
  100.   *   where the assert_param error has occurred.
  101.   * @param  file: pointer to the source file name
  102. ……………………

  103. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
stm32f105.rar (458.73 KB, 下載次數: 117)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

ID:418101 發表于 2018-10-31 12:15 | 顯示全部樓層
樓主你好,我用你的代碼,測試105r8 CAN時,發現發送的時候還是發不出去,在tx pin看不到波形,一直是高電平,打印transmit的返回值,發現mailbox值一直從1 2 3 4 4 4 后面就一直是4了,也就是從未發出去,樓主測試過嗎?
回復

使用道具 舉報

ID:191583 發表于 2019-1-29 14:30 | 顯示全部樓層
正在學習,謝謝提供的資料。
回復

使用道具 舉報

ID:158966 發表于 2019-7-30 09:49 | 顯示全部樓層
正在學習,謝謝提供的資料
回復

使用道具 舉報

ID:251047 發表于 2019-7-30 15:05 | 顯示全部樓層
多謝分享,哈哈哈
回復

使用道具 舉報

ID:320751 發表于 2020-9-7 21:17 | 顯示全部樓層
謝謝分享  學習一下 感恩付出
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品久久九 | 81精品国产乱码久久久久久 | 91免费高清 | 久草视频网站 | 天天干夜夜 | 人人澡人人射 | 国产一级电影在线 | 亚洲欧洲视频 | 亚洲一区二区久久 | 国产一二三视频在线观看 | 欧洲高清转码区一二区 | 热久色 | 久久久久久99 | av一级久久 | 国产精品福利视频 | 午夜影院免费体验区 | 成人精品一区二区三区中文字幕 | 欧美五月婷婷 | 涩涩视频网站在线观看 | 中午字幕在线观看 | 91精品国产美女在线观看 | 日本在线中文 | 欧美日韩在线看 | 在线免费观看视频你懂的 | av影音| 成人欧美一区二区三区1314 | 日韩快播电影 | 国产91视频播放 | 国产福利视频在线观看 | 久久精品91久久久久久再现 | 亚洲欧美国产一区二区三区 | 美女高潮网站 | 欧美日韩久久久 | 一区二区三区四区免费在线观看 | 精品福利在线 | 看羞羞视频免费 | 日韩在线精品 | 久久精品视频在线播放 | 在线免费看毛片 | 欧美精产国品一二三区 | 色播99 |