Interrupt on Receiving CAN FD S32k144

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

Interrupt on Receiving CAN FD S32k144

Jump to solution
1,316 Views
12914A
Contributor III

Hi,
i would ask if there's any example for CAN FD Interrupt without SDK.

I've configured IMASK1, is there anything else I must do?

I tested it with canoe and send a CAN FD Message. But it says Tx Error (Bit Error and NAK Error)

 

Hope anyone can help

 

Sandra

0 Kudos
Reply
1 Solution
1,290 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Sandra1

I made a demo base on "S32K144_Project_CanFd" which is provided in S32 DS For Arm V2.2.

1.set MB4 interrupt mask in FLEXCAN0_init()

CAN0->IMASK1 |= CAN_IMASK1_BUF31TO0M(1 << 4);/*Enable MB 4 interrupt mask*/

2.Set NVIC and install  CAN0 IRQ Handler

void NVIC_init_IRQs (void)
{
	  S32_NVIC->ICPR[2] = 1 << (CAN0_ORed_0_15_MB_IRQn % 32);
	  S32_NVIC->ISER[2] = 1 << (CAN0_ORed_0_15_MB_IRQn % 32);
	  S32_NVIC->IP[CAN0_ORed_0_15_MB_IRQn] = 0xA0;
}

void CAN0_ORed_0_15_MB_IRQHandler(void)
{
    if ((CAN0->IFLAG1 >> 4) & 1) {  /* If CAN 0 MB 4 flag is set (received msg), read MB4 */
      FLEXCAN0_receive_msg();      /* Read message */
      rx_msg_count++;               /* Increment receive msg counter */

      if (rx_msg_count == 10) {   /* If 1000 messages have been received, */
        PTD->PTOR |= 1<<16;         /*   toggle output port D16 (Green LED) */
        rx_msg_count = 0;           /*   and reset message counter */
      }

      FLEXCAN0_transmit_msg();     /* Transmit message using MB0 */
    }
}

Senlent_0-1721109138585.png

 

View solution in original post

0 Kudos
Reply
1 Reply
1,291 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Sandra1

I made a demo base on "S32K144_Project_CanFd" which is provided in S32 DS For Arm V2.2.

1.set MB4 interrupt mask in FLEXCAN0_init()

CAN0->IMASK1 |= CAN_IMASK1_BUF31TO0M(1 << 4);/*Enable MB 4 interrupt mask*/

2.Set NVIC and install  CAN0 IRQ Handler

void NVIC_init_IRQs (void)
{
	  S32_NVIC->ICPR[2] = 1 << (CAN0_ORed_0_15_MB_IRQn % 32);
	  S32_NVIC->ISER[2] = 1 << (CAN0_ORed_0_15_MB_IRQn % 32);
	  S32_NVIC->IP[CAN0_ORed_0_15_MB_IRQn] = 0xA0;
}

void CAN0_ORed_0_15_MB_IRQHandler(void)
{
    if ((CAN0->IFLAG1 >> 4) & 1) {  /* If CAN 0 MB 4 flag is set (received msg), read MB4 */
      FLEXCAN0_receive_msg();      /* Read message */
      rx_msg_count++;               /* Increment receive msg counter */

      if (rx_msg_count == 10) {   /* If 1000 messages have been received, */
        PTD->PTOR |= 1<<16;         /*   toggle output port D16 (Green LED) */
        rx_msg_count = 0;           /*   and reset message counter */
      }

      FLEXCAN0_transmit_msg();     /* Transmit message using MB0 */
    }
}

Senlent_0-1721109138585.png

 

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1908515%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EInterrupt%20on%20Receiving%20CAN%20FD%20S32k144%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1908515%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3CBR%20%2F%3Ei%20would%20ask%20if%20there's%20any%20example%20for%20CAN%20FD%20Interrupt%20without%20SDK.%3C%2FP%3E%3CP%3EI've%20configured%20IMASK1%2C%20is%20there%20anything%20else%20I%20must%20do%3F%3C%2FP%3E%3CP%3EI%20tested%20it%20with%20canoe%20and%20send%20a%20CAN%20FD%20Message.%20But%20it%20says%20Tx%20Error%20(Bit%20Error%20and%20NAK%20Error)%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EHope%20anyone%20can%20help%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESandra%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1909410%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Interrupt%20on%20Receiving%20CAN%20FD%20S32k144%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1909410%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%40%3CA%20id%3D%22link_5%22%20class%3D%22lia-link-navigation%20lia-page-link%20lia-user-name-link%22%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F232799%22%20target%3D%22_self%22%20aria-label%3D%22View%20Profile%20of%20Sandra1%22%3E%3CSPAN%20class%3D%22%22%3ESandra1%3C%2FSPAN%3E%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EI%20made%20a%20demo%20base%20on%20%22S32K144_Project_CanFd%22%20which%20is%20provided%20in%20S32%20DS%20For%20Arm%20V2.2.%3C%2FP%3E%0A%3CP%3E1.set%20MB4%20interrupt%20mask%20in%26nbsp%3BFLEXCAN0_init()%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3ECAN0-%26gt%3BIMASK1%20%7C%3D%20CAN_IMASK1_BUF31TO0M(1%20%26lt%3B%26lt%3B%204)%3B%2F*Enable%20MB%204%20interrupt%20mask*%2F%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E2.Set%20NVIC%20and%20install%26nbsp%3B%20CAN0%20IRQ%20Handler%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3Evoid%20NVIC_init_IRQs%20(void)%0A%7B%0A%09%20%20S32_NVIC-%26gt%3BICPR%5B2%5D%20%3D%201%20%26lt%3B%26lt%3B%20(CAN0_ORed_0_15_MB_IRQn%20%25%2032)%3B%0A%09%20%20S32_NVIC-%26gt%3BISER%5B2%5D%20%3D%201%20%26lt%3B%26lt%3B%20(CAN0_ORed_0_15_MB_IRQn%20%25%2032)%3B%0A%09%20%20S32_NVIC-%26gt%3BIP%5BCAN0_ORed_0_15_MB_IRQn%5D%20%3D%200xA0%3B%0A%7D%0A%0Avoid%20CAN0_ORed_0_15_MB_IRQHandler(void)%0A%7B%0A%20%20%20%20if%20((CAN0-%26gt%3BIFLAG1%20%26gt%3B%26gt%3B%204)%20%26amp%3B%201)%20%7B%20%20%2F*%20If%20CAN%200%20MB%204%20flag%20is%20set%20(received%20msg)%2C%20read%20MB4%20*%2F%0A%20%20%20%20%20%20FLEXCAN0_receive_msg()%3B%20%20%20%20%20%20%2F*%20Read%20message%20*%2F%0A%20%20%20%20%20%20rx_msg_count%2B%2B%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F*%20Increment%20receive%20msg%20counter%20*%2F%0A%0A%20%20%20%20%20%20if%20(rx_msg_count%20%3D%3D%2010)%20%7B%20%20%20%2F*%20If%201000%20messages%20have%20been%20received%2C%20*%2F%0A%20%20%20%20%20%20%20%20PTD-%26gt%3BPTOR%20%7C%3D%201%26lt%3B%26lt%3B16%3B%20%20%20%20%20%20%20%20%20%2F*%20%20%20toggle%20output%20port%20D16%20(Green%20LED)%20*%2F%0A%20%20%20%20%20%20%20%20rx_msg_count%20%3D%200%3B%20%20%20%20%20%20%20%20%20%20%20%2F*%20%20%20and%20reset%20message%20counter%20*%2F%0A%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20FLEXCAN0_transmit_msg()%3B%20%20%20%20%20%2F*%20Transmit%20message%20using%20MB0%20*%2F%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Senlent_0-1721109138585.png%22%20style%3D%22width%3A%20739px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Senlent_0-1721109138585.png%22%20style%3D%22width%3A%20739px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F288689iEC089D9E9FAAC789%2Fimage-dimensions%2F739x213%3Fv%3Dv2%22%20width%3D%22739%22%20height%3D%22213%22%20role%3D%22button%22%20title%3D%22Senlent_0-1721109138585.png%22%20alt%3D%22Senlent_0-1721109138585.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E