Change baudrate CAN.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change baudrate CAN.

1,986 Views
lohrsistemas
Contributor IV

Is it possible to change the baudrate of the can with the application running? In one case, I need to change from 250k to 1M.

Thanks.

0 Kudos
3 Replies

1,625 Views
robertboys
Contributor IV

Hello

Changing the CAN frequency has been noted for not being a great idea.  It is a bit like self-modifying code, an intriguing idea but the most unexpected events will pop up unexpectedly to bite you.

CAN was really designed from the beginning to be fixed frequency.  I surely can see where this would be useful...but...

Petr is correct - if not done properly, there will be CAN errors with the threat of a CAN node(s) going bus-off and now you have to restart this - node(s) may go into limp-home mode and so on....so your system is no longer working normally...during this switch over time it can be really exciting for the developer....(like jumping out of an airplane with balky parachute).  CAN tools will have a difficult time tracking the change...

I know of only one company successfully doing this and this was with single-wire CAN and lower frequency (50K ?).  They are a big company with plenty of CAN experience and it seems to have worked.  There may be more examples I don't know about.

Switching frequency has a better chance of working in a closed system (all your own nodes) so you have a little more control over things.

Just my 2 cents...maybe others have additional knowledge.

Bob Boys

0 Kudos

1,625 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Yes, you can change the baudrate in runtime, but this must be done while module is in Freeze mode.

Also all other nodes must change its baudrate similarly during bus idle time, before communication is started again, otherwise bit errors will be detected and error frames will be sent on the bus.

BR, Petr

0 Kudos

1,625 Views
lohrsistemas
Contributor IV

Petr,

Thanks for your feedback.

I'm using the code below:

void FLEXCAN0_init(unsigned long baud) {
#define MSG_BUF_SIZE  4    /* Msg Buffer Size. (CAN 2.0AB: 2 hdr +  2 data= 4 words) */
      uint32_t   i=0;

      PCC->PCCn[PCC_FlexCAN0_INDEX] |= PCC_PCCn_CGC_MASK; /* CGC=1: enable clock to FlexCAN0 */
      CAN0->MCR |= CAN_MCR_MDIS_MASK;         /* MDIS=1: Disable module before selecting clock */
      CAN0->CTRL1 |= CAN_CTRL1_CLKSRC_MASK;  /* CLKSRC=1: The CAN engine clock source is  BUS_CLK (40MHz) */
      CAN0->MCR &= ~CAN_MCR_MDIS_MASK;        /* MDIS=0; Enable module config. (Sets FRZ, HALT)*/
      while (!((CAN0->MCR & CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT))  {}
                     /* Good practice: wait for FRZACK=1 on freeze mode entry/exit */
      if(baud==CAN_1M)
      {
          CAN0->CTRL1 = 0x03F90003; //0n47 at 60MHz
      }
      else
      {
          CAN0->CTRL1 = 0x0E790004; //0n47 at 60MHz
      }

[...]

}

When I first configure (250Mbaud), everything works, but when I reconfigure CAN (1Mbaud) with application running, my firmware never goes out of the while below:

      while (!((CAN0->MCR & CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT))  {}

I'm waiting for your answer.

Thanks.

0 Kudos