AnsweredAssumed Answered

STM32F302R8 CANBus Not Working

Question asked by Marshal Haupt on Jun 26, 2017
Latest reply on Jul 24, 2017 by Marshal Haupt

I need help with the integrated CANBus controller on the NUCLEO STM32F302R8. We are using STM32CubeMX to generate our setup code with the  STM32Cube_FW_F3_V1.8.0v Firmware package provided by ST. We are then using the transmit and receive functions provided by the STM32F3xx_HAL_Driver. The problem is nothing is showing up on the pins. There is nothing on the Tx pin when we set the device to continuously send, and it is not receiving messages from a known-good CANBus network. I suspect the problem is in the setup of the GPIO pins. I have attached my code, but below is a function found in stm32f3xx_hal_msp.c. I suspect that GPIO_InitStruct.Alternate should be GPIO_AF9_CAN.

 

void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{

GPIO_InitTypeDef GPIO_InitStruct;
if(hcan->Instance==CAN)
{
/* USER CODE BEGIN CAN_MspInit 0 */

/* USER CODE END CAN_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_CAN1_CLK_ENABLE();

/**CAN GPIO Configuration
PA11 ------> CAN_RX
PA12 ------> CAN_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_TIM1
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USER CODE BEGIN CAN_MspInit 1 */

/* USER CODE END CAN_MspInit 1 */
}

}

Attachments

Outcomes