This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F280049的driverlib中的CAN_setBitRate()函数有bug

Other Parts Discussed in Thread: C2000WARE

版本:C2000Ware_1_00_06_00

函数原型:

extern void
CAN_setBitRate(uint32_t base, uint32_t clock, uint32_t bitRate,
uint16_t bitTime);

driverlib的例程,路径C2000Ware_1_00_06_00\driverlib\f28004x\examples\can

里面调用方法如下,其中DEVICE_SYSCLK_FREQ=100e6,希望设置的波特率为500kbps

    CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);

实际上这样设置出来的波特率为521kbps,误差超过4%,完全是不可接受的,也完全无法与其它500kbps的CAN节点通讯。

我分析以后发现问题出在函数中brp计算上,上面的例子中,brp实际值应该是12.5,然而整形计算会去尾到12,即brp=12,直接导致误差超过4%

//
// Calculate bit timing values
//
brp = (uint16_t)(clock/(bitRate * bitTime));
tPhase = bitTime - (tSync + tProp);

请TI工作人员确认一下,如果属实及时反馈给负责这部分代码的员工,尽快修复。或者直接去掉该函数,直接用CAN_setBitTiming()函数就可以了。