Hi everyone!
I am currently transporting the can_pal_S32K148 example to an FreeRTOS based project.
I created two different tasks, one for sending the other one for receiving
Sending in a separate Task is no problem.
But now i want to do some receiving.
Everything is fine as long as i use the Lines from the example project in my receive task:
/* Define receive buffer */
can_message_t recvMsg;
/* Start receiving data in RX_MAILBOX. */
CAN_Receive(&can_pal1_instance, RX_MAILBOX, &recvMsg);
/* Wait until the previous FlexCAN receive is completed */
while(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY);
/* Check the received message ID and payload */
if((recvMsg.data[0] == LED0_CHANGE_REQUESTED) &&
recvMsg.id == RX_MSG_ID)
{
/* Toggle output value LED0 */
PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));
}
else if((recvMsg.data[0] == LED1_CHANGE_REQUESTED) &&
recvMsg.id == RX_MSG_ID)
{
/* Toggle output value LED1 */
PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));
}
If i send a data everything works without a problem.
But with this option I have the whole Idle time inside the while loop waiting for the state to get "unbusy", which I don't want to have.
So i tried to change it to something like this:
/* Start receiving data in RX_MAILBOX. */
CAN_Receive(&can_pal1_instance, RX_MAILBOX, &recvMsg);
/* Wait until the previous FlexCAN receive is completed */
if(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY)
{
return;
}
Because if i call this cyclic it should be the same like with the while, right?
Which works fine, if i send CAN Message with the wrong IDs.
But as soon as I send the CAN Message with the wright ID, for example 2 as done in the can_pal_S32K148 example, the whole system stops and I end up being stuck in the FreeRtos Watchdog.
I decreased the calling cycle to 1ms, which is the fastes cycle I can adjust at the FreeRTOS.
Is there any way to avoid this kind of error?
Or do I have to extract the CAN_GetTransferStatus function to some kind of IRQ and communicate with a flag that the can is not longer busy?
Best regards
Christof
Hi Christof,
I didn't see where you defined callback function for CAN_Receive by using CAN_InstallEventCallback. Would you please refer the S32K144_CAN_PAL_SamplePrj_Basic_TxRx_ID_FiltersConfig_SDKRTM3P0 example in S32K1xx SDK FlexCAN sample projects to demonstrate its basic and advanced features?
It will show you how to use callback instead of use CAN_GetTransferStatus.
Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi Robin!
I ported the sample code to my freeRTOS project and it works fine.
The key is to only call the CAN_Receive only once and wait until all data are there.
Thx for the support.
Regards
Christof
Hi Robin,
I didn't know that i have to use the function CAN_InstallEventCallback because it was not used at the sample project.
Thx for the tip, i will look into it.
Will come back to you when i have results.
Regards
Christof