陈万垒 发表于 2016-11-30 15:21:50

STM32F407的CAN通信,选择扩展格式发送怎么设置

RT,现在标准格式能发送,在发送结构体CanTxMsg
typedef struct
{
uint32_t StdId;/*!< Specifies the standard identifier.
                        This parameter can be a value between 0 to 0x7FF. */

uint32_t ExtId;/*!< Specifies the extended identifier.
                        This parameter can be a value between 0 to 0x1FFFFFFF. */

uint8_t IDE;   /*!< Specifies the type of identifier for the message that
                        will be transmitted. This parameter can be a value
                        of @ref CAN_identifier_type */

uint8_t RTR;   /*!< Specifies the type of frame for the message that will
                        be transmitted. This parameter can be a value of
                        @ref CAN_remote_transmission_request */

uint8_t DLC;   /*!< Specifies the length of the frame that will be
                        transmitted. This parameter can be a value between
                        0 to 8 */

uint8_t Data; /*!< Contains the data to be transmitted. It ranges from 0
                        to 0xFF. */
} CanTxMsg;有一位是IDE,是选择扩展帧还是标准帧发送,但是我把这一位置1了,还是发送的标准帧,请问下其他地方还要设置吗?


陈万垒 发表于 2016-11-30 17:12:23

已解决!
官方库发送扩展帧的函数错误,改一下就好了      hcan->Instance->sTxMailBox.TIR |= ((hcan->pTxMsg->ExtId << 3U) | \
                                                hcan->pTxMsg->IDE | \
                                                hcan->pTxMsg->RTR);
手册里是这样写的
位 31:21 STID/EXID:标准标识符或扩展标识符 (Standard identifier or extended identifier) 标准标识符或扩展标识符的 MSB(取决于 IDE 位的值)。 位 20:3 EXID:扩展标识符 (Extended identifier) 扩展标识符的 LSB。
控制器区域网络 (bxCAN) RM0090
636/1284 文档 ID 018909 第 4 版
CAN 邮箱数据长度控制和时间戳寄存器 (CAN_TDTxR) (x=0..2) CAN mailbox data length control and time stamp register
当邮箱未处于空状态时,该寄存器的所有位均为写保护状态。 偏移地址:0x184、0x194、0x1A4 复位值:0xXXXX XXXX
         
         
位 2 IDE:标识符扩展 (Identifier extension) 此位用于定义邮箱中消息的标识符类型。 0:标准标识符。 1:扩展标识符。 位 1 RTR:远程发送请求 (Remote transmission request) 0:数据帧 1:遥控帧 位 0 TXRQ:发送邮箱请求 (Transmit mailbox request) 由软件置 1,用于请求发送相应邮箱的内容。 邮箱变为空后,此位由硬件清零。

所以应该是extid左移3位, 然后IDE左移两位 , RTR左移一位 再拼一起就OK 了。

妈蛋,浪费我一下午时间。。。

陈万垒 发表于 2016-11-30 17:14:44

固件库版本cubef4V1.13.0

leo121_3006061 发表于 2016-11-30 19:17:29

厉害哦:)

makc 发表于 2016-11-30 21:00:55




陈万垒 发表于 2016-12-1 09:30:53

makc 发表于 2016-11-30 21:00


soga,原来有宏定义,如果用宏定义那就没错
页: [1]
查看完整版本: STM32F407的CAN通信,选择扩展格式发送怎么设置