Hi,
Recently, I came into contact with S32K platform. The loopback test using CAN_PAL peripheral failed. It has been several days.Please give me a suggestion.The code is simple, as follows:
In DEBUG, the program gets stuck in "while(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY);
#include "Cpu.h"
#include "callbacks.h"
#define TX_MAILBOX (1UL)
#define TX_MSG_ID (1UL)
#define RX_MAILBOX (0UL)
#define RX_MSG_ID (1UL)
volatile int exit_code = 0;
can_message_t recvMsg;
void BoardInit(void)
{
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
}
void CAN1_Init(void)
{
CAN_Init(&can_pal1_instance, &can_pal1_Config0);
can_buff_config_t RX_buffCfg = {
.enableFD = false,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};
/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &RX_buffCfg, RX_MSG_ID);
can_buff_config_t TX_buffCfg = {
.enableFD = false,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};
/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigTxBuff(&can_pal1_instance, TX_MAILBOX, &TX_buffCfg);
);
}
/*
* @brief Function which configures the LEDs and Buttons
*/
int main(void)
{
BoardInit();
CAN1_Init();
can_message_t sendMsg = {
.cs=0U,
.id = RX_MSG_ID,
.data[0] = 0x05,
.length = 1U
};
while(1)
{
CAN_Send(&can_pal1_instance,TX_MAILBOX,&sendMsg);
while(CAN_GetTransferStatus(&can_pal1_instance, TX_MAILBOX) == STATUS_BUSY);
CAN_Receive(&can_pal1_instance,RX_MAILBOX,&recvMsg);
while(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY);
}
Hi,
try to move CAN_ConfigTxBuff into main function. But rather reorganize code little bit, e.g as below
void CAN1_Init(void)
{
CAN_Init(&can_pal1_instance, &can_pal1_Config0);
can_buff_config_t RX_buffCfg = {
.enableFD = false,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};
/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &RX_buffCfg, RX_MSG_ID);
}
/*
* @brief Function which configures the LEDs and Buttons
*/
int main(void)
{
BoardInit();
CAN1_Init();
can_message_t sendMsg = {
.cs=0U,
.id = RX_MSG_ID,
.data[0] = 0x05,
.length = 1U
};
CAN_Receive(&can_pal1_instance,RX_MAILBOX,&recvMsg);
can_buff_config_t TX_buffCfg = {
.enableFD = false,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};
/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigTxBuff(&can_pal1_instance, TX_MAILBOX, &TX_buffCfg);
CAN_Send(&can_pal1_instance,TX_MAILBOX,&sendMsg);
while(1)
{
while(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY);
CAN_Receive(&can_pal1_instance,RX_MAILBOX,&recvMsg);
for(int i=0;i<200000;i++){};
/* Toggle output value LED0 */
PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));
CAN_Send(&can_pal1_instance,TX_MAILBOX,&sendMsg);
}
BR, Petr
Thanks for your advice! I achieved it after move CAN_ConfigTxBuff into main function!
But I don't understand why.can you tell me? thanks a lot.
Hi,
I only found the TX buffer is not properly filled in Send function then, but don't know exact reason.
BR, Petr
Thanks,
Best Regards.