cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot change CAN Baud on the fly - STM32F103C8T6

Cde M.1
Associate II

Hi, I'm developing an CAN to USB converter, this converter needs to change the baud rate of the CAN when the user sends an determined message via UART.

The Prescaler, TimeSeg1, TimeSeg2 are all configured correctly for the baud rate I desire, as example:

 

 

      hcan.Init.Prescaler = 100;
      hcan.Init.TimeSeg1  = CAN_BS1_15TQ;
      hcan.Init.TimeSeg2  = CAN_BS2_2TQ;
 
In the example above, I choose the baud rate to be in 20kbps, when the command is sent the values are correctly stored, but checking with the osciloscope I noticed that the baud rate didn't change.
 
The steps that im using are:
 
    HAL_CAN_Stop(&hcan);
    HAL_CAN_MspDeInit(&hcan);
    
    hcan.Init.Prescaler = 100;
    hcan.Init.TimeSeg1  = CAN_BS1_15TQ;
    hcan.Init.TimeSeg2  = CAN_BS2_2TQ;
    HAL_CAN_MspInit(&hcan);
    HAL_CAN_Start(&hcan);
 
Is there something that I'm missing with this routine?
 
Values in hcan before sending the baud rate change
CdeM1_0-1697816846474.png

 Values of hcan after sending baud rate change

CdeM1_1-1697816921680.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

>>Is there something that I'm missing with this routine?

Wouldn't HAL_CAN_Init() be the function to be calling? This would then presumably call HAL_CAN_MspInit(), a routine you supply to configure the clocks, pins, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

>>Is there something that I'm missing with this routine?

Wouldn't HAL_CAN_Init() be the function to be calling? This would then presumably call HAL_CAN_MspInit(), a routine you supply to configure the clocks, pins, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Lead III

Call HAL_CAN_DeInit first. Change your baud rate. Then call HAL_CAN_Init then HAL_CAN_Start

 

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.
Cde M.1
Associate II

@Karl Yamashita @Tesla DeLorean Thank you so much! I noticed it just a few moments after posting this topic. But anyway, that was exactly the problem. Thank you so muuuuch!!