Dear all
I'm trying to use CAN controller on demo board DK-TM4C129X.
I wont ti use CAN controller CAN0 to send massage and CAN1 to read message.
CAN0 have PA0= CAN0RX and PA1=CAN0TX.
CAN1 have PB0= CAN1RX and PB1=CAN1TX.
I wired on the demoboard PA0= CAN0_RX with PB1=CAN1_TX and PA1= CAN0_TX with PB0=CAN1_RX to
emulete a transmission.
But when i debug the code I see that the esecution dont run and the debugger still fixed after the system clock initialization.
In the following my code:
//*****************************************************************************
// interrupt handler for the CAN0 peripheral.
//*****************************************************************************
void CANIntHandler(void)
{
uint32_t ui32Status;
// Read the CAN interrupt status to find the cause of the interrupt
ui32Status = 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.
ui32Status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
// Set a flag to indicate some errors may have occurred.
g_bErrFlag = 1;
}
//
// Check if the cause is message object 1, which what we are using for
// sending messages.
//
else if(ui32Status == 1)
{
// Getting to this point means that the TX interrupt occurred on
// message object 1, and the message TX is complete. Clear the
// message object interrupt.
CANIntClear(CAN0_BASE, 1);
// Increment a counter to keep track of how many messages have been
// sent. In a real application this could be used to set flags to
// indicate when a message is sent.
g_ui32MsgCount++;
// Since the message was sent, clear any error flags.
g_bErrFlag = 0;
}
//
// Otherwise, something unexpected caused the interrupt. This should
// never happen.
//
else
{
//
// Spurious interrupt handling can go here.
//
}
}
//*****************************************************************************
// main
//*****************************************************************************
int main(void)
{
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | // Run from the PLL at 120 MHz.
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA|SYSCTL_PERIPH_GPIOB );
// Configure the GPIO pin muxing to select CAN0 and CAN1 functions for these pins.
GPIOPinConfigure(GPIO_PA0_CAN0RX); // firmware stall here
GPIOPinConfigure(GPIO_PA1_CAN0TX);
GPIOPinConfigure(GPIO_PB0_CAN1RX);
GPIOPinConfigure(GPIO_PB1_CAN1TX);
// Enable the alternate function on the GPIO pins.
GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// Enable CAN0 e CAN1 peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN1);
// Initialize the CAN0 e CAN1 controller
CANInit(CAN0_BASE);
CANInit(CAN1_BASE);
// Set up the bit rate for the CAN0 and CAN1 to 500KHz
CANBitRateSet(CAN0_BASE, ui32SysClock, 500000);
CANBitRateSet(CAN1_BASE, ui32SysClock, 500000);
//-- Enable interrupts on the CAN0 peripheral ---------------------------------
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
// Enable the CAN0 interrupt on the processor (NVIC).
IntEnable(INT_CAN0);
// Enable the CAN0 for operation.
CANEnable(CAN0_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.
ui32MsgData = 0;
sCANMessageTX.ui32MsgID = 1;
sCANMessageTX.ui32MsgIDMask = 0;
sCANMessageTX.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
sCANMessageTX.ui32MsgLen = sizeof(pui8MsgData);
sCANMessageTX.pui8MsgData = pui8MsgData;
// Enable the CAN1 for operation.
CANEnable(CAN1_BASE);
// Initialize a message object to be used for receiving CAN messages with
// any CAN ID. In order to receive any CAN ID, the ID and mask must both
// be set to 0, and the ID filter enabled.
sCANMessageRX.ui32MsgID = 0;
sCANMessageRX.ui32MsgIDMask = 0;
sCANMessageRX.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
sCANMessageRX.ui32MsgLen = 8;
// 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 uint32_t
// and incremented by one each time.
while(1)
{
// Send the CAN message
CANMessageSet(CAN0_BASE, 1, &sCANMessageTX, MSG_OBJ_TYPE_TX); // CAN0 trasmit message object
while((CANStatusGet(CAN1_BASE, CAN_STS_NEWDAT)&1)== 0)
{
CANMessageGet(CAN1_BASE, 1, &sCANMessageRX, 0);
}
// Increment the value in the message data.
ui32MsgData++;
}
//
// Return no errors
//
return(0);
}
Many thanks for the support
best regards
Marco