Other Parts Discussed in Thread:CONTROLSUITE, C2000WARE
问题是这样的:
我用的28377d,使用CANA接好收发器及120Ω电阻之后与usbcan分析仪相连,程序是发送数据100次,用can_external_transmit改的,分析仪无法显示接受的数据。我用万用表量gpio71无论程序运行与否均显示3.27v,量收发器的CANH和CANL之间永远是0v。
程序如下:
#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"
//
// Defines
//
#define TXCOUNT 100
#define MSG_DATA_LENGTH 8
#define TX_MSG_OBJ_ID 15
#define RX_MSG_OBJ_ID 1
//
// Globals
//
volatile unsigned long i;
volatile uint32_t txMsgCount = 0;
volatile uint32_t rxMsgCount = 0;
volatile uint32_t errorFlag = 0;
unsigned char txMsgData[4];
unsigned char rxMsgData[4];
tCANMsgObject sTXCANMessage;
tCANMsgObject sRXCANMessage;
//
// Function Prototypes
//
__interrupt void canaISR(void);
//
// Main
//
void main(void)
{
//
// Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
//
InitSysCtrl();
//
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
// on module A and B
//
InitGpio();
//
// Setup GPIO pin mux for CAN-A TX/RX and CAN-B TX/RX
//
GPIO_SetupPinMux(70, GPIO_MUX_CPU1, 5); //GPIO30 – CANRXA
GPIO_SetupPinOptions(70, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinMux(71, GPIO_MUX_CPU1, 5); //GPIO31 – CANTXA
GPIO_SetupPinOptions(71, GPIO_OUTPUT, GPIO_PUSHPULL);
// Initialize the CAN controllers
//
CANInit(CANA_BASE);
//CANInit(CANB_BASE);
//
// Setup CAN to be clocked off the PLL output clock
//
CANClkSourceSelect(CANA_BASE, 0); // 500kHz CAN-Clock
//CANClkSourceSelect(CANB_BASE, 0); // 500kHz CAN-Clock
//
// Set up the CAN bus bit rate to 500kHz for each module
// This function sets up the CAN bus timing for a nominal configuration.
// You can achieve more control over the CAN bus timing by using the
// function CANBitTimingSet() instead of this one, if needed.
// Additionally, consult the device data sheet for more information about
// the CAN module clocking.
//
CANBitRateSet(CANA_BASE, 200000000, 250000);
//CANBitRateSet(CANB_BASE, 200000000, 500000);
//
// Enable interrupts on the CAN B peripheral.
//
CANIntEnable(CANA_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
//
// Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;
//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
//
InitPieCtrl();
//
// Disable CPU interrupts and clear all CPU interrupt flags
//
IER = 0x0000;
IFR = 0x0000;
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
//
InitPieVectTable();
//
// 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.
//
EALLOW;
PieVectTable.CANA0_INT = canaISR;
EDIS;
//
// Enable the CAN-B interrupt on the processor (PIE).
//
PieCtrlRegs.PIEIER9.bit.INTx5 = 1;
IER |= M_INT9;
EINT;
//
// Enable the CAN-B interrupt signal
//
CANGlobalIntEnable(CANA_BASE, CAN_GLB_INT_CANINT0);
//
// 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.ui32MsgIDMask = 0;
sTXCANMessage.ui32Flags = 0;
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 = 0x0;
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);
//
// Initialize the transmit message object data buffer to be sent
//
txMsgData[0] = 0x12;
txMsgData[1] = 0x34;
txMsgData[2] = 0x56;
txMsgData[3] = 0x78;
//
// Start CAN module A and B operations
//
CANEnable(CANA_BASE);
//CANEnable(CANB_BASE);
//
// Transmit messages from CAN-A to CAN-B
//
while(1)
{
//
// Check the error flag to see if errors occurred
//
if(errorFlag)
{
//asm(" ESTOP0");
}
//
// Verify that the number of transmitted messages equal the number of
// messages received before sending a new message
//
//
// 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;
//
// Reset data if exceeds a byte
//
if(txMsgData[0] > 0xFF)
{
txMsgData[0] = 0;
}
if(txMsgData[1] > 0xFF)
{
txMsgData[1] = 0;
}
if(txMsgData[2] > 0xFF)
{
txMsgData[2] = 0;
}
if(txMsgData[3] > 0xFF)
{
txMsgData[3] = 0;
}
}
//
// Stop application
//
asm(" ESTOP0");
}
//
// CAN B ISR – The interrupt service routine called when a CAN interrupt is
// triggered on CAN module B.
//
__interrupt void canaISR(void)
{
uint32_t status;
//
// Read the CAN-B interrupt status to find the cause of the interrupt
//
status = CANIntStatus(CANA_BASE, CAN_INT_STS_CAUSE);
//
// 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 = CANStatusGet(CANA_BASE, CAN_STS_CONTROL);
//
// Check to see if an error occurred.
//
if(((status & ~(CAN_ES_RXOK)) != 7) &&
((status & ~(CAN_ES_RXOK)) != 0))
{
//
// Set a flag to indicate some errors may have occurred.
//
errorFlag = 1;
}else
{
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);
}
}
//
// Check if the cause is the CAN-B receive message object 1
//
else if(status == RX_MSG_OBJ_ID)
{
//
// 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);
//
// 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;
}
//
// 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;
}
//
// End of File
//
Susan Yang:
请问您现在使用的是开发板?使用例程can_ex1_loopback可以测试成功吗?
目前我们这边没有usbcan分析仪,所以不太好分析您的问题
,
user6432345:
是的,是使用的开发板。loopback例程的话,我用expression查看sTXCANMessage和sRXCANMessage都可以正常显示。
,
Susan Yang:
谢谢反馈,目前我们这边没有usbcan分析仪,确实不好分析
之前有客户也有过类似问题,您可以看一下
e2echina.ti.com/…/187275
若还是不可以的话,请您在E2E上咨询下国外工程师:
e2e.ti.com/…/171
,
user6432345:
好的,谢谢你
,
Susan Yang:
不客气
,
user6432345:
对了,我还想麻烦您一下,可以帮我确认一下我这个程序确实是往外面发送数据吗?
,
Susan Yang:
This example initializes CAN module A and CAN module B for external
//! communication. CAN-A module is setup to transmit incrementing data for "n"
//! number of times to the CAN-B module, where "n" is the value of TXCOUNT.
//! CAN-B module is setup to trigger an interrupt service routine (ISR) when
//! data is received. An error flag will be set if the transmitted data doesn't
//! match the received data.这个是CAN_A与CAN-B的传输,CAN_A发送数据到CAN_B,CAN_B收到数据后触发中断
,
user6432345:
QAQ,我把canb注释掉了,只留下了cana,然后注释掉了canb的接收程序,我的目的就是往外发送,不管接收了。这是can_external_transmit改的呀。。。
,
Susan Yang:
只是测试发送的话,建议您测试一下
can_ex4_simple_transmit
//! This example initializes CAN module A for external communication.
//! CAN-A module is setup to transmit data for "n" number of times,
//! where "n" is the value of TXCOUNT. Another CAN node configured for the
//! same bit-rate is needed to provide the ACK. No interrupts are used.
//!
//! \b Hardware \b Required \n
//!- A C2000 board with CAN transceiver and another CAN node configured
//!for the same bit-rate to provide the ACK.
,
user6432345:
请问一下,这个ex4在哪里找的呀,controlsuite里面没有看到诶,我上次看到别的回复里面有提到ex5的时候就想找的,但是没有。。
,
Susan Yang:
这个是包含在C200ware内的,您可以在安装C2000ware后查找。默认路径:
C2000Ware\driverlib\f2837xd\examples\cpu1\can
,
user6432345:
好的,非常感谢您的耐心回答。谢谢您!
,
Susan Yang:
很高兴能帮到您!
,
user4921973:
TI官网有个C2000Ware软件,下载下来,安装之后,就可以看到相应程序,c2000系列芯片程序都有