Problem about MPC5744P FlexCAN on S32DS

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

Problem about MPC5744P FlexCAN on S32DS

Jump to solution
1,210 Views
hityouxinxin
Contributor II

Hello,

I have a problem when I build my project using S32DS.I want to use the FlexCAN module to receive multiple data and process the messages in the interrupt,but I'm failed.The ProcessorExpert only provide the following function prototypes which seems to be useful.

void FLEXCAN_DRV_InstallEventCallback(uint8_t instance,
flexcan_callback_t callback,
void *callbackParam);‍‍‍

And I use it in my code,here like this:

static void ReceiveCANData(uint32_t mailbox, uint32_t messageId,
 flexcan_msgbuff_t * data_buf_struct, uint32_t len)
{
 /*configure the data Info*/
 flexcan_data_info_t dataInfo =
 { .data_length = len, .msg_id_type = FLEXCAN_MSG_ID_STD };

 /*configure the RXMb*/
 FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, mailbox, &dataInfo, messageId);
 /*Install the callback function*/
 FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, Callback,data_buf_struct);
 /*Receive data for the specified ID using a specific mailbox*/
 while(FLEXCAN_DRV_Receive(INST_CANCOM1, mailbox, data_buf_struct) != STATUS_SUCCESS)
 {
 ;
 }


}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Then I called this function to receive three different messages.

int main(void)
{
 /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
 #ifdef PEX_RTOS_INIT
 PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
 #endif
 /*** End of Processor Expert internal initialization. ***/

 CANService();


 /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
 /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
 #ifdef PEX_RTOS_START
 PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
 #endif
 /*** End of RTOS startup code. ***/
 /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
 for(;;) {
 if(exit_code != 0) {
 break;
 }
 }
 return exit_code;
 /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}

void CANService(void)
{

 BoardInit();
 Set_Pit_100ms(); /*Use the PIT to send message from chip every 100ms*/
 InitCAN();

 /*receive three message*/
 ReceiveCANData(1, 0x101, &test1,7);
 ReceiveCANData(5, 0x105, &test2, 7);
 ReceiveCANData(6, 0x106, &test3, 7);
}

But when I tested my code, there were some bugs.Here's my test code.

static void Callback(uint8_t instance,
 flexcan_event_type_t eventType, uint32_t buffIdx,
 flexcan_state_t *flexcanState)
{
 /*Passing parameters with flexcanState,the parameter is the message buffer*/
 flexcan_msgbuff_t * poninter_to_buf_struct = flexcanState ->callbackParam;
 /*Define an array to receive data*/
 uint8_t data1[8] = {0};
 /*Assign values to arrays*/
 int i = 0;
 for (;i < poninter_to_buf_struct ->dataLen; i++)
 {
 data1 [i] = poninter_to_buf_struct ->data[i];
 }
 /*Processing received data*/
 switch (eventType)
 {
 case FLEXCAN_EVENT_RX_COMPLETE:
 switch (buffIdx)
 {
 case 1:
 /*When receiving the data of the corresponding bufIdx,
 * the chip will use the mailbox 2 to send the data with
 * the ID what 102, and the content is the received data,
 *because the function FLEXCAN_DRV_ConfigTxMb() Configured to receive
 *the specified ID using a specific mailbox
 */
 BSW_SendCANData(2, 0x102, data, 7);
 BSW_ReceiveCANData(1, 0x101,
 &test1, 7);
 break;
 case 5:
 BSW_SendCANData(3, 0x103, data, 7);
 BSW_ReceiveCANData(5, 0x105, &test2, 7);
 break;
 case 6:
 BSW_SendCANData(4, 0x104, data, 7);
 BSW_ReceiveCANData(6, 0x106, &test3, 7);
 break;
 default:
 break;
 }

 break;
 case FLEXCAN_EVENT_TX_COMPLETE:
 break;
 default:
 break;
 }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The result is an error as shown below.

20181029225937.png

The expected result is that when the chip receives the ID101 data, it should send the ID101 data back with ID102.The result was a mess.The ID102 returns the data of ID106 and ID103 returns the ID101's data.

I want to know how this problem occurs, how to deal with it, what should be the correct way to use interrupt processing to receive messages?

Thank you,

You.

Tags (3)
0 Kudos
1 Solution
825 Views
hityouxinxin
Contributor II

The problem has been solved,my code logic has a problem.

FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, Callback,data_buf_struct);

It will always pass the last buff to the callback function.

*Passing parameters with flexcanState,the parameter is the message buffer*/
 flexcan_msgbuff_t * poninter_to_buf_struct = flexcanState ->callbackParam

I hope it will help others who have the same question.

View solution in original post

0 Kudos
1 Reply
826 Views
hityouxinxin
Contributor II

The problem has been solved,my code logic has a problem.

FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, Callback,data_buf_struct);

It will always pass the last buff to the callback function.

*Passing parameters with flexcanState,the parameter is the message buffer*/
 flexcan_msgbuff_t * poninter_to_buf_struct = flexcanState ->callbackParam

I hope it will help others who have the same question.

0 Kudos