项目中需要用CAN总线进行通讯,看了LM3S9B92 Datasheet中相关内容,对于can的位速率设置不是太明白:
在Datasheet的Bit Time and Bit Rate一节这么写着:The length of the time quantum (tq), which is
the basic time unit of the bit time, is defined by the CAN controller's input clock (fsys) and the Baud
Rate Prescaler (BRP)
tq是位定时的基本单位。它由CAN控制器的输入时钟和波特率预分频所决定
tq = BRP / fsys
The fsys input clock is the system clock frequency as configured by the RCC or RCC2 registers
fsys也就是配置的系统时钟频率。
问题是此处没有对Baud Rate Prescaler做更多的解释。
假如我的系统时钟是50MHz,CAN波特率为1MHz,那么预分频应该是多少呢?是怎么算出来的呢?
我看了Driverlib中CANBitRateSet(unsigned long ulBase, unsigned long ulSourceClock,
unsigned long ulBitRate)这个函数,它里边的算法是:
系统时钟/位速率/ulCanBits,如果能够整除,算出的数字就是预分频,ulCanBits是4~19范围中的一个数字
我还是不太明白为什么这么算。
拿了几个不同的频率尝试算了一下,结果还确实和别人已经算出的TSEG2,TSEG1,SWJ和BRP一致。