NXP

S32K144 FlexCAN驱动SDK使用

2019-07-12 11:34发布

想利用NXP的S32K144MCU的FlexCAN模块实现一个简单的周期性发送CAN报文的功能,根据NXP官方提供的SDK。 1.首先需要对flexcan模块进行chus初始化,调用 FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0); 2.配置发信邮箱FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, 1, &dataInfo, 0x428); 3.打开中断 INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn); 4.调用 FLEXCAN_DRV_Send(INST_CANCOM1, 1, &dataInfo, 0x428, report_data); 接上cantest,发现无报文输出。检查配置,原demo程序中提供的配置代码: const flexcan_user_config_t canCom1_InitConfig0 = {
    .fd_enable = false,
    .pe_clock = FLEXCAN_CLK_SOURCE_SOSCDIV2,
    .max_num_mb = 2,
    .num_id_filters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
    .is_rx_fifo_needed = false,
    .flexcanMode = FLEXCAN_NORMAL_MODE,
    .payload = FLEXCAN_PAYLOAD_SIZE_8,
    .bitrate = {
        .propSeg = 7,
        .phaseSeg1 = 4,
        .phaseSeg2 = 1,
        .preDivider = 5,
        .rJumpwidth = 1
    },
    .bitrate_cbt = {
        .propSeg = 7,
        .phaseSeg1 = 4,
        .phaseSeg2 = 1,
        .preDivider = 5,
        .rJumpwidth = 1
    },
    .transfer_type = FLEXCAN_RXFIFO_USING_INTERRUPTS,
    .rxFifoDMAChannel = 0U
}; 查看S32K144RM,时钟源根据平台有所不同,将.pe_clock换成FLEXCAN_CLK_SOURCE_SYS,直接实现预期功能. 我的CAN收发器为UJA1044T,不适用CANFD功能。