Closed pazi88 closed 3 years ago
By executing this function, you can find out the timing according to the CPU clock and CAN SPEED.
void setup() {
// initialize Serial
Serial.begin(115200);
// set CAN bit rate
initCanard(50*1000);
initCanard(100*1000);
initCanard(125*1000);
initCanard(250*1000);
initCanard(500*1000);
initCanard(1000*1000);
}
void initCanard(uint32_t speed)
{
Serial.print("speed=");
Serial.print(speed);
Serial.println();
CanardSTM32CANTimings timings;
//int result = canardSTM32ComputeCANTimings(HAL_RCC_GetPCLK1Freq(), 1000000, &timings);
int result = canardSTM32ComputeCANTimings(HAL_RCC_GetPCLK1Freq(), speed, &timings);
Serial.print("timings.bit_rate_prescaler=");
Serial.print(timings.bit_rate_prescaler);
Serial.println();
Serial.print("timings.bit_segment_1=");
Serial.print(timings.bit_segment_1);
Serial.println();
Serial.print("timings.bit_segment_2=");
Serial.print(timings.bit_segment_2);
Serial.println();
Serial.print("timings.max_resynchronization_jump_width=");
Serial.print(timings.max_resynchronization_jump_width);
Serial.println();
}
Great thanks! I also found this site which had working calculator. Once I figured out I need to use APB1 clock rate: http://www.bittiming.can-wiki.info/
Not really issue, but still. I would like to know how you have calculated the bit timings, so I could calculate those for other F4 boards too that have different clock frequency. Like F401 and F411