Hi i have problems with CAN1 configuration (CAN0 works fine).
I have this code with PC10 and PC11 pins are connected to PCAN-USB
void peri_clock_gating (void) { /* Configure gating/enabling peripheral(CAN) clocks */
MC_ME.RUN_PC[0].R = 0x00000000; /* gate off clock for all RUN modes */
MC_ME.RUN_PC[1].R = 0x000000FE; /* config. peri clock for all RUN modes */
MC_ME.PCTL[70].B.RUN_CFG = 0x1; /* FlexCAN 0: select peri. cfg. RUN_PC[1] */
MC_ME.PCTL[71].B.RUN_CFG = 0x1; /* FlexCAN 1: select peri. cfg. RUN_PC[1] */
}
void readCanBus1(unsigned int *id, unsigned char *buf,unsigned int len,unsigned int *outLen)
{
uint8_t j;
uint32_t __attribute__ ((unused)) dummy;
while (CAN_1.IFLAG1.B.BUF4TO1I != 8) {};
*id = CAN_1.MB[4].ID.B.ID_STD;
*outLen = CAN_1.MB[4].CS.B.DLC;
if (*outLen>len)
{
*outLen=len;
}
for (j=0; j<(*outLen); j++) {
buf[j] = CAN_1.MB[4].DATA.B[j];
}
dummy = CAN_1.TIMER.R;
CAN_1.IFLAG1.R = 0x00000010;
}
void writeCanBus1(unsigned int id, unsigned char *buf,unsigned int len)
{
uint8_t i;
CAN_1.MB[0].CS.B.IDE = 0;
CAN_1.MB[0].ID.B.ID_STD = id;
CAN_1.MB[0].CS.B.RTR = 0;
CAN_1.MB[0].CS.B.DLC = len;
for (i=0; i<len; i++) {
CAN_1.MB[0].DATA.B[i] = buf[i];
}
CAN_1.MB[0].CS.B.SRR = 1;
CAN_1.MB[0].CS.B.CODE =0xC;
}
void initCanBus1()
{
int i;
CAN_1.MCR.B.MDIS = 1;
CAN_1.CTRL1.B.CLKSRC=0;
CAN_1.MCR.B.MDIS = 0;
while (!CAN_1.MCR.B.FRZACK) {}
CAN_1.CTRL1.R = 0x04DB0086;
for (i=0; i<96; i++) {
CAN_1.MB[i].CS.B.CODE = 0;
}
//TX
CAN_1.MB[0].CS.B.CODE = 8;
//RX
CAN_1.MB[4].CS.B.IDE = 0;
CAN_1.MB[4].ID.B.ID_STD = 0x666;
CAN_1.MB[4].CS.B.CODE = 4;
CAN_1.RXMGMASK.R = 0;//0x1FFFFFFF;
SIUL2.MSCR[42].B.SSS = 1; /* Pad PC10: Source signal is CAN1_TX */
SIUL2.MSCR[42].B.OBE = 1; /* Pad PC10: Output Buffer Enable */
SIUL2.MSCR[42].B.SRC = 3; /* Pad PC10: Maximum slew rate */
SIUL2.MSCR[43].B.IBE = 1; /* Pad PC11: Enable pad for input - CAN1_RX */
SIUL2.IMCR[701-512].B.SSS = 3; /* CAN1_RX: connected to pad PC11 */
CAN_1.MCR.R = 0x0000003F;
while (CAN_1.MCR.B.FRZACK & CAN_1.MCR.B.NOTRDY) {}
}
Also i try send data between CAN0 and CAN1, it doesn't work. I suppose i have some problem with configuration CAN1
Could you help me?
I know CAN1 doesn't have termination resistor. I tried connected CAN0, CAN1 and PCAN-USB parallels
Thank you
Hi,
I'm just wondering how did you connected CAN 1? Did you use external CAN transceiver connected by wires? There's CAN transceiver only for CAN 0 on this board.
Regards,
Lukas
Hi Lukas,
What does this mean. "There's CAN transceiver only for CAN 0 on this board."
According datasheet eight FlexCAN.
I have connected PB0 - PC10 - CAN-H PCAN-USB and PB1 - PC11 - CAN-L PCAN-USB
Hi,
yes, there are 8 CAN modules. But one thing is CAN module, second thing is CAN transceiver defined by ISO 11898-2.
First link and picture I found on the web:
https://can-newsletter.org/assets/files/ttmedia/raw/778ff25c6a48bbd0d67b4eee94ea11ea.pdf
This is what you need. Only a few MCUs have CAN transceiver implemented directly on the chip (like some of our 16bit S12 devices).
There's TJA1044GT on CAN 0 as you can see in the schematic.
TJA1044 | High-speed CAN transceiver with Standby mode | NXP
PCAN-USB also includes high speed transceiver. It's not possible to connect CAN signals without the transceiver.
Regards,
Lukas
Hi Lukas,
I have checked schematic my board, it's surprise for me.
Thank you for information.