#include "F28x_Project.h" // Device Headerfile and Examples Include File
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_can.h"
#include "driverlib/can.h"
volatile unsigned long g_ulMsgCount = 0;
volatile unsigned long g_bErrFlag = 0;
int
main(void)
{
tCANMsgObject sTXCANMessage;
tCANMsgObject sRXCANMessage;
unsigned char ucTXMsgData[4];
unsigned char ucRXMsgData[4];
InitSysCtrl();
InitGpio();
//GPIO30 – CANRXA
GPIO_SetupPinMux(5, GPIO_MUX_CPU1, 6);
//GPIO31 – CANTXA
GPIO_SetupPinMux(4, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(5, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(4, GPIO_OUTPUT, GPIO_PUSHPULL);
CANInit(CANA_BASE);
CANClkSourceSelect(CANA_BASE, 0);
CANBitRateSet(CANA_BASE, 200000000, 500000);// 500 kHz.
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
// Enable the CAN for operation.
CANEnable(CANA_BASE);
*(unsigned long *)ucTXMsgData = 0;
sTXCANMessage.ui32MsgID =1 ; // CAN message ID – use 1
sTXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sTXCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE; // enable interrupt on TX
sTXCANMessage.ui32MsgLen = sizeof(ucTXMsgData); // size of message is 4
sTXCANMessage.pucMsgData = ucTXMsgData; // ptr to message content
// Initialize the message object that will be used for recieving CAN
// messages.
*(unsigned long *)ucRXMsgData = 0;
sRXCANMessage.ui32MsgID = 1; // CAN message ID – use 1
sRXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sRXCANMessage.ui32Flags = MSG_OBJ_NO_FLAGS; //
sRXCANMessage.ui32MsgLen = sizeof(ucRXMsgData); // size of message is 4
sRXCANMessage.pucMsgData = ucRXMsgData; // ptr to message content
// Setup the message object being used to receive messages
CANMessageSet(CANA_BASE, 2, &sRXCANMessage, MSG_OBJ_TYPE_RX);
for(;;)
{
CANMessageSet(CANA_BASE, 1, &sTXCANMessage, MSG_OBJ_TYPE_TX);
DELAY_US(1000*1000);
// Get the receive message
CANMessageGet(CANA_BASE, 2, &sRXCANMessage, true);
.
(*(unsigned long *)ucTXMsgData)++;
}
}
这是TI controlSUITE里的代码 将LOOPBACK的两行代码屏蔽
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
CAN控制芯片为sn65hvd230,通过示波器测CAN芯片的TX、RX、CANH和CANL管脚都有波形,但是通过CANMonitor接收不到数据。
求各位大神指点明路呀!!
mangui zhang:
参考一下最新版的controlSUITE提供的例程吧
#include "F28x_Project.h" // Device Headerfile and Examples Include File
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_can.h"
#include "driverlib/can.h"
volatile unsigned long g_ulMsgCount = 0;
volatile unsigned long g_bErrFlag = 0;
int
main(void)
{
tCANMsgObject sTXCANMessage;
tCANMsgObject sRXCANMessage;
unsigned char ucTXMsgData[4];
unsigned char ucRXMsgData[4];
InitSysCtrl();
InitGpio();
//GPIO30 – CANRXA
GPIO_SetupPinMux(5, GPIO_MUX_CPU1, 6);
//GPIO31 – CANTXA
GPIO_SetupPinMux(4, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(5, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(4, GPIO_OUTPUT, GPIO_PUSHPULL);
CANInit(CANA_BASE);
CANClkSourceSelect(CANA_BASE, 0);
CANBitRateSet(CANA_BASE, 200000000, 500000);// 500 kHz.
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
// Enable the CAN for operation.
CANEnable(CANA_BASE);
*(unsigned long *)ucTXMsgData = 0;
sTXCANMessage.ui32MsgID =1 ; // CAN message ID – use 1
sTXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sTXCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE; // enable interrupt on TX
sTXCANMessage.ui32MsgLen = sizeof(ucTXMsgData); // size of message is 4
sTXCANMessage.pucMsgData = ucTXMsgData; // ptr to message content
// Initialize the message object that will be used for recieving CAN
// messages.
*(unsigned long *)ucRXMsgData = 0;
sRXCANMessage.ui32MsgID = 1; // CAN message ID – use 1
sRXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sRXCANMessage.ui32Flags = MSG_OBJ_NO_FLAGS; //
sRXCANMessage.ui32MsgLen = sizeof(ucRXMsgData); // size of message is 4
sRXCANMessage.pucMsgData = ucRXMsgData; // ptr to message content
// Setup the message object being used to receive messages
CANMessageSet(CANA_BASE, 2, &sRXCANMessage, MSG_OBJ_TYPE_RX);
for(;;)
{
CANMessageSet(CANA_BASE, 1, &sTXCANMessage, MSG_OBJ_TYPE_TX);
DELAY_US(1000*1000);
// Get the receive message
CANMessageGet(CANA_BASE, 2, &sRXCANMessage, true);
.
(*(unsigned long *)ucTXMsgData)++;
}
}
这是TI controlSUITE里的代码 将LOOPBACK的两行代码屏蔽
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
CAN控制芯片为sn65hvd230,通过示波器测CAN芯片的TX、RX、CANH和CANL管脚都有波形,但是通过CANMonitor接收不到数据。
求各位大神指点明路呀!!
shook xu:
先保证你的canmonitor设置是否正确,波特率是否对应,是否设置了接收滤波,如果都正确降低一下波特率再试一试,原来我碰到过1M通信速率也通信不上的问题,降低波特率就好了,主要原因还是canmonitor的时钟和28377的还是不太同步(在高波特率的情况下)
#include "F28x_Project.h" // Device Headerfile and Examples Include File
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_can.h"
#include "driverlib/can.h"
volatile unsigned long g_ulMsgCount = 0;
volatile unsigned long g_bErrFlag = 0;
int
main(void)
{
tCANMsgObject sTXCANMessage;
tCANMsgObject sRXCANMessage;
unsigned char ucTXMsgData[4];
unsigned char ucRXMsgData[4];
InitSysCtrl();
InitGpio();
//GPIO30 – CANRXA
GPIO_SetupPinMux(5, GPIO_MUX_CPU1, 6);
//GPIO31 – CANTXA
GPIO_SetupPinMux(4, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(5, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(4, GPIO_OUTPUT, GPIO_PUSHPULL);
CANInit(CANA_BASE);
CANClkSourceSelect(CANA_BASE, 0);
CANBitRateSet(CANA_BASE, 200000000, 500000);// 500 kHz.
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
// Enable the CAN for operation.
CANEnable(CANA_BASE);
*(unsigned long *)ucTXMsgData = 0;
sTXCANMessage.ui32MsgID =1 ; // CAN message ID – use 1
sTXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sTXCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE; // enable interrupt on TX
sTXCANMessage.ui32MsgLen = sizeof(ucTXMsgData); // size of message is 4
sTXCANMessage.pucMsgData = ucTXMsgData; // ptr to message content
// Initialize the message object that will be used for recieving CAN
// messages.
*(unsigned long *)ucRXMsgData = 0;
sRXCANMessage.ui32MsgID = 1; // CAN message ID – use 1
sRXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sRXCANMessage.ui32Flags = MSG_OBJ_NO_FLAGS; //
sRXCANMessage.ui32MsgLen = sizeof(ucRXMsgData); // size of message is 4
sRXCANMessage.pucMsgData = ucRXMsgData; // ptr to message content
// Setup the message object being used to receive messages
CANMessageSet(CANA_BASE, 2, &sRXCANMessage, MSG_OBJ_TYPE_RX);
for(;;)
{
CANMessageSet(CANA_BASE, 1, &sTXCANMessage, MSG_OBJ_TYPE_TX);
DELAY_US(1000*1000);
// Get the receive message
CANMessageGet(CANA_BASE, 2, &sRXCANMessage, true);
.
(*(unsigned long *)ucTXMsgData)++;
}
}
这是TI controlSUITE里的代码 将LOOPBACK的两行代码屏蔽
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
CAN控制芯片为sn65hvd230,通过示波器测CAN芯片的TX、RX、CANH和CANL管脚都有波形,但是通过CANMonitor接收不到数据。
求各位大神指点明路呀!!
qin situ:
请问你这个问题解决了吗?我也遇到同样的问题,求指点。
#include "F28x_Project.h" // Device Headerfile and Examples Include File
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_can.h"
#include "driverlib/can.h"
volatile unsigned long g_ulMsgCount = 0;
volatile unsigned long g_bErrFlag = 0;
int
main(void)
{
tCANMsgObject sTXCANMessage;
tCANMsgObject sRXCANMessage;
unsigned char ucTXMsgData[4];
unsigned char ucRXMsgData[4];
InitSysCtrl();
InitGpio();
//GPIO30 – CANRXA
GPIO_SetupPinMux(5, GPIO_MUX_CPU1, 6);
//GPIO31 – CANTXA
GPIO_SetupPinMux(4, GPIO_MUX_CPU1, 6);
GPIO_SetupPinOptions(5, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(4, GPIO_OUTPUT, GPIO_PUSHPULL);
CANInit(CANA_BASE);
CANClkSourceSelect(CANA_BASE, 0);
CANBitRateSet(CANA_BASE, 200000000, 500000);// 500 kHz.
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
// Enable the CAN for operation.
CANEnable(CANA_BASE);
*(unsigned long *)ucTXMsgData = 0;
sTXCANMessage.ui32MsgID =1 ; // CAN message ID – use 1
sTXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sTXCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE; // enable interrupt on TX
sTXCANMessage.ui32MsgLen = sizeof(ucTXMsgData); // size of message is 4
sTXCANMessage.pucMsgData = ucTXMsgData; // ptr to message content
// Initialize the message object that will be used for recieving CAN
// messages.
*(unsigned long *)ucRXMsgData = 0;
sRXCANMessage.ui32MsgID = 1; // CAN message ID – use 1
sRXCANMessage.ui32MsgIDMask = 0; // no mask needed for TX
sRXCANMessage.ui32Flags = MSG_OBJ_NO_FLAGS; //
sRXCANMessage.ui32MsgLen = sizeof(ucRXMsgData); // size of message is 4
sRXCANMessage.pucMsgData = ucRXMsgData; // ptr to message content
// Setup the message object being used to receive messages
CANMessageSet(CANA_BASE, 2, &sRXCANMessage, MSG_OBJ_TYPE_RX);
for(;;)
{
CANMessageSet(CANA_BASE, 1, &sTXCANMessage, MSG_OBJ_TYPE_TX);
DELAY_US(1000*1000);
// Get the receive message
CANMessageGet(CANA_BASE, 2, &sRXCANMessage, true);
.
(*(unsigned long *)ucTXMsgData)++;
}
}
这是TI controlSUITE里的代码 将LOOPBACK的两行代码屏蔽
// HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
// HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
CAN控制芯片为sn65hvd230,通过示波器测CAN芯片的TX、RX、CANH和CANL管脚都有波形,但是通过CANMonitor接收不到数据。
求各位大神指点明路呀!!
user4938334:
你好,
1、你看一下波特率是否一样?
2、是否需要终端电阻是否正确?
3、都正确的话,试着降低波特率设置试一试
以上只是建议,如果都不行的话,那就只能是CAN配置有问题了。