CAN1 not working in S32K144

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

CAN1 not working in S32K144

Jump to solution
4,074 Views
vairam_s32
Contributor II

Hi All,

   I want to implement the CAN1 in the evaluation board. I tested CAN0 code with example program it's working. For CAN1, i change the CAN0 pointer to CAN1, pin assignment and MB nos. But i was not working. I was observing the CAN pin PTA12/PTA13 with oscilloscope, the pin was not toggling as like CAN0 pins. Below is my code

void CANT_Init(uint16 bps)
{
     uint32_t i=0;

   PCC->PCCn[PCC_PORTA_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clock for PORTE */
   PCC->PCCn[PCC_FlexCAN1_INDEX] |= PCC_PCCn_CGC_MASK; /* CGC=1: enable clock to FlexCAN0 */
   PORTA->PCR[12] |= PORT_PCR_MUX(3); /* Port A12: MUX = ALT3, CAN1_RX */
   PORTA->PCR[13] |= PORT_PCR_MUX(3); /* Port A13: MUX = ALT3, CAN1_TX */

   CAN1->MCR |= CAN_MCR_MDIS_MASK; /* MDIS=1: Disable module before selecting clock */
   CAN1->CTRL1 &= ~CAN_CTRL1_CLKSRC_MASK; /* CLKSRC=0: Clock Source = oscillator (8 MHz) */
   CAN1->MCR &= ~CAN_MCR_MDIS_MASK; /* MDIS=0; Enable module config. (Sets FRZ, HALT)*/
   while (!((CAN1->MCR & CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT)) {}
      /* Good practice: wait for FRZACK=1 on freeze mode entry/exit */
   CAN1->CTRL1 = 0x00DB0006; /* Configure for 500 KHz bit time */
      /* Time quanta freq = 16 time quanta x 500 KHz bit time= 8MHz */
      /* PRESDIV+1 = Fclksrc/Ftq = 8 MHz/8 MHz = 1 */
      /* so PRESDIV = 0 */
      /* PSEG2 = Phase_Seg2 - 1 = 4 - 1 = 3 */
      /* PSEG1 = PSEG2 = 3 */
      /* PROPSEG= Prop_Seg - 1 = 7 - 1 = 6 */
      /* RJW: since Phase_Seg2 >=4, RJW+1=4 so RJW=3. */
      /* SMP = 1: use 3 bits per CAN sample */
      /* CLKSRC=0 (unchanged): Fcanclk= Fosc= 8 MHz */
   for(i=0; i<64; i++ ) { /* CAN0: clear 32 msg bufs x 4 words/msg buf = 128 words*/
   CAN1->RAMn[i] = 0; /* Clear msg buf word */
   }
   for(i=0; i<16; i++ ) { /* In FRZ mode, init CAN0 16 msg buf filters */
   CAN1->RXIMR[i] = 0xFFFFFFFF; /* Check all ID bits for incoming messages */
   }
   CAN1->RXMGMASK = 0x1FFFFFFF; /* Global acceptance mask: check all ID bits */
   CAN1->RAMn[ 4*MSG_BUF_SIZE + 0] = 0x04000000; /* Msg Buf 4, word 0: Enable for reception */
         /* EDL,BRS,ESI=0: CANFD not used */
         /* CODE=4: MB set to RX inactive */
         /* IDE=0: Standard ID */
         /* SRR, RTR, TIME STAMP = 0: not applicable */
   CAN1->RAMn[ 4*MSG_BUF_SIZE + 1] = 0x14440000; /* Msg Buf 4, word 1: Standard ID = 0x111 */
         /* PRIO = 0: CANFD not used */
   CAN1->MCR = 0x0000001F; /* Negate FlexCAN 1 halt state for 32 MBs */
   while ((CAN1->MCR && CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT) {}
         /* Good practice: wait for FRZACK to clear (not in freeze mode) */
   while ((CAN1->MCR && CAN_MCR_NOTRDY_MASK) >> CAN_MCR_NOTRDY_SHIFT) {}
         /* Good practice: wait for NOTRDY to clear (module ready) */

}

void FLEXCAN1_transmit_msg(void) { /* Assumption: Message buffer CODE is INACTIVE */
   CAN1->IFLAG1 = 0x00000001; /* Clear CAN 0 MB 0 flag without clearing others*/
   CAN1->RAMn[ 0*MSG_BUF_SIZE + 2] = 0xA5112233; /* MB0 word 2: data word 0 */
   CAN1->RAMn[ 0*MSG_BUF_SIZE + 3] = 0x44556677; /* MB0 word 3: data word 1 */
   CAN1->RAMn[ 0*MSG_BUF_SIZE + 1] = 0x15540000; /* MB0 word 1: Tx msg with STD ID 0x555 */
   CAN1->RAMn[ 0*MSG_BUF_SIZE + 0] = 0x0C400000 | 8 <<CAN_WMBn_CS_DLC_SHIFT; /* MB0 word 0: */
         /* EDL,BRS,ESI=0: CANFD not used */
         /* CODE=0xC: Activate msg buf to transmit */
         /* IDE=0: Standard ID */
         /* SRR=1 Tx frame (not req'd for std ID) */
         /* RTR = 0: data, not remote tx request frame*/
         /* DLC = 8 bytes */
}

I have referred the below post also

CAN1 Does not work with example code 

CAN1 not work,CAN0 is ok 

https://community.nxp.com/message/995504?commentID=995504#comment-995504 

Here, i have attached the application note containing example code .

Kindly resolve the issue , thanks in advance.

Regards,

Vairamani.V

Tags (1)
1 Solution
3,721 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

to test CAN1 with onboard transceiver you need not to remove R137 & R136, it is enough to not configure PTE4 & PTE5  (thus pins stay in high-Z) and simply connect PTE4-PTA12 and PTE5-PTA13. I tried to modify demo SDK project for CAN1 and I am able to see message on CANH/CANL.

In your case if ESR1 shows zero, it says the module is not synchronized to the bus at all, no communication can be done, most probably RX line is held low by SBC. It seems SBC is no longer in default state (Forced normal) when transceiver is enabled. From the factory the SBC comes in this Forced Normal mode and no special init is needed for the SBC and its CAN transceiver. If the SBC leaves this init mode (by clearing FNMC bit of the SBC configuration control register) then the SBC init must be done. Or restoring factory preset values can be performed as mentioned in SBC datasheet.

Also discussed herehttps://community.nxp.com/message/1047022#comment-1105605

  

BR, Petr

View solution in original post

7 Replies
62 Views
Anilpatil_SasvaAuto
Contributor I
Hello vairam_s32,
Could you please provide the Working CAN0 code for S32K144EVB?
If possible, please provide the procedure o of the CAN 0 setting with EVB.
0 Kudos
3,720 Views
vairam_s32
Contributor II

Hi,

thanks for reply,

   I have not connected the transceiver to CAN1 and as per your suggestion, i transmitted the message by shorting the PTA12 & PTA13, then got some waveform as similar to shorting CAN0 TX & Rx pins.

   So, In evaluation board I disconnected the CAN0 from the transceiver by removing the R137 & R136, then connected the CAN1 pins to on-board transceiver. But still i'm not getting the can message from the output of CAN transceiver. I have connected the 12V supply too.

By debugging, we checked the ECR and ESR1 register value, it was ZERO.

 

Kindly provide your suggestion to fix the issue.

-Vairamani.V

0 Kudos
3,722 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

to test CAN1 with onboard transceiver you need not to remove R137 & R136, it is enough to not configure PTE4 & PTE5  (thus pins stay in high-Z) and simply connect PTE4-PTA12 and PTE5-PTA13. I tried to modify demo SDK project for CAN1 and I am able to see message on CANH/CANL.

In your case if ESR1 shows zero, it says the module is not synchronized to the bus at all, no communication can be done, most probably RX line is held low by SBC. It seems SBC is no longer in default state (Forced normal) when transceiver is enabled. From the factory the SBC comes in this Forced Normal mode and no special init is needed for the SBC and its CAN transceiver. If the SBC leaves this init mode (by clearing FNMC bit of the SBC configuration control register) then the SBC init must be done. Or restoring factory preset values can be performed as mentioned in SBC datasheet.

Also discussed herehttps://community.nxp.com/message/1047022#comment-1105605

  

BR, Petr

2,940 Views
abhijithshankaren
Contributor I

So the only hardware change to be done to make CAN1 work properly with on-board Transceiver is to 
   1. Connect a jumper from PTE4 to PTA12.

   2. And another jumper from PTE5 to PTA13, is that correct ?
   

And 

Kindly share, if we have any direct method without changing the hardware or connecting any jumpers to configure the CAN 1 to onboard Transceiver.

Regards
Abhijith 

0 Kudos
3,722 Views
jaures168
Contributor II

i use s23k144 -64pin and add can0,can2 not work,

i don't know why?

i had change package to 64pin and xtal 20mhz.

use cal_pal_s32k144

0 Kudos
3,722 Views
vairam_s32
Contributor II

Hi,

Thanks for your help..

We reset the SBC as given in the link.

Now, CAN1 is working.

-Vairamani.V

0 Kudos
3,722 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

the feedback can be the same as on threads you mentioned.

Do you have transceiver connected to CAN1 (PTA12/PTA13 pins)? If not you can try to connect PTA12/PTA13 together to see it is properly initialized. Once you transmit message you should see it on this external loopback connection.

If not most probably pin config is wrong, but it looks correct. Also you can check ECR and ESR1 registers.

BR, Petr