//CAN总线的波特率计算公式:波特率 = 1 / (时间段1 + 时间段2 + 1) / 时钟分频器 // =(42MHz/(6+3+1))/21=250000=250Kps if(BaudRate==5){ // 125Kbps hcan1.Init.Prescaler = 42; hcan1.Init.TimeSeg1 = CAN_BS1_6TQ;//时间段1 hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;//时间段2 } //CAN总线的波特率计算公式:波特率 = 1 / (时间段1 + 时间段2 + 1) / 时钟分频器 // =(42MHz/(6+1+1))/21=250000=250Kps if(BaudRate==6){// 250Kbps hcan1.Init.Prescaler = 21; hcan1.Init.TimeSeg1 = CAN_BS1_6TQ;//时间段1 hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;//时间段2 }根据这些规律写出其它常用CAN波特率配置
时间: 2023-12-17 07:02:45 浏览: 278
根据上述公式,以下是常用的CAN波特率配置:
1. 500Kbps: hcan1.Init.Prescaler = 10, hcan1.Init.TimeSeg1 = CAN_BS1_6TQ, hcan1.Init.TimeSeg2 = CAN_BS2_1TQ
2. 250Kbps: hcan1.Init.Prescaler = 21, hcan1.Init.TimeSeg1 = CAN_BS1_6TQ, hcan1.Init.TimeSeg2 = CAN_BS2_1TQ
3. 125Kbps: hcan1.Init.Prescaler = 42, hcan1.Init.TimeSeg1 = CAN_BS1_6TQ, hcan1.Init.TimeSeg2 = CAN_BS2_1TQ
4. 100Kbps: hcan1.Init.Prescaler = 42, hcan1.Init.TimeSeg1 = CAN_BS1_8TQ, hcan1.Init.TimeSeg2 = CAN_BS2_3TQ
5. 50Kbps: hcan1.Init.Prescaler = 84, hcan1.Init.TimeSeg1 = CAN_BS1_8TQ, hcan1.Init.TimeSeg2 = CAN_BS2_3TQ
6. 20Kbps: hcan1.Init.Prescaler = 210, hcan1.Init.TimeSeg1 = CAN_BS1_8TQ, hcan1.Init.TimeSeg2 = CAN_BS2_3TQ
注意:以上配置仅供参考,具体配置还需要根据实际情况进行调整。
阅读全文