Other Parts Discussed in Thread: SN65HVD230, SN65HVD1050
hi
we are developing a product based on TIVA controller and trying to use CAN but we used example code to test it but now we are trying to send the CAN message data frame of size 8. When Iwecapture the CAN data at the CAN simulator we can see only Message ID,length and one byte For example In the code atttached I am planning to send 0x7DF 8 1 C C C
0 0 0 0.
But what appears at the other side is only 0x7DF 8 1 please help us to resolve this issue asap
#include "can_private.h"
#define CAN_RXOBJECT 2
#define CAN_TXOBJECT 1
volatile bool g_bErrFlag = 0;
volatile bool g_bRXFlag = 0;
static uint8_t candata[8];
tCANMsgObject sTxCANMessage;
tCANMsgObject sRxCANMessage;
static char s[10];
void InitCAN()
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_GPIOPinConfigure(GPIO_PB4_CAN0RX);
ROM_GPIOPinConfigure(GPIO_PB5_CAN0TX);
ROM_GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
ROM_CANInit(CAN0_BASE);
ROM_CANBitRateSet(CAN0_BASE, ROM_SysCtlClockGet(), 250000);
ROM_CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
ROM_IntEnable(INT_CAN0);
ROM_CANEnable(CAN0_BASE);
CAN_HIGHSPEED;
DPRINTF("CAN Initialised\r\n");
}
void SetCANMessage()
{
// uint32_t ui32MsgData;
// uint8_t *pui8MsgData;
// pui8MsgData = (uint8_t *)&ui32MsgData;
sTxCANMessage.ui32MsgID = 0x7DF;
sTxCANMessage.ui32MsgIDMask = 0;
sTxCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
sTxCANMessage.ui32MsgLen = 0x8;
candata[0] = 0x01;
candata[1] = 0x0C;
candata[2] = 0x0C;
candata[3] = 0x0C;
candata[4] = 0x0;
candata[5] = 0x0;
candata[6] = 0x0;
candata[7] = 0x0;
sTxCANMessage.pui8MsgData = &candata[0];
ROM_CANMessageSet(CAN0_BASE, CAN_TXOBJECT, &sTxCANMessage, MSG_OBJ_TYPE_TX);
sRxCANMessage.ui32MsgID = 0;
sRxCANMessage.ui32MsgIDMask = 0;
sRxCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
sRxCANMessage.ui32MsgLen = 8;
ROM_CANMessageSet(CAN0_BASE, CAN_RXOBJECT, &sRxCANMessage, MSG_OBJ_TYPE_RX);
}
void GetCANMessage()
{
int i;
if(g_bRXFlag == 1)
{
g_bRXFlag = 0;
DPRINTF("Recieved data\r\n");
sRxCANMessage.pui8MsgData = &candata[0];
ROM_CANMessageGet(CAN0_BASE, CAN_RXOBJECT, &sRxCANMessage, 0);
vts_itoa(sRxCANMessage.ui32MsgID,s);
DPRINTF("MessageID:");
DPRINTF(s);
DPRINTF("\r\nMessage: ");
for(i = 0; i < 8; i++)
{
vts_itoa(candata[i],s);
DPRINTF(s);
DPRINTF(" ");
}
DPRINTF("\r\n");
}
}
void CAN0IntHandler()
{
uint32_t ui32Status;
//
// Read the CAN interrupt status to find the cause of the interrupt
//
ui32Status = ROM_CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
//
// If the cause is a controller status interrupt, then get the status
//
if(ui32Status == CAN_INT_INTID_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.
//
ui32Status = ROM_CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
//
// Set a flag to indicate some errors may have occurred.
//
g_bErrFlag = 1;
DPRINTF("STATUS Interrupt: ");
vts_itoa(ui32Status,s);
DPRINTF(s);
DPRINTF("\r\n");
}
//
// Check if the cause is message object 1, which what we are using for
// receiving messages.
//
else if(ui32Status == CAN_RXOBJECT)
{
//
// Getting to this point means that the RX interrupt occurred on
// message object 1, and the message reception is complete. Clear the
// message object interrupt.
//
DPRINTF("Rx interrupt\r\n");
ROM_CANIntClear(CAN0_BASE, CAN_RXOBJECT);
//
// Set flag to indicate received message is pending.
//
g_bRXFlag = 1;
//
// Since a message was received, clear any error flags.
//
g_bErrFlag = 0;
}
else if(ui32Status == CAN_TXOBJECT)
{
//
// Getting to this point means that the RX interrupt occurred on
// message object 1, and the message reception is complete. Clear the
// message object interrupt.
//
DPRINTF("Tx interrupt\r\n");
ROM_CANIntClear(CAN0_BASE, CAN_TXOBJECT);
g_bErrFlag = 0;
}
//
// Otherwise, something unexpected caused the interrupt. This should
// never happen.
//
else
{
//
// Spurious interrupt handling can go here.
//
}
}
int main()
{
ROM_FPULazyStackingEnable();
/* Set the clocking to run directly from the crystal. */
//ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
//SYSCTL_XTAL_16MHZ);
/* Set the clocking to run from internal clock and set system clock to 80 MHz*/
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_OSC_INT | SYSCTL_RCC2_USERCC2 | SYSCTL_RCC2_DIV400 );
ROM_SysCtlMOSCConfigSet(SYSCTL_MOSC_NO_XTAL);
ROM_SysCtlDeepSleepClockSet(SYSCTL_DSLP_DIV_1 | SYSCTL_DSLP_OSC_INT30 | SYSCTL_DSLP_PIOSC_PD);
PowerDownInit();
ROM_SysCtlPeripheralClockGating(TM_TRUE);
SysCtlDeepSleepPowerSet(SYSCTL_DSLPPWRCFG_FLASHLPM | SYSCTL_DSLPPWRCFG_SRAMLPM);
InitCAN();
SetCANMessage();
while (1)
{
}
}
Regards
nandish

