I have to re-calculate the CAN bit timing which is implemented in the CAN library, as I switch the APB frequency between 48MHz and 2MHz (PLL off).
I've changed the baudrate prescaler as the library assumed 8MHz APB. In 48MHz all bitrates works 100k->1M bit. I test with a RS232->CAN dongle. When I change to 2MHz, I re-initialize with the same rates except the prescaler and 250K and 125K bit works correct, but I cannot get 100K bit to receive anything. I studied the reference manual and I cannot find a register that contains the Tprop segment. Does anybody know how to set this segment?
Calculate the required BRP(baud rate prescaler) for the clock frequency
BRP = (Clock frequency / number of Time quanter) / Required Baud rate so for a 4 meg clock with 10 times PLL (40M), using 16 time quanter if a baud rate of 250K is required PBR = ( 40000000 / 16 ) / 250000 = 10 the total number of time quanter is Tseg1 + Tseg2 + 1 for your 20M clock at 100kbit, i calculate your BPR to be 1.6666 you need to change the size of your time segments to get this to be a whole number, maybe try CAN_TIMING( 5, 4, 3, 2) or something, like that