您好!我现在配置一个CANT通信收发数据,现在用CAN盒去获取数据,出现如图所示现象。实在搞不懂什么原因,这个程序单独另建一个工程时,是可以发送数据的。因为我现在整合CLA ADC EPWM一些外设。就出现这这种情况了。还有一就是使用延时函数时,就出现程序跑飞,即跑进非法中断死循环里。一屏蔽就没事了。目前怀疑的是DELAY_US和INITFLASH()地址重叠了。请帮我参考一些CAN通信的问题,谢谢!!!!!
void InitECANA(void)
{
//
// Setup GPIO pin mux for CAN-A TX/RX and CAN-B TX/RX
//
GPIO_SetupPinMux(36, GPIO_MUX_CPU1, 6); //GPIO36 – CANRXA
GPIO_SetupPinOptions(36, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinMux(37, GPIO_MUX_CPU1, 6); //GPIO37 – CANTXA
GPIO_SetupPinOptions(37, GPIO_OUTPUT, GPIO_PUSHPULL);
//
// Initialize the CAN controllers
//
CANInit(CANA_BASE);
//
//Setup CAN to be clocked off the PLL output clock
//
CANClkSourceSelect(CANA_BASE, 0); //选择CAN-Clock
CANBitRateSet(CANA_BASE, 120000000, 1000000); //波特率设置:1MHz
//
// Start CAN module A and B operations
//
CANEnable(CANA_BASE);
}
//
void ECanAmailConfigure(void)
{
//
// Initialize the transmit message object used for sending CAN messages.
// Message Object Parameters:
// Message Identifier: 0x5555
// Message ID Mask: 0x0
// Message Object Flags: None
// Message Data Length: 4 Bytes
// Message Transmit data: txMsgData
//sTXCANMessage.ui32MsgID = 0x5555;
sTXCANMessage.ui32MsgID.ebit.SAID = 0x12; // 0:7 //源地址
sTXCANMessage.ui32MsgID.ebit.PSID = 0x46; // 8:15 //目的地址
sTXCANMessage.ui32MsgID.ebit.PF = 0x60; // 16:23
sTXCANMessage.ui32MsgID.ebit.R = 0; // 24
sTXCANMessage.ui32MsgID.ebit.DP = 0; // 25
sTXCANMessage.ui32MsgID.ebit.P = 0x02; // 26:28
sTXCANMessage.ui32MsgIDMask = 0;
sTXCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
sTXCANMessage.ui32MsgLen = MSG_DATA_LENGTH;
sTXCANMessage.pucMsgData = txMsgData;
//
// 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: 4 Bytes
// Message Receive data: rxMsgData
//
//sRXCANMessage.ui32MsgID = 0x5555;
sRXCANMessage.ui32MsgID.ebit.SAID = 0x46; // 0:7 //源地址
sRXCANMessage.ui32MsgID.ebit.PSID = 0x12; // 8:15 //目的地址
sRXCANMessage.ui32MsgID.ebit.PF = 0x60; // 16:23
sRXCANMessage.ui32MsgID.ebit.R = 0; // 24
sRXCANMessage.ui32MsgID.ebit.DP = 0; // 25
sRXCANMessage.ui32MsgID.ebit.P = 0x02; // 26:28
sRXCANMessage.ui32MsgIDMask = 0; //屏蔽位
sRXCANMessage.ui32Flags = MSG_OBJ_USE_EXT_FILTER | MSG_OBJ_EXTENDED_ID;
sRXCANMessage.ui32MsgLen = MSG_DATA_LENGTH; //数据长度
sRXCANMessage.pucMsgData = rxMsgData; //接收的数据
CANMessageSet(CANB_BASE,RX_MSG_OBJ_ID, &sRXCANMessage, MSG_OBJ_TYPE_RX);
}
//数据处理函数
void ECanADataDeal(void)
{
// Initialize the transmit message object data buffer to be sent
//
txMsgData[0] = 0x12;
txMsgData[1] = 0x34;
txMsgData[2] = 0x56;
txMsgData[3] = 0x78;
for(i = 0; i < TXCOUNT; i++)
{
//
// Verify that the number of transmitted messages equal the number of
// messages received before sending a new message
//
if(txMsgCount == rxMsgCount)
{
//Transmit Message
//传送数据
CANMessageSet(CANA_BASE, TX_MSG_OBJ_ID, &sTXCANMessage,MSG_OBJ_TYPE_TX);
//txMsgCount++;
}
//
// Delay 0.25 second before continuing
//
//DELAY_US(1000 * 250);
//
// Increment the value in the transmitted message data.
//增加传输的消息数据中的值。
txMsgData[0] += 0x01;
txMsgData[1] += 0x01;
txMsgData[2] += 0x01;
txMsgData[3] += 0x01;
}
//
// Stop application
//
//asm(" ESTOP0");
}
Susan Yang:粗看了下程序,感觉CAN本身设置以及操作是没有问题的。
建议您将整合CLA ADC EPWM的这些外设以及延时等分别在程序内屏蔽,然后进行测试,看到底是哪一部分会影响CAN通信
您好!我现在配置一个CANT通信收发数据,现在用CAN盒去获取数据,出现如图所示现象。实在搞不懂什么原因,这个程序单独另建一个工程时,是可以发送数据的。因为我现在整合CLA ADC EPWM一些外设。就出现这这种情况了。还有一就是使用延时函数时,就出现程序跑飞,即跑进非法中断死循环里。一屏蔽就没事了。目前怀疑的是DELAY_US和INITFLASH()地址重叠了。请帮我参考一些CAN通信的问题,谢谢!!!!!
void InitECANA(void)
{
//
// Setup GPIO pin mux for CAN-A TX/RX and CAN-B TX/RX
//
GPIO_SetupPinMux(36, GPIO_MUX_CPU1, 6); //GPIO36 – CANRXA
GPIO_SetupPinOptions(36, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinMux(37, GPIO_MUX_CPU1, 6); //GPIO37 – CANTXA
GPIO_SetupPinOptions(37, GPIO_OUTPUT, GPIO_PUSHPULL);
//
// Initialize the CAN controllers
//
CANInit(CANA_BASE);
//
//Setup CAN to be clocked off the PLL output clock
//
CANClkSourceSelect(CANA_BASE, 0); //选择CAN-Clock
CANBitRateSet(CANA_BASE, 120000000, 1000000); //波特率设置:1MHz
//
// Start CAN module A and B operations
//
CANEnable(CANA_BASE);
}
//
void ECanAmailConfigure(void)
{
//
// Initialize the transmit message object used for sending CAN messages.
// Message Object Parameters:
// Message Identifier: 0x5555
// Message ID Mask: 0x0
// Message Object Flags: None
// Message Data Length: 4 Bytes
// Message Transmit data: txMsgData
//sTXCANMessage.ui32MsgID = 0x5555;
sTXCANMessage.ui32MsgID.ebit.SAID = 0x12; // 0:7 //源地址
sTXCANMessage.ui32MsgID.ebit.PSID = 0x46; // 8:15 //目的地址
sTXCANMessage.ui32MsgID.ebit.PF = 0x60; // 16:23
sTXCANMessage.ui32MsgID.ebit.R = 0; // 24
sTXCANMessage.ui32MsgID.ebit.DP = 0; // 25
sTXCANMessage.ui32MsgID.ebit.P = 0x02; // 26:28
sTXCANMessage.ui32MsgIDMask = 0;
sTXCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
sTXCANMessage.ui32MsgLen = MSG_DATA_LENGTH;
sTXCANMessage.pucMsgData = txMsgData;
//
// 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: 4 Bytes
// Message Receive data: rxMsgData
//
//sRXCANMessage.ui32MsgID = 0x5555;
sRXCANMessage.ui32MsgID.ebit.SAID = 0x46; // 0:7 //源地址
sRXCANMessage.ui32MsgID.ebit.PSID = 0x12; // 8:15 //目的地址
sRXCANMessage.ui32MsgID.ebit.PF = 0x60; // 16:23
sRXCANMessage.ui32MsgID.ebit.R = 0; // 24
sRXCANMessage.ui32MsgID.ebit.DP = 0; // 25
sRXCANMessage.ui32MsgID.ebit.P = 0x02; // 26:28
sRXCANMessage.ui32MsgIDMask = 0; //屏蔽位
sRXCANMessage.ui32Flags = MSG_OBJ_USE_EXT_FILTER | MSG_OBJ_EXTENDED_ID;
sRXCANMessage.ui32MsgLen = MSG_DATA_LENGTH; //数据长度
sRXCANMessage.pucMsgData = rxMsgData; //接收的数据
CANMessageSet(CANB_BASE,RX_MSG_OBJ_ID, &sRXCANMessage, MSG_OBJ_TYPE_RX);
}
//数据处理函数
void ECanADataDeal(void)
{
// Initialize the transmit message object data buffer to be sent
//
txMsgData[0] = 0x12;
txMsgData[1] = 0x34;
txMsgData[2] = 0x56;
txMsgData[3] = 0x78;
for(i = 0; i < TXCOUNT; i++)
{
//
// Verify that the number of transmitted messages equal the number of
// messages received before sending a new message
//
if(txMsgCount == rxMsgCount)
{
//Transmit Message
//传送数据
CANMessageSet(CANA_BASE, TX_MSG_OBJ_ID, &sTXCANMessage,MSG_OBJ_TYPE_TX);
//txMsgCount++;
}
//
// Delay 0.25 second before continuing
//
//DELAY_US(1000 * 250);
//
// Increment the value in the transmitted message data.
//增加传输的消息数据中的值。
txMsgData[0] += 0x01;
txMsgData[1] += 0x01;
txMsgData[2] += 0x01;
txMsgData[3] += 0x01;
}
//
// Stop application
//
//asm(" ESTOP0");
}
user6138275:
回复 Susan Yang:
你好,我查到的原因可能是中断影响了延时函数了