2006-06-09 12:20 AM
2006-06-07 03:50 AM
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?2006-06-07 04:42 AM
What are the Tseg paramaters that you are using?
2006-06-07 08:13 PM
at 48MHz:
u16 CanTimings[] = { // value bitrate NTQ TSEG1 TSEG2 SJW BRP CAN_TIMING(11, 4, 4, 30), //100kBit CAN_TIMING(11, 4, 4, 24), //125kBit CAN_TIMING( 4, 3, 3, 24),//250kBit CAN_TIMING(13, 2, 1, 6), //500kBit CAN_TIMING( 4, 3, 1, 6)} //1MBit At 2MHz: u16 CanTimings2M[] = { // value bitrate NTQ TSEG1 TSEG2 SJW BRP CAN_TIMING( 8, 3, 1, 1), //100kBit CAN_TIMING(11, 4, 4, 1), //125kBit CAN_TIMING( 4, 3, 3, 1), //250kBit The RS232->CAN dongle I use is setup with these values: t_prop=8 t_seg1=8 t_seg3=3 t_sjw =1 And then adjusted with the TQ-Scaler for the appropiate bitrate.2006-06-07 09:49 PM
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 that2006-06-09 12:20 AM
great CAN_TIMING( 5, 4, 3, 2) seems to work!
My problem was that I made a mistake when calculating the total number of TQ. Thank you very much for your help!