Other Parts Discussed in Thread: SYSBIOS
Hi guys,
I’m Luca and I’m working on Tiva chip TM4C129 ( or better XM4…). Now I’m using the EVB EK-TM4C129XL rev C and I’m trying to use the CAN with the interrupt.
My issue is that I’m not able to generate the interrupt in TX mode.
The code is based on LM3S9D chip (works) but I also followed the instruction on spmu298a.pdf document and TI forums suggestions.
I’m compiling with TARGET_IS_TM4C129_RA1 flags and I’m using the TivaWare_C_Series-2.1.0.12573 library.
The examples on this library in any case is not for this platform because some of the ROM function is not include on lib (for example ROM_GPIOPinTypeCAN) .
Attached the implementation and the ISR. I used the app.cfg to generate the code. The interrupt use the “interrupt number” 54.
void CANDriverInit()
{
tCANMsgObject CANRecvMessage;
//tCANBitClkParms CANBitClk;
uint32_t freq = 0;
// enable peripeheral controller for CAN0
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
// configure the pins
//should be not needed?????? - only pin 33-CAN0RC and ping 34-CAN0TX are designed to use as CAN 0
ROM_GPIOPinConfigure(GPIO_PA0_CAN0RX);
ROM_GPIOPinConfigure(GPIO_PA1_CAN0TX);
// - not in new api Enable the alternate function on the GPIO pins.?????
//ROM_GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// enable and init CAN0
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
ROM_CANInit(CAN0_BASE);
//ROM_CANRetrySet(CAN0_BASE, 1);
#ifndef PORTING_TIVA // old
ROM_CANBitRateSet(CAN0_BASE, ROM_SysCtlClockGet(), CAN_BITRATE);
#else
//todo - to be check
//freq = ROM_SysCtlClockFreqSet((SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
//CANSetBitTiming(CAN0_BASE, &CANBitClk); //-nothing to do
//ROM_CANBitRateSet(CAN0_BASE, freq, CAN_BITRATE);; //-nothing to do
//ROM_CANBitRateSet(CAN0_BASE, ROM_SysCtlClockGet(), CAN_BITRATE);; //-nothing to do
ROM_CANBitRateSet(CAN0_BASE, 120000000, CAN_BITRATE);
#endif
/* to test - not ok
// @80MHz, 500kbps = 4 / 3 / 0 / 20
tCANClkParams.ui32SyncPropPhase1Seg = 4;
tCANClkParams.ui32Phase2Seg = 3;
tCANClkParams.ui32SJW = 1;
tCANClkParams.ui32QuantumPrescaler = 20;
ROM_CANBitTimingSet(CAN0_BASE, &tCANClkParams);
however, did not work following code.
// @80MHz, 1000kbps = 4 / 3 / 0 / 10
tCANClkParams.ui32SyncPropPhase1Seg = 4;
tCANClkParams.ui32Phase2Seg = 3;
tCANClkParams.ui32SJW = 1;
tCANClkParams.ui32QuantumPrescaler = 10;
ROM_CANBitTimingSet(CAN0_BASE, &tCANClkParams);
CANBitClk.ui32SyncPropPhase1Seg = 5;
CANBitClk.ui32Phase2Seg = 5;
CANBitClk.ui32SJW = 2;
CANBitClk.ui32QuantumPrescaler = 2;
ROM_CANBitTimingSet(CAN0_BASE, &CANBitClk);
*/
// Enable interrupt for Can event or for Bus-Off
ROM_CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
// Enable the CAN interrupt on the processor (NVIC).
ROM_IntEnable(INT_CAN0);
ROM_CANEnable(CAN0_BASE);
//not needed and not working
//CANIntRegister(CAN0_BASE,&CANInterruptHandler);
CANRecvMessage.ui32MsgID = 0; // CAN msg ID - 0 for any
CANRecvMessage.ui32MsgIDMask = 0; // mask is 0 for any ID
CANRecvMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER | MSG_OBJ_EXTENDED_ID | MSG_OBJ_FIFO;
CANRecvMessage.ui32MsgLen = 8; // allow up to 8 bytes
ROM_CANMessageSet(CAN0_BASE, 1, &CANRecvMessage, MSG_OBJ_TYPE_RX);
ROM_CANMessageSet(CAN0_BASE, 2, &CANRecvMessage, MSG_OBJ_TYPE_RX);
.....
CANRecvMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER | MSG_OBJ_EXTENDED_ID;
ROM_CANMessageSet(CAN0_BASE, 31, &CANRecvMessage, MSG_OBJ_TYPE_RX);
}
void CANInterruptHandler(void)
{
...
unsigned long mailboxNum = 0;
mailboxNum = ROM_CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
...
}
void sendMsg(..)
{
...
CANSendMessage.ui32MsgLen = 8;
CANSendMessage.ui32MsgID = 1;
CANSendMessage.ui32MsgIDMask = 0;
CANSendMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
ROM_CANMessageSet(CAN0_BASE, 32, &CANSendMessage, MSG_OBJ_TYPE_TX);
..
}
Does anyone have some suggestion?
Thanks
Luca