XMC4200 switch CAN baudrate at runtime

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hello, everyone.

I have a question about XMC4200 CAN bit timing.
Could you please guide me, how can I switch it at runtime?
Specially, if my hardware is already initialized by DAVE's init functions.
Namely, I need to reinit my CANs from 83333 to 500000.
Here is my code, which does not work:
void CANxUpdateBaudrate( const CAN_NODE_t* handle, uint32_t baudrate )
{
//Disable CAN node participation in CAN traffic
XMC_CAN_NODE_SetInitBit(handle->node_ptr);
//Function to configure the baud rate based on UI configuration
//Keep sample_point and sjw as they was before, update baudrate.
CAN_NODE_ConfigBaudrate(handle, baudrate, handle->baudrate_config->sample_point, handle->baudrate_config->sjw);
//Enable CAN node participation in CAN traffic
XMC_CAN_NODE_ResetInitBit(handle->node_ptr);
}


This is usage example:
CANxUpdateBaudrate( &CAN1, 500000 );


NOTE: my CANs works fine at 83333, I have to update
  CAN1_BitTimeConfig.baudrate = 83333;
CAN2_BitTimeConfig.baudrate = 83333;

in main.c before DAVE_Init(), because GUI does not allow to set CAN's baudrate less than 100k.
It also works fine at 500000 baud, if inited by DAVE_Init().

Now the method, which I use to check how it works:
I add 2 MOs on my CANs: CAN1, CAN2, one for receive and transmit respectively.
Then I add Rx and Tx events on needed MOs and link them to corresponding INTERRUPTs.
When I do so, and enable these INTERRUPTs, they start to occur and receive CAN frames as I expect.
I'm sending packets every 10 ms and all of them are received.


This works fine with settings inited by GUI both at 83333 and 500000 bauds.
But do not work when I try to switch baudrate. At least INTERRUPTs do not occurs.

For example, I'm starting to send infinit number of frames at 500000 baud/s, and while CAN initialized at 83333 it obviously does not receive anything. But when CAN switches to 500000 it still does not receive anything.
0 Likes
1 Reply
User18841
Level 1
Level 1
Hi SashaBelykh, I am trying todo something similar, and like you, I am experiencing an issue with the CAN_NODE_ConfigBaudrate(..) API.
Have you come across a solution?
0 Likes