Hi
I am trying to use the CAN bus on the tms320f28377s on launchxl-f28377s.
I have another board that sends data over the CAN, I do not know how it exactly sends data over the CAN. It is based on STM32F4 MCU.
I want to reads its data without any filtering on my CAN and i do not know the identifier. I only knows it sends 500KHz baud. (I guessed it uses identifier 1 to send data but I am not sure because the following code does not generate any interrupts or newDATA flag)
How can I create an interrupt over any arrival of data?
This is the code that I have right now
void CAN_init(void){
// pin configuration
GPIO_SetupPinMux(70, GPIO_MUX_CPU1, 1); //GPIO70 - CANRXA
GPIO_SetupPinOptions(70, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinMux(71, GPIO_MUX_CPU1, 1); //GPIO71 - CANTXA
GPIO_SetupPinOptions(71, GPIO_OUTPUT, GPIO_PUSHPULL);
EALLOW;
GpioCtrlRegs.GPCGMUX1.bit.GPIO70 = 1;
GpioCtrlRegs.GPCGMUX1.bit.GPIO71 = 1;
EDIS;
// turn on the CAN clock
EALLOW;
CpuSysRegs.PCLKCR10.bit.CAN_A = 1;
EDIS;
// Initialize the CAN controllers
CANInit(CANA_BASE);
// Setup CAN to be clocked off the PLL output clock
CANClkSourceSelect(CANA_BASE, 0); // 200MHz CAN-Clock directly from sysCLK
//CANBitTimingSet();
CANBitRateSet(CANA_BASE, 200000000, 500000); // 500K baud
// Enable interrupts on the CAN A peripheral.
CANIntEnable(CANA_BASE, CAN_INT_MASTER | CAN_INT_ERROR);// | CAN_INT_STATUS
//EALLOW;
//PieVectTable.CANA0_INT = &canaISR;
//EDIS;
CANIntRegister(CANA_BASE, 0, cana_rx_ISR);
// Enable the CAN-A interrupt on the processor (PIE).
PieCtrlRegs.PIEIER9.bit.INTx5 = 1;
IER |= M_INT9;
// Enable the CAN-A interrupt signal
CANGlobalIntEnable(CANA_BASE, CAN_GLB_INT_CANINT0);
//
// Initialize the receive message object used for receiving CAN messages.
// Message Object Parameters:
// Message Identifier: 0x5555
// Message ID Mask: 0x0
// Message Object Flags: Receive Interrupt
// Message Data Length: 8 Bytes
// Message Receive data: rxMsgData
sRXCANMessage.ui32MsgID = 0x0001;//2
sRXCANMessage.ui32MsgIDMask = 0;
sRXCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE;
sRXCANMessage.ui32MsgLen = MSG_DATA_LENGTH;
sRXCANMessage.pucMsgData = rxMsgData;
CANMessageSet(CANA_BASE, RX_MSG_OBJ_ID, &sRXCANMessage, MSG_OBJ_TYPE_RX);
// Start CAN module A and B operations
CANEnable(CANA_BASE);
}
// CAN A ISR - The interrupt service routine called when a CAN interrupt is
// triggered on CAN module A.
__interrupt void cana_rx_ISR(void){
uint32_t status_can;
// Read the CAN-B interrupt status to find the cause of the interrupt
status_can = CANIntStatus(CANA_BASE, CAN_INT_STS_CAUSE);
// If the cause is a controller status interrupt, then get the status
if(status_can == CAN_INT_INT0ID_STATUS){
// Read the controller status. This will return a field of status
// error bits that can indicate various errors. Error processing
// is not done in this example for simplicity. Refer to the
// API documentation for details about the error status bits.
// The act of reading this status will clear the interrupt.
status_can = CANStatusGet(CANA_BASE, CAN_STS_CONTROL);
// Check to see if an error occurred.
//if(((status_can & ~(CAN_ES_RXOK)) != 7) && ((status_can & ~(CAN_ES_RXOK)) != 0)){
// Set a flag to indicate some errors may have occurred.
//}
}else if(status_can == RX_MSG_OBJ_ID){// Check if the cause is the CAN-A receive message object 1
// Get the received message
CANMessageGet(CANA_BASE, RX_MSG_OBJ_ID, &sRXCANMessage, true);
// Getting to this point means that the RX interrupt occurred on
// message object 1, and the message RX is complete. Clear the
// message object interrupt.
CANIntClear(CANA_BASE, RX_MSG_OBJ_ID);
int ij=0;
int length=sRXCANMessage.ui32MsgLen<=8?sRXCANMessage.ui32MsgLen:8;
for (;ij<length ;ij++){
_CAN_rx_buffer[_first_index_of_empty_place_in_CAN_RXbuffer++] = rxMsgData[ij];
if(_first_index_of_empty_place_in_CAN_RXbuffer >= _CAN_rx_buffer_size){
_first_index_of_empty_place_in_CAN_RXbuffer = 0;
}
if (_first_index_of_empty_place_in_CAN_RXbuffer==_first_index_of_data_in_CAN_RXbuffer){// 1 byte is overwritten without to be read
_first_index_of_data_in_CAN_RXbuffer++;
}
}
}
// If something unexpected caused the interrupt, this would handle it.
//else{
//Spurious interrupt handling can go here.
//}
// Clear the global interrupt flag for the CAN interrupt line
CANGlobalIntClear(CANA_BASE, CAN_GLB_INT_CANINT0);
// Acknowledge this interrupt located in group 9
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}