2016-06-02 05:52 AM
Hello. I have initialized CAN1 and it works properly. I need initialize after a while CAN2 and it is finishing on timeout because INAK is stil TRUE. Where can be problem?
Thanks, Jiri #can2-stm32f407-inak2016-06-02 06:07 AM
I've used both CAN buses on the F407, so its not the chip.
Perhaps we should look more critically at exactly what you are doing on the software/hardware side. CAN2 depends on CAN1 for resources and clocks CAN2 uses different filter levels.2016-06-02 06:19 AM
Hi clive1.
I know it. I am using filter 0 for CAN1 and filter 14 for CAN2. I successfully use CAN1. These initialization of CAN2 fails: /* Enable GPIO clock */ //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); __GPIOB_CLK_ENABLE(); /* Enable CAN clock */ __CAN2_CLK_ENABLE(); /* CAN1 TX GPIO pin configuration */ GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Alternate = GPIO_AF9_CAN2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* CAN1 RX GPIO pin configuration */ GPIO_InitStruct.Pin = GPIO_PIN_6; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* CAN configuration ********************************************************/ CanHandle2.Instance = CAN2; /* CAN register init */ //HAL_CAN_DeInit(&CanHandle2); /* CAN cell init */ CanHandle2.pTxMsg = &TxMessage2; CanHandle2.pRxMsg = &RxMessage2; CanHandle2.Init.TTCM = DISABLE; CanHandle2.Init.ABOM = DISABLE; CanHandle2.Init.AWUM = DISABLE; CanHandle2.Init.NART = ENABLE; //DISABLE; CanHandle2.Init.RFLM = DISABLE; CanHandle2.Init.TXFP = DISABLE; CanHandle2.Init.Mode = CAN_MODE_NORMAL; CanHandle2.Init.SJW = CAN_SJW_1TQ; CanHandle2.Init.BS1 = CAN_BS1_3TQ; //6TQ; CanHandle2.Init.BS2 = CAN_BS2_2TQ; //8TQ; CanHandle2.Init.Prescaler = 7 << Pre; // 0 ... 1 MBaud, 1 .. 500k, 2 .. 250k, 3 .. 125k if(HAL_CAN_Init(&CanHandle2) != HAL_OK) { /* Initialization Error */ for(;;); // ToDo remove / / ********** It is ending here with timeout error and CAN2->MSR is 9 }2016-06-02 07:54 AM
Hi antos.jiri,
You have to enable also CAN1 clock.
As mentionned in reference manual RM0090, “Dual CAN� part ( page 1069) :
''- CAN1: Master bxCAN for managing the communication between a Slave
bxCAN and the 512-byte SRAM memory. -CAN2: Slave bxCAN, with no direct access to the SRAM memory.'' Hence when using CAN2 it's obligatory to enable the Clock of CAN1 accordingly.-Hannibal-
Hi clive1.
I know it. I am using filter 0 for CAN1 and filter 14 for CAN2. I successfully use CAN1. These initialization of CAN2 fails: /* Enable GPIO clock */ //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); __GPIOB_CLK_ENABLE(); /* Enable CAN clock */ __CAN2_CLK_ENABLE(); /* CAN1 TX GPIO pin configuration */ GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Alternate = GPIO_AF9_CAN2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* CAN1 RX GPIO pin configuration */ GPIO_InitStruct.Pin = GPIO_PIN_6; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* CAN configuration ********************************************************/ CanHandle2.Instance = CAN2; /* CAN register init */ //HAL_CAN_DeInit(&CanHandle2); /* CAN cell init */ CanHandle2.pTxMsg = &TxMessage2; CanHandle2.pRxMsg = &RxMessage2; CanHandle2.Init.TTCM = DISABLE; CanHandle2.Init.ABOM = DISABLE; CanHandle2.Init.AWUM = DISABLE; CanHandle2.Init.NART = ENABLE; //DISABLE; CanHandle2.Init.RFLM = DISABLE; CanHandle2.Init.TXFP = DISABLE; CanHandle2.Init.Mode = CAN_MODE_NORMAL; CanHandle2.Init.SJW = CAN_SJW_1TQ; CanHandle2.Init.BS1 = CAN_BS1_3TQ; //6TQ; CanHandle2.Init.BS2 = CAN_BS2_2TQ; //8TQ; CanHandle2.Init.Prescaler = 7 << Pre; // 0 ... 1 MBaud, 1 .. 500k, 2 .. 250k, 3 .. 125k if(HAL_CAN_Init(&CanHandle2) != HAL_OK) { /* Initialization Error */ for(;;); // ToDo remove / / ********** It is ending here with timeout error and CAN2->MSR is 9 }2016-06-02 10:28 PM
Hi Hannibal,
I have enabled CAN1 clock. My SW working by this way: 1. I receive command by CAN1 and set some flag 2. main loop, when this flag is true, starts initialization of CAN2 I have an idea, that there is something wrong in HW, but driver is same as for CAN1 and connection is too simple - 2 wires between micro and driver. Jiri2016-06-03 12:28 AM
Hi everybody,
I want to use GPIOB.5 and .6 to connect CAN2 driver. Wires GPIOB.12 and .13 I have free, therefore I change CAN2 pins to this. CAN2 is starting now. I am testing crazy configuration - I have enabled both pins for CAN2TX (B.5 and B.12) and CAN2RX (B.6 and B.13). Initalisation is finished OK. Will it work for communication? Jiri2016-06-03 04:48 AM
Hi everybody.
STM32F407 is OK. I have something wrong on secondary side of CAN driver. Jiri2016-06-03 05:35 AM
I have pull-up resistor on CAN-H line and pull-down resistor in CAN-L line.
When I removed them, everythink is OK. Jiri2016-06-03 07:43 AM
Hi antos.jiri,
It is nice to hear that. Keep the good work. -Hannibal-