当前位置:   article > 正文

stm32F103 can总线使用HAL库例程_stm32f103 hal can

stm32f103 hal can

以下是一个基于STM32F103芯片的CAN总线例程示例,仅供参考:

首先需要在MCU上配置CAN硬件和时钟,可以使用STM32CubeMX工具自动生成代码。

接下来是CAN总线初始化和发送CAN消息的程序

  1. #include "stm32f10x.h"
  2. #include "stm32f10x_can.h"
  3. void CAN_Configuration(void)
  4. {
  5. CAN_InitTypeDef CAN_InitStructure;
  6. CAN_FilterInitTypeDef CAN_FilterInitStructure;
  7. RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
  8. CAN_StructInit(&CAN_InitStructure);
  9. CAN_InitStructure.CAN_TTCM = DISABLE;
  10. CAN_InitStructure.CAN_ABOM = DISABLE;
  11. CAN_InitStructure.CAN_AWUM = DISABLE;
  12. CAN_InitStructure.CAN_NART = ENABLE;
  13. CAN_InitStructure.CAN_RFLM = DISABLE;
  14. CAN_InitStructure.CAN_TXFP = ENABLE;
  15. CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
  16. // CAN bus speed is set to 500 kbps in this example
  17. CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
  18. CAN_InitStructure.CAN_BS1 = CAN_BS1_12tq;
  19. CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;
  20. CAN_InitStructu
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/512805
推荐阅读
相关标签
  

闽ICP备14008679号