s32k144 can interrupt recieve

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

s32k144 can interrupt recieve

2,020 Views
victor_song_171
Contributor III

I want to use can interrupt to recieve data. when send can data ,it can enter interrupt,but when recieve can data via USB-CAN ,it not work and can not enter interrupt. Code below:

void CAN_IRQ_Callback(uint8_t instance, flexcan_event_type_t eventType,flexcan_state_t *flexcanState)
{
if(eventType == FLEXCAN_EVENT_RXFIFO_COMPLETE)flag_rx_can = true;
else if(eventType == FLEXCAN_EVENT_TX_COMPLETE)flag_tx_can = true;
}

int main()

{

..........

INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn);
INT_SYS_SetPriority(CAN0_ORed_0_15_MB_IRQn,0U);

FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);

FLEXCAN_DRV_ConfigRxFifo(INST_CANCOM1,FLEXCAN_RX_FIFO_ID_FORMAT_A,&can_id_table);

FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, CAN_IRQ_Callback, (void *)NULL);

FLEXCAN_DRV_Receive(INST_CANCOM1,0U,&can_rx_buff);

   while(1)

   {

      if(flag_rx_can ){......}

      else if(flag_tx_can ){......}

   }

}

0 Kudos
6 Replies

1,512 Views
constantinrazva
NXP Employee
NXP Employee

Hello victor_song_171819@163.com‌,

I have a few questions to get a better understanding: did you debug the code and it did not enter CAN_IRQ_Callback function, or did you check just the running application and see it did not execute whatever code it was inside if(flag_rx_can)? I don't see exactly how the flags are defined, but to be sure the application works as expected, declare them as volatile. Another question I have is regarding the canCom1_InitConfig0 needed by the initialization function of fcan - what settings are you using? And one more thing - I think that MB0 (the one you are using on the receive function) should be configured - using FLEXCAN_DRV_ConfigRxMb - before calling the Receive function.

You should probably ask this question in the S32K community as there you'll get an answer from the guys that wrote the driver for flexcan - here we handle questions regarding MATLAB/Simulink and our toolboxes.

Hope this helps,

Razvan.

0 Kudos

1,512 Views
victor_song_171
Contributor III

First of all ,thanks for your asistance.

Did 'FLEXCAN_DRV_ConfigRxMb' function config the mailbox or message buffer? I confused . Is Mb short for Mailbox or Message buffer?

I debug the code ,when push button to transmit can frame,it can enter the callback function. but not work for recieve data from CANoe.

the flag_rx_can is volatile bool-type data.

const flexcan_user_config_t canCom1_InitConfig0 = {
.fd_enable = false,
.pe_clock = FLEXCAN_CLK_SOURCE_SOSCDIV2,
.max_num_mb = 16,
.num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.is_rx_fifo_needed = false,
.flexcanMode = FLEXCAN_NORMAL_MODE,
.payload = FLEXCAN_PAYLOAD_SIZE_8,
.bitrate = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.bitrate_cbt = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.transfer_type = FLEXCAN_RXFIFO_USING_INTERRUPTS,
.rxFifoDMAChannel = 0U
};

0 Kudos

1,512 Views
constantinrazva
NXP Employee
NXP Employee

Hello victor_song_171819@163.com‌,

The SDK comes with documentation - accessible from {SDK_ROOT_DIR}\doc\Start_here.html. Here you can go to Modules -> Controller Area Network with Flexible Data Rate (FlexCAN) -> FlexCAN Driver (navigate from the list on the left). You can find all DRV functions and some details & info. 

pastedImage_1.png

This is an example for the function that you are asking - when in doubt, you can double check with the documentation. 

The Mb refers to message buffer. The same goes for the FLEXCAN_DRV_Receive function - 2nd parameter, mb_idx, refers to the index of the message buffer.

Now for your settings - i think you need to enable RxFiFO from here (in red):

const flexcan_user_config_t canCom1_InitConfig0 = {
.fd_enable = false,
.pe_clock = FLEXCAN_CLK_SOURCE_SOSCDIV2,
.max_num_mb = 16,
.num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.is_rx_fifo_needed = true, <<< you had false here
.flexcanMode = FLEXCAN_NORMAL_MODE,
.payload = FLEXCAN_PAYLOAD_SIZE_8,
.bitrate = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.bitrate_cbt = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.transfer_type = FLEXCAN_RXFIFO_USING_INTERRUPTS,
.rxFifoDMAChannel = 0U
};

One more note, I'm not sure if you need the .bitrate_cbt - when you have can_fd disabled, .bitrate is where you declare the bitrate for standard frames; when you have can_fd enabled, in .bitrate you have bitrate for arbitration phase of FD frames and in .bitrate_cbt you have bitrate for data phase of FD frames.

You should try first just to enable can_fd (.is_rx_fifo_needed set to true). 

Kind regards,

Razvan.

0 Kudos

1,512 Views
victor_song_171
Contributor III

I just want CAN 2.0B, is that necessary to enable can_fd?

I am flesh to NXP's chip,so many thing is strange and unfamiliar .Is there any document for "How to design the code for CAN interrupt" or something ?

0 Kudos

1,512 Views
constantinrazva
NXP Employee
NXP Employee

Hello victor_song_171819@163.com‌,

It is not necessary to enable can_fd, but it is to enable RX FIFO if you want to use this feature.

.fd_enable = false, // You do not need this if you just want to use standard frames (no can fd)
.is_rx_fifo_needed = true, // You need this if you want to use RX FIFO

As for your other question, I am not aware of such a document, but you can find examples from the SDK. For more information you can ask on S32K  community - there you'll get more in depth answers about anything regarding the CAN drivers.

Kind regards,

Razvan.

1,512 Views
constantinrazva
NXP Employee
NXP Employee

And one more thing - what version of SDK are you using? We used to have a problem using the RxFIFO interrupts in an earlier version - I think it got fixed somewhere in 2.9.x so if you are using 2.9.x or 3.0.0 this should not be the problem - although it is always recommended to use the latest version. You can try and use 1 MB instead of RxFIFO and see if that is working just to be sure all the setup and configurations are ok and then upgrade the SDK (if you're using earlier versions).

Kind regards,

Razvan.

0 Kudos