This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280049: 库函数编程CAN通信不进接收邮箱中断

Part Number: TMS320F280049
Other Parts Discussed in Thread: TMS320F2800137, TMS320F280023

问题:

使用F280049,INT0的邮箱1来中断接收CAN数据,不过滤ID和方向。CAN线上有数据就接收。

CAN线上每隔500ms有数据发送。

能进中断服务函数,不进接收邮箱1的中断。

仿真观察寄存器数据,当进中断服务函数时,CAN_INT的值为0x00008000,说明有中断事件;

CAN_ES的值为0x00000010,说明有接收到数据。

为啥就不进设定的邮箱中断呢?是不是配置错了?

增加发送配置后可以正常发送,仍不能进接收邮箱中断。

主要代码如下:

配置部分:

// CANA -> MyCANA Pinmux
//
GPIO_setPinConfig(GPIO_30_CANA_RX);
GPIO_setPadConfig(MyCANA_CANRX_GPIO, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(MyCANA_CANRX_GPIO, GPIO_QUAL_ASYNC);

GPIO_setPinConfig(GPIO_31_CANA_TX);
GPIO_setPadConfig(MyCANA_CANTX_GPIO, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(MyCANA_CANTX_GPIO, GPIO_QUAL_ASYNC);

// Initialize the CAN controller
//
CAN_initModule(CANA_BASE);

//
// Set up the CAN bus bit rate to 500kHz
// Refer to the Driver Library User Guide for information on how to set
// tighter timing control. Additionally, consult the device data sheet
// for more information about the CAN module clocking.
//
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 250000, 20);

//
// Enable interrupts on the CAN peripheral.
//
CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR | CAN_INT_STATUS);

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
// This registers the interrupt handler in PIE vector table.
//
Interrupt_register(INT_CANA0, &canISR);

//
// Enable the CAN interrupt signal
//
Interrupt_enable(INT_CANA0);
CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0);

// Initialize the receive message object used for receiving CAN messages.
// Message Object Parameters:
// Message Object ID Number: 1
// Message Identifier: 0x3
// Message Frame: EXT
// Message Type: Receive
// Message ID Mask: 0x0.接收CAN线上的所有数据
// Message Object Flags: Receive Interrupt
// Message Data Length: 8 Bytes (Note that DLC field is a "don't care"
// for a Receive mailbox
//
CAN_setupMessageObject(CANA_BASE, 1, 3, CAN_MSG_FRAME_EXT,CAN_MSG_OBJ_TYPE_RX, 0, CAN_MSG_OBJ_RX_INT_ENABLE, 8);

//
// Enable CAN test mode with external loopback
//
//CAN_enableTestMode(CANA_BASE, CAN_TEST_EXL);

//
// Start CAN module operations
//
CAN_startModule(CANA_BASE);

中断服务函数:

// CAN ISR - The interrupt service routine called when a CAN interrupt is
// triggered. It checks for the cause of the interrupt, and
// maintains a count of all messages that have been transmitted.
//
__interrupt void
canISR(void)
{
uint32_t status;

//


// Read the CAN interrupt status to find the cause of the interrupt
//
status = CAN_getInterruptCause(CANA_BASE);

//
// If the cause is a controller status interrupt, then get the status
//
if(status == 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_getStatus(CANA_BASE);

//
// Check to see if an error occurred.
//
if(((status & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 7) &&
((status & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 0))
{
//
// Set a flag to indicate some errors may have occurred.
//
errorFlag = 1;
}
}

//
// Check if the cause is the transmit message object 1
//
else if(status == TX_MSG_OBJ_ID)
{


// Getting to this point means that the TX interrupt occurred on
// message object 1, and the message TX is complete. Clear the
// message object interrupt.
//
CAN_clearInterruptStatus(CANA_BASE, TX_MSG_OBJ_ID);

//
// Increment a counter to keep track of how many messages have been
// sent. In a real application this could be used to set flags to
// indicate when a message is sent.
//

//
// Since the message was sent, clear any error flags.
//
errorFlag = 0;
}

//
// Check if the cause is the receive message object 2
//
else if(status == 1)//CAN数据接收邮箱
{
//
// Get the received message
//
//CAN_readMessage(CANA_BASE, RX_MSG_OBJ_ID, rxMsgData);

//
// Getting to this point means that the RX interrupt occurred on
// message object 2, and the message RX is complete. Clear the
// message object interrupt.
//
CAN_clearInterruptStatus(CANA_BASE, RX_MSG_OBJ_ID);

//
// Increment a counter to keep track of how many messages have been
// received. In a real application this could be used to set flags to
// indicate when a message is received.
//
rxMsgCount++;

//
// Since the message was received, clear any error flags.
//
errorFlag = 0;
}
else if(status == RX_MSG_OBJ_ID_SAME)//机号相同接收邮箱
{
}

//
// 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
//
CAN_clearGlobalInterruptStatus(CANA_BASE, CAN_GLOBAL_INT_CANINT0);

//
// Acknowledge this interrupt located in group 9
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}

CAN寄存器值如下:

  • 我也碰到了同样的问题,芯片型号是TMS320F2800137, CAN能接收数据但是进不了中断,第一次会进入interrupt void PIE_RESERVED_ISR(void)中断,之后就不会再进入任何中断,相关寄存器查不出任何异常,  程序是从TMS320F280023上移植的,在0023上运行完全正常