STM32F103 微控制器 CAN 消息
我想知道是否有人熟悉 STM32f10x 微控制器?
如果是这样,我在配置 CAN 驱动程序时遇到了一些问题。我可以运行设置为loop_Back模式的演示代码,但我无法让Normal_Mode工作。
我通读了所有数据表,除了 CAN_MSR 寄存器中的 INAK 从未重置为 0 之外,所有内容都配置正确。如果需要,我可以提供更多详细信息,但首先我需要知道是否有人使用过 STM32F103 微控制器和 CAN 消息。
I am wondering if anyone is familiar with any STM32f10x micro-controllers?
If so, I am having some problems configuring a CAN driver. I can run the demo code, which is set to a loop_Back mode, but I cannot get Normal_Mode to work.
I read through all the data sheets, and everything is configured correctly except the INAK in the CAN_MSR register never resets to 0. I can provide more detail if needed, but first I need to know if there is someone who has worked with a STM32F103 microcontroller and CAN messages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将 Tx 引脚设置为 Out_PP,但应将其配置为备用功能。下面是我在 STM32F107 上的 CAN 初始化代码。我将其从现有项目中复制粘贴并删除,因此不需要某些内容(例如并非所有 GPIO 都需要启用)。另请注意,我使用重映射功能将 CAN Rx 和 Tx 引脚置于端口 D 上。
使用 72 MHz 时钟时,此配置将总线速度设置为 500 kbit/s。
发送消息可以这样完成:
接收是通过 IRQ 完成的:
You set the Tx pin as Out_PP, but it should be configured as Alternate Function instead. Below is my init code for CAN on an STM32F107. I copy-pasted and stripped it from an existing project so some stuff is not needed (like not all GPIOs need to be enabled). Also note I used the remap function to put the CAN Rx and Tx pins on port D.
This configuration sets the bus speed to 500 kbit/s when using a 72 MHz clock.
Sending a message can then be done like this:
Receiving is done via IRQ:
我曾使用过 STM32F103 微控制器,但我对 CAN 的唯一(少量)经验是启用它会导致 USB 无法工作。两个模块共享内存空间。因此,请确保禁用 USB 模块及其时钟(清除 RCC_APB1ENR 的位 23)。
I've worked with STM32F103 microcontrollers but my only (small) experience with CAN was that enabling it caused USB not to work. The two modules share a memory space. So make sure you disable the USB module and the clock to it (clear bit 23 of RCC_APB1ENR).