Hi,
I tried with the FlexCAN for the CAN 0 and 1, its working fine in S32K146 EVB.
But parallelly using the 2 uart's in FreeRTOS, facing some issue.
so, trying to configure the CAN with interrupt and call back (same as LPUART example), didn't find any example for CAN interrupt.
configured interrupt and callback not working. seems missing some API calls.
Kindly provide some example for the interrupt configurations and API's.
Thanks in Advance.
#include <stdint.h>
#include <stdbool.h>
#include "Cpu.h"
/*Set information about the data to be TX or RX*/
flexcan_data_info_t dataInfo =
{
.msg_id_type = FLEXCAN_MSG_ID_STD,
.data_length = 8,
.fd_enable = false,
.fd_padding = 0U,
.enable_brs = false,
.is_remote = false
};
//Message Box Index
#define mb_idx_0 0
#define mb_idx_1 1
#define mb_idx_2 2
#define mb_idx_3 3
//Message ID
#define msg_id_0 1
#define msg_id_1 2
#define msg_id_2 3
#define msg_id_3 4
flexcan_msgbuff_t recvMsg;
void Can_Callback(uint8_t instance,flexcan_event_type_t eventType,uint32_t buffIdx,flexcan_state_t *flexcanState)
{
switch(eventType)
{
case FLEXCAN_EVENT_RX_COMPLETE:
if(mb_idx_1 == buffIdx)
{
FLEXCAN_DRV_Receive(INST_CANCOM1,mb_idx_1,&recvMsg);
}
break;
case FLEXCAN_EVENT_TX_COMPLETE:
break;
default:
break;
}
}
void flexcan0_ErrorCallback(uint8_t instance, flexcan_event_type_t eventType,flexcan_state_t *flexcanState)
{
volatile uint32_t error;
(void)flexcanState;
(void)instance;
switch(eventType)
{
case FLEXCAN_EVENT_ERROR:
error = FLEXCAN_DRV_GetErrorStatus(INST_CANCOM1);
if(error&0x4) // if BOFFINT was set
{
// abort TX MB, after bus off recovery message is not send
FLEXCAN_DRV_AbortTransfer(INST_CANCOM1,mb_idx_0);
}
break;
default:
break;
}
}
int main(void)
{
uint8_t SendBuffer[8] = {0};
bool i = 0;
CLOCK_SYS_Init(g_clockManConfigsArr,CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr,CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/*Initialize FlexCAN driver.*/
FLEXCAN_DRV_Init(INST_CANCOM1,&canCom1_State,&canCom1_InitConfig0);
/*Configure a Tx Message Buffer.*/
FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, mb_idx_0, &dataInfo, msg_id_0);
/*Configure a Rx Message Buffer.*/
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, mb_idx_1, &dataInfo, msg_id_1);
/*Receives a CAN frame into a configured message buffer.*/
FLEXCAN_DRV_Receive(INST_CANCOM1,mb_idx_1,&recvMsg);
/*Install a callback function for the IRQ handler.*/
FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1,(flexcan_callback_t)Can_Callback,NULL);
FLEXCAN_DRV_InstallErrorCallback(INST_CANCOM1, (flexcan_error_callback_t)flexcan0_ErrorCallback, (void*)NULL);
INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn);
INT_SYS_SetPriority(CAN0_ORed_0_15_MB_IRQn,1);
while(1)
{
OSIF_TimeDelay(1000);
SendBuffer[3] = 0xff;
FLEXCAN_DRV_Send(INST_CANCOM1,mb_idx_0,&dataInfo,msg_id_0,SendBuffer);
}
}
Hi Senlent,
Sorry for the delayed response, we having some delay in the HW modification.
I will test it and let you know if any details required.
Thanks for your reply.