最近接触到S32K平台。使用 CAN_PAL 外围设备的环回测试失败。已经好几天了。请大家给个建议。代码很简单,如下:
- 在 DEBUG 中,程序卡在 " while(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY);
CAN_PAL
PIN_MUX
#include "Cpu.h"
#include "callbacks.h"
#define TX_MAILBOX (1UL)
#define TX_MSG_ID (1UL)
#define RX_MAILBOX (0UL)
#define RX_MSG_ID (1UL)
vola
tile 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);
}