我根据TI给出的can-loopback例程,然后把IO口改掉,环回模式是对的,之后把环回模式 // Enable test mode and select external loopback HWREG(CANA_BASE + CAN_O_CTL) |= CAN_CTL_TEST;
HWREG(CANA_BASE + CAN_O_TEST) = CAN_TEST_EXL;
给注释掉,波特率也设定好了,连接一个CAN分析仪后,发现dsp的数据不能发送出去,请问还需要修改其他地方嘛?
这是我的程序,十分感谢各位前辈的指导。
main(void)
{
tCANMsgObject sTXCANMessage;
tCANMsgObject sRXCANMessage;
// Step 1. Initialize System Control:
InitSysCtrl();
// Step 2. Initialize GPIO:
InitGpio();
//GPIO70 - CANRXA
GPIO_SetupPinMux(17, GPIO_MUX_CPU1, 2);
//GPIO71 - CANTXA
GPIO_SetupPinMux(12, GPIO_MUX_CPU1, 2);
GPIO_SetupPinOptions(17, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(12, GPIO_OUTPUT, GPIO_PUSHPULL);
// Initialize the CAN controller
CANInit(CANA_BASE);
// Setup CAN to be clocked off the M3/Master subsystem clock
CANClkSourceSelect(CANA_BASE, 0);
CANBitRateSet(CANA_BASE, 200000000, 50000);
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// Enable test mode and select external loopback
// 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);
// Initialize the message object that will be used for sending CAN
// messages. The message will be 4 bytes that will contain an incrementing
// value. Initially it will be set to 0.
*(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, 5, &sRXCANMessage, MSG_OBJ_TYPE_RX);
// Enter loop to send messages. A new message will be sent once per
// second. The 4 bytes of message content will be treated as an unsigned
// long and incremented by one each time.
for(;;)
{
// Send the CAN message using object number 1
CANMessageSet(CANA_BASE, 1, &sTXCANMessage, MSG_OBJ_TYPE_TX);
// Now wait 1 second before continuing
DELAY_US(1000*1000);
// Get the receive message
CANMessageGet(CANA_BASE, 5, &sRXCANMessage, true);
// Ensure the received data matches the transmitted data
if((*(unsigned long *)ucTXMsgData) != (*(unsigned long *)ucRXMsgData)){
asm(" ESTOP0");
}
// Increment the value in the transmitted message data.
(*(unsigned long *)ucTXMsgData)++;
asm(" ESTOP0");
}
}
|