cancel
Showing results for 
Search instead for 
Did you mean: 

enable CAN1_RX0_IRQn and CAN1_SCE_IRQn

fnick2812
Associate
Posted on October 17, 2014 at 11:21

I have a CAN bus project that needs to use bothCAN1_RX0_IRQn and CAN1_SCE_IRQn. But it happened is that when I enabledboth of the interrupts, then the interrupts did not work at all. Here is my CanConfig():


#define CAN1_CLK RCC_APB1Periph_CAN1

#define CAN1_RX_PIN GPIO_Pin_0

#define CAN1_TX_PIN GPIO_Pin_1

#define CAN1_GPIO_PORT GPIOD

#define CAN1_GPIO_CLK RCC_AHB1Periph_GPIOD

#define CAN1_AF_PORT GPIO_AF_CAN1

#define CAN1_RX_SOURCE GPIO_PinSource0

#define CAN1_TX_SOURCE GPIO_PinSource1


uint8_t CANConfig1(
void
) {

/* CAN1 Periph clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);


/* CAN GPIOs configuration **************************************************/

GPIO_InitTypeDef GPIO_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;


/* Enable GPIO clock */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

/* Configure CAN RX and TX pins */

GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOD, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOD, CAN_RX_SOURCE, GPIO_AF_CAN1);

GPIO_PinAFConfig(GPIOD, CAN_TX_SOURCE, GPIO_AF_CAN1);


CAN_InitTypeDef CAN_InitStructure;

CAN_FilterInitTypeDef CAN_FilterInitStructure;


/* CAN register init */

CAN_DeInit(CAN1);

/* CAN cell init */

CAN_InitStructure.CAN_TTCM = DISABLE;

CAN_InitStructure.CAN_ABOM = DISABLE;

CAN_InitStructure.CAN_AWUM = DISABLE;

CAN_InitStructure.CAN_NART = DISABLE;

CAN_InitStructure.CAN_RFLM = DISABLE;

CAN_InitStructure.CAN_TXFP = DISABLE;

CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;

CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

/* Baudrate = 250 Kbps */

CAN_InitStructure.CAN_BS1 = CAN_BS1_14tq;

CAN_InitStructure.CAN_BS2 = CAN_BS2_6tq;

CAN_InitStructure.CAN_Prescaler = 8;

CAN_Init(CAN1, &CAN_InitStructure);


/* CAN filter init */

CAN_FilterInitStructure.CAN_FilterNumber = 1;

CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;

CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;

CAN_FilterInitStructure.CAN_FilterIdHigh = 0x000 << 5;

CAN_FilterInitStructure.CAN_FilterIdLow = 0x000 << 5;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x000 << 5;

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x000 << 5;

CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;

CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;

CAN_FilterInit(&CAN_FilterInitStructure);


/* Enable CAN1 RX0 interrupt IRQ channel */

// NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn| CAN1_SCE_IRQn; //not working

NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn; 
// working

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);


/* CAN FIFO0 message pending interrupt enable */

CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);

CAN_ITConfig(CAN1, CAN_IT_BOF | CAN_IT_EPV | CAN_IT_EWG | CAN_IT_ERR,

ENABLE);

return
0;

}

My interrupt routines, I just leave them empty, like this:

void CAN1_SCE_IRQHandler(void) {
}

I tested my method of sending which is correct but receiving method has the problem as stated above. My board is stm32f4 discovery. Can you help me to see what i do wrong :(
2 REPLIES 2
Posted on October 17, 2014 at 13:58

NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn| CAN1_SCE_IRQn;

Yeah, can't OR them together like that.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fnick2812
Associate
Posted on October 20, 2014 at 04:44

:)) what a stupid mistake. Thanks you very much.