通过公式计算
cpp
* 波特率和采样点计算公式:
* tSeg1 = (S_SEG_1 + 2); tSeg2 = (S_SEG_2 + 1).
* BandRate = (SCR_CLK / (S_PRESC + 1) / ((S_SEG_1 + 2) + (S_SEG_2 + 1))), SCR_CLK 为CAN 模块源时钟
* SamplePoint = (tSeg1 / (tSeg1 + tSeg2)).
cpp
{0x0D, 0x04, 0x04, 0x3B}, // SEG_1, SEG_2, SJW, PRESC 50K, 75%
{0x0D, 0x04, 0x04, 0x1D}, // SEG_1, SEG_2, SJW, PRESC 100K, 75%
{0x0D, 0x04, 0x04, 0x02}, // SEG_1, SEG_2, SJW, PRESC 1M, 75%
{0x15, 0x06, 0x06, 0x00}, // SEG_1, SEG_2, SJW, PRESC 2M, 77%
{0x09, 0x03, 0x03, 0x00}, // SEG_1, SEG_2, SJW, PRESC 4M, 73%
{0x05, 0x02, 0x02, 0x00}, // SEG_1, SEG_2, SJW, PRESC 6M, 70%
{0x04, 0x01, 0x01, 0x00}, // SEG_1, SEG_2, SJW, PRESC 7.5M, 75%
把公式给文心一言
用文心一言验证50K配置
用文心一言验证100K配置
用文心一言验证7.5M配置
上述验证全部正确,计算60Mhz 5M 75%配置
cpp
60Mhz 5M 75%
{0x07, 0x02, 0x01, 0x00}
测试OK
上述验证全部正确,计算60Mhz 500K 80%配置
因为1M的分频在2,
并且普通CAN的分频也是2,
因此设置预分频2来计算配置(之前默认0计算结果都错的)
cpp
60Mhz 500K 80%
{0x1E, 0x07, 0x01, 0x02}
测试OK