2023-05-16 05:57 AM - edited 2023-11-20 05:20 AM
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?
Which 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?
Solved! Go to Solution.
2023-05-25 02:19 AM
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
2023-05-18 05:00 AM
2023-05-18 01:54 PM - edited 2023-11-20 05:21 AM
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.
The 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);
}
}
2023-05-25 02:19 AM
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