cancel
Showing results for 
Search instead for 
Did you mean: 

SPC560P50L5 CAN Communication data rate calculation

MAli.6
Associate II

I am trying to write a code to send CAN messages using SPC560P50L5, I am trying to get idea from the SPC5 studio CAN Example but i am having difficulty understanding how to set bit rate since i am planning to set bit rate to 50000bits/s. I have gone through the data sheet and application notes?


_legacyfs_online_stmicro_images_0693W00000bkBy7QAE.pngWhich clock frequency is used when it is set to internal clock? Crystal(12MHz) or system clk (64MHz in clock tree), and while dividing the prescaler do i have to add 1 to it (1 + prescaler)?

Even if i use these setting with 12MHz crystal clock or 64MHz system clock i can't seem to get a full rounded bit rate i.e. 150000bits/s or 50000bits/s?

1 ACCEPTED SOLUTION

Accepted Solutions
MAli.6
Associate II

The issue is resolved now, but for anyone looking for information the steps are as follows:-

1- Enable the CAN

2- If use external clock is selected then the XOSC crystal is used to feed the clock to CAN else it is SYS CLK

3- Enable filter and enter the CAN ID of Receiver i.e. 0x07, the receiver is a must for a successful CAN communication

4- Timing is calculated as follows:-

if XOSC clock is 12M then 12/(1+pred)=12M if pred=0 and if pros=2+ pseg1 and pseg =3 and 3 then it equals resulting in 1Mbs

5- Both transmitter and receiver has to match in data rate and filter ID configure so transmitter and receiver can communication

View solution in original post

3 REPLIES 3
Giuseppe DI-GIORE
ST Employee

Hello,

have a look at this application note: AN5416

Regards.

MAli.6
Associate II

Hi,

Thanks for the reply, I have spent quite a bit time but CAN0TX pin is always high even if i try to send data, meaning it is in recessive mode.


_legacyfs_online_stmicro_images_0693W00000bkOaNQAU.pngThe example provided in SPC5 Studio works in loopback mode but if i disable loopback mode, no data is being transmitted, I try following AN5416, but SPC58 CAN setup is different,

Currently I am using SYS_CLK for CAN clock, which is 64MHz and dividing it by 7+1 meaning 8 generating 8MHz and then divide it by time quanta of 16 resulting 500Kbits/s.

No loopback mode is selected and then program the code in flash to eliminate any breaks but the TX pin stay high, also the RX is pulled high via advanced mode.

This is the part of example to that should send packets during transmission but it CANH and CANL never change and CAN0TXD pin always remain high

  txmsg.IDE = CAN_IDE_EXT;

  txmsg.EID = 0x8901234UL;

  while (can_lld_transmit(&CAND1, 1, &txmsg) == CAN_MSG_WAIT) {

  }

  /* Transmit Can message received by FIFO */

  txmsg.IDE = CAN_IDE_EXT;

  txmsg.EID = 0x70;

  while (can_lld_transmit(&CAND1, 2, &txmsg) == CAN_MSG_WAIT) {

}

  /* Transmit Can message received by mailbox */

  txmsg.IDE = CAN_IDE_STD;

  txmsg.SID = 0x11L;

  while (can_lld_transmit(&CAND1, 3, &txmsg) == CAN_MSG_WAIT) {

  }

/*

* Receives the RX CAN Message.

*/

  if (can_lld_receive(&CAND1, 1, &rxmsg) == CAN_MSG_OK) {

   pal_lld_togglepad(PORT_G, Led_D13);

  }

  osalThreadDelayMilliseconds(250UL);

 }

}

MAli.6
Associate II

The issue is resolved now, but for anyone looking for information the steps are as follows:-

1- Enable the CAN

2- If use external clock is selected then the XOSC crystal is used to feed the clock to CAN else it is SYS CLK

3- Enable filter and enter the CAN ID of Receiver i.e. 0x07, the receiver is a must for a successful CAN communication

4- Timing is calculated as follows:-

if XOSC clock is 12M then 12/(1+pred)=12M if pred=0 and if pros=2+ pseg1 and pseg =3 and 3 then it equals resulting in 1Mbs

5- Both transmitter and receiver has to match in data rate and filter ID configure so transmitter and receiver can communication