AnsweredAssumed Answered

enable CAN1_RX0_IRQn and CAN1_SCE_IRQn

Question asked by do.khiem on Oct 17, 2014
Latest reply on Oct 20, 2014 by do.khiem
I have a CAN bus project that needs to use both CAN1_RX0_IRQn and CAN1_SCE_IRQn. But it happened is that when I enabled both of the interrupts, then the interrupts did not work at all. Here is my CanConfig():

01.#define CAN1_CLK                    RCC_APB1Periph_CAN1
02.#define CAN1_RX_PIN                 GPIO_Pin_0
03.#define CAN1_TX_PIN                 GPIO_Pin_1
04.#define CAN1_GPIO_PORT              GPIOD
05.#define CAN1_GPIO_CLK               RCC_AHB1Periph_GPIOD
06.#define CAN1_AF_PORT                GPIO_AF_CAN1
07.#define CAN1_RX_SOURCE              GPIO_PinSource0
08.#define CAN1_TX_SOURCE              GPIO_PinSource1
09. 
10.uint8_t CANConfig1(void) {
11.    /* CAN1 Periph clock enable */
12.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
13. 
14.    /* CAN GPIOs configuration **************************************************/
15.    GPIO_InitTypeDef GPIO_InitStructure;
16.    NVIC_InitTypeDef NVIC_InitStructure;
17. 
18.    /* Enable GPIO clock */
19.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
20.    /* Configure CAN RX and TX pins */
21.    GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;
22.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
23.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
24.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
25.    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
26.    GPIO_Init(GPIOD, &GPIO_InitStructure);
27.    GPIO_PinAFConfig(GPIOD, CAN_RX_SOURCE, GPIO_AF_CAN1);
28.    GPIO_PinAFConfig(GPIOD, CAN_TX_SOURCE, GPIO_AF_CAN1);
29. 
30.    CAN_InitTypeDef CAN_InitStructure;
31.    CAN_FilterInitTypeDef CAN_FilterInitStructure;
32. 
33.    /* CAN register init */
34.    CAN_DeInit(CAN1);
35.    /* CAN cell init */
36.    CAN_InitStructure.CAN_TTCM = DISABLE;
37.    CAN_InitStructure.CAN_ABOM = DISABLE;
38.    CAN_InitStructure.CAN_AWUM = DISABLE;
39.    CAN_InitStructure.CAN_NART = DISABLE;
40.    CAN_InitStructure.CAN_RFLM = DISABLE;
41.    CAN_InitStructure.CAN_TXFP = DISABLE;
42.    CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
43.    CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
44.    /* Baudrate = 250 Kbps */
45.    CAN_InitStructure.CAN_BS1 = CAN_BS1_14tq;
46.    CAN_InitStructure.CAN_BS2 = CAN_BS2_6tq;
47.    CAN_InitStructure.CAN_Prescaler = 8;
48.    CAN_Init(CAN1, &CAN_InitStructure);
49. 
50.    /* CAN filter init */
51.    CAN_FilterInitStructure.CAN_FilterNumber = 1;
52.    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
53.    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;
54.    CAN_FilterInitStructure.CAN_FilterIdHigh = 0x000 << 5;
55.    CAN_FilterInitStructure.CAN_FilterIdLow = 0x000 << 5;
56.    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x000 << 5;
57.    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x000 << 5;
58.    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
59.    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
60.    CAN_FilterInit(&CAN_FilterInitStructure);
61. 
62.    /* Enable CAN1 RX0 interrupt IRQ channel */
63.//  NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn| CAN1_SCE_IRQn;  //not working
64.    NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;  // working
65.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
66.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
67.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
68.    NVIC_Init(&NVIC_InitStructure);
69. 
70.    /* CAN FIFO0 message pending interrupt enable */
71.    CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
72.    CAN_ITConfig(CAN1, CAN_IT_BOF | CAN_IT_EPV | CAN_IT_EWG | CAN_IT_ERR,
73.            ENABLE);
74.    return 0;
75.}

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 :(

Outcomes