Part Number: TMS320F28384D
Other Parts Discussed in Thread: C2000WARE
Dears
My customer 1st time to develop MCAN base on F28384, we expect to generate MCAN RX interrupt while RX BUFF receive new data, however now only can generate once interrupt then never happen interrupt again, we check the register status as below:
1, CPU enter MCAN 1st time RX interrupt function, check both MCAN interrupt flag and CPU PIE flag are set in register window
2, Firmware clear both MCAN interrupt flag and CPU PIE flag and confirm they turn to 0 in register window, then exit the interrupt function
3, Send CAN new data to the Bus, and confirm the RX BUFF receive the new data in register window
4, Check the MCAN interrupt flag is set again, and confirm the MCAN interrupt enable is set
5, however CPU never respond the MCAN interrupt function, check the CPU PIE flag is always 0 and will not set again
6, Other function interrupt can still continue work normal, indicate the CPU PIE should work without block
May I ask if we have example code for implement MCAN RX BUFF interrupt? Because I check it seem do not have such example in C2000WARE so far? I also attach customer code for MCAN configuration, or could you help review if customer code has some mistake?
#include "f28x_project.h"
#include "inc/hw_memmap.h"
#include "MCAN_Config.h"
#include "UDS_Para.h"
#include "hw_types.h"
#include "gpio.h"
#include "device.h"
#include "HW_Config.h"
void Init_MCAN(void)
{
MCAN_InitParams initParams;
MCAN_BitTimingParams bitTimes;
MCAN_MsgRAMConfigParams msgRAMConfigParams;
//
// Initialize MCAN Init parameters.
//
initParams.fdMode = 0x0U; // FD operation disabled.
initParams.brsEnable = 0x0U; // Bit rate switching for
//
// Initialize bit timings.
//
#if (CAN_BAUD_RATE == CAN_BR_500K)
bitTimes.nomRatePrescalar = 19U; // Nominal Baud Rate Pre-scaler.
bitTimes.nomTimeSeg1 = 14U; // Nominal Time segment before SP.
bitTimes.nomTimeSeg2 = 3U; // Nominal Time segment after SP.
bitTimes.nomSynchJumpWidth = 2U; // Nominal SJW Range.
#elif (CAN_BAUD_RATE == CAN_BR_250K)
bitTimes.nomRatePrescalar = 39U; // Nominal Baud Rate Pre-scaler.
bitTimes.nomTimeSeg1 = 14U; // Nominal Time segment before SP.
bitTimes.nomTimeSeg2 = 3U; // Nominal Time segment after SP.
bitTimes.nomSynchJumpWidth = 2U; // Nominal SJW Range.
#endif
//
// Initialize Message RAM Sections Configuration Parameters
//
msgRAMConfigParams.txStartAddr = MCAN_TX_BUFF_START_ADDR; // Tx Buffers Start Address.
msgRAMConfigParams.txBufNum = MCAN_TX_BUFF_SIZE; // Number of Dedicated Transmit Buffers.
msgRAMConfigParams.txBufMode = 0U;
msgRAMConfigParams.txBufElemSize = MCAN_ELEM_SIZE_8BYTES; // Tx Buffer Element Size.
msgRAMConfigParams.flssa = MCAN_STD_ID_FILT_START_ADDR; // Standard ID Filter List Start Address.
msgRAMConfigParams.lss = MCAN_STD_ID_FILTER_NUM;
// List Size: Standard ID.
#if (CAN_RXMODE == CAN_RXBUFFMODE)
msgRAMConfigParams.rxBufStartAddr = MCAN_RX_BUFF_START_ADDR; // Rx Buffer Start Address.
msgRAMConfigParams.rxBufElemSize = MCAN_ELEM_SIZE_8BYTES; // Rx Buffer Element Size.
#elif (CAN_RXMODE == CAN_RXFIFOMODE)
// FIFO Configuration Parameters
msgRAMConfigParams.rxFIFO0startAddr = MCAN_FIFO_0_START_ADDR; // Rx FIFO1 Start Address (748U).
msgRAMConfigParams.rxFIFO0size = MCAN_FIFO_0_NUM; // Number of Rx FIFO elements (1).
msgRAMConfigParams.rxFIFO0waterMark = MCAN_FIFO_0_WATERMARK; // Level for Rx FIFO 1 watermark interrupt (1).
msgRAMConfigParams.rxFIFO0OpMode = 1U; //FIFO Overwrite mode
msgRAMConfigParams.rxFIFO0ElemSize = MCAN_ELEM_SIZE_8BYTES; // Rx FIFO1 Element Size. RBDS field of MCAN_RXESC Register
#endif
//
// Wait for memory initialization to happen.
//
while(FALSE == MCAN_isMemInitDone(MCAN0_BASE))
{
}
//
// Put MCAN in SW initialization mode.
//
MCAN_setOpMode(MCAN0_BASE, MCAN_OPERATION_MODE_SW_INIT);
//
// Wait till MCAN is not initialized.
//
while (MCAN_OPERATION_MODE_SW_INIT != MCAN_getOpMode(MCAN0_BASE))
{}
//
// Initialize MCAN module.
//
MCAN_init(MCAN0_BASE, &initParams);
//
// Configure Bit timings.
//
MCAN_setBitTime(MCAN0_BASE, &bitTimes);
//
// Configure Message RAM Sections
//
MCAN_msgRAMConfig(MCAN0_BASE, &msgRAMConfigParams);
//
// Configure Standard ID filter element
//
SetMsgBox();
//
// Enable Interrupts.
//
// MCAN_enableIntr(MCAN0_BASE, MCAN_INTR_MASK_ALL, 1U);
MCAN_enableIntr(MCAN0_BASE, MCAN_IR_DRX_MASK, 1U);
// MCAN_enableIntr(MCAN0_BASE, MCAN_IR_RF0N_MASK, 1U);
// Uint32 LTempAx;
// LTempAx = MCAN_getIE(MCAN0_BASE); //DeBug
//
// Select Interrupt Line.
//
MCAN_selectIntrLine(MCAN0_BASE, MCAN_IR_DRX_MASK, MCAN_INTR_LINE_NUM_0);
//
// Enable Interrupt Line.
//
MCAN_enableIntrLine(MCAN0_BASE, MCAN_INTR_LINE_NUM_0, 1U);
//
// Take MCAN out of the SW initialization mode
//
MCAN_setOpMode(MCAN0_BASE, MCAN_OPERATION_MODE_NORMAL);
while (MCAN_OPERATION_MODE_NORMAL != MCAN_getOpMode(MCAN0_BASE))
{
}
}
void SetMsgBox(void)
{
int16 i;
Uint16 RxFiltNum = 0;
MCAN_StdMsgIDFilterElement RxMsg_Std;
MCAN_ExtMsgIDFilterElement RxMsg_Ext;
for(i = 0; i < MAX_ID_CNT; i++)
{
if(CanIdConfig[i].MsgBoxId < 32)
{
if(CanIdConfig[i].IsTxId == RX_ID)
{
if(CanIdConfig[i].IsExtId == STAND_ID)
{
#if (CAN_RXMODE == CAN_RXBUFFMODE)
RxMsg_Std.sfid2 = (0x1 << RxFiltNum); // Standard Filter ID 2.
RxMsg_Std.sfid1 = CanIdConfig[i].ID; // Standard Filter ID 1.
RxMsg_Std.sfec = 0x7U; // Store into Rx Buffer
#elif (CAN_RXMODE == CAN_RXFIFOMODE)
RxMsg_Std.sft = 1; // SFID1 or SFID2
RxMsg_Std.sfid2 = CanIdConfig[i].ID; // Standard Filter ID 2.
RxMsg_Std.sfid1 = CanIdConfig[i].ID; // Standard Filter ID 1.
RxMsg_Std.sfec = 0x1U; // Store in Rx FIFO 0 if filter matches
#endif
MCAN_addStdMsgIDFilter(MCAN0_BASE, (2 * RxFiltNum + 1), &RxMsg_Std);
RxFiltNum++;
}
else
{
#if (CAN_RXMODE == CAN_RXBUFFMODE)
RxMsg_Ext.efid2 = (0x1 << RxFiltNum); // Standard Filter ID 2.
RxMsg_Ext.efid1 = CanIdConfig[i].ID; // Standard Filter ID 1.
RxMsg_Ext.efec = 0x7U; // Store into Rx Buffer
#elif (CAN_RXMODE == CAN_RXFIFOMODE)
RxMsg_Ext.eft = 1; // SFID1 or SFID2
RxMsg_Ext.efid2 = CanIdConfig[i].ID; // Standard Filter ID 2.
RxMsg_Ext.efid1 = CanIdConfig[i].ID; // Standard Filter ID 1.
RxMsg_Ext.efec = 0x1U; // Store in Rx FIFO 0 if filter matches
#endif
MCAN_addExtMsgIDFilter(MCAN0_BASE, RxFiltNum, &RxMsg_Ext);
RxFiltNum++;
}
}
}
else
{
asm (" ESTOP0");
}
}
}