Hi everybody,
I am trying to write simple code that implementing the CAN serial protocol and here is the transmitter launchpad code.
i observe that when i step over the
CANIntRegister(CAN0_BASE, CANIntHandler);
function the white led is just turning on (take a look to the handler code) and the execution stops on the following line
I try to register the handler statically in the startup file then, when i step over the
IntEnable(INT_CAN0) ;
function it turn on the white led and the execution stops at the following line in the code.
In both cases i try to continue stepping to see what happen after CANmsgSet() .. i find out the code is getting stuck in the handler forever (the led blinking continuously)..
could somebody help please ?
regards,
Sarea
#pragma diag_push
#pragma CHECK_MISRA("none")
#include <stdint.h>
#include <stdbool.h>
#include "stdlib.h"
//#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_uart.h"
#include "inc/hw_gpio.h"
#include "inc/hw_pwm.h"
#include "inc/hw_types.h"
#include "driverlib/timer.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/udma.h"
#include "driverlib/pwm.h"
#include "driverlib/ssi.h"
#include "driverlib/can.h"
#include "driverlib/systick.h"
#include <string.h>
#include <uartstdio.h>
#include <SysTick_Init.h>
#include <PORTF_Init.h>
#pragma diag_pop
void CANIntHandler(void);
int main(void) ;
int main(void){
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
PORTF_Init() ;
// CAN0 and PORTE configurations
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE) ;
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE)){}
GPIOPinConfigure(GPIO_PE4_CAN0RX) ;
GPIOPinConfigure(GPIO_PE5_CAN0TX) ;
GPIOPinTypeCAN(GPIO_PORTE_BASE, GPIO_PIN_4|GPIO_PIN_5) ;
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0) ;
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN0)){}
CANInit(CAN0_BASE) ;
CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000) ;
CANIntRegister(CAN0_BASE, CANIntHandler);
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
IntEnable(INT_CAN0) ;
CANEnable(CAN0_BASE) ;
// set up the CAN message object
tCANMsgObject msg ;
uint32_t msgData;
uint8_t *msgDataPtr = (uint8_t *) &msgData ;
msgData = 0;
msg.ui32MsgID = 1;
msg.ui32MsgIDMask = 0 ;
msg.ui32Flags = MSG_OBJ_TX_INT_ENABLE ;
msg.ui32MsgLen = sizeof(msgDataPtr) ;
msg.pui8MsgData = msgDataPtr ;
while(1){
CANMessageSet(CAN0_BASE, 1, &msg, MSG_OBJ_TYPE_TX) ;
SysTick80_Delay_10ms(300) ;
}
return 0;
}
void CANIntHandler(void){
GPIO_PORTF_DATA_R ^= 0x0E ; // toggle the white LED
SysTick80_Delay_10ms(300) ;
CANIntClear(CAN0_BASE, 1); // clear interrupt
unsigned long status = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE); // read interrupt status
if(status == CAN_INT_INTID_STATUS) { // controller status interrupt
status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL); // read back error bits, do something with them?
} else if(status == 1) { // message object 1
CANIntClear(CAN0_BASE, 1); // clear interrupt
}
}