cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F303K8 - CAN bus doing nothing?

MP.17
Associate II

Hi there,

we are using the STM32F303K8 with the NUCLEO-F303K8 board. I installed the latest STM32 Cube IDE v.1.0.0 and wanted to get the CAN bus working.

So after searching for the latest documentation it took a while to figure out the new can bus implenentation. So as mentioned in "STM32L$ CAN new API and migration.pdf" my code looks like this:

int main(void)
 
{
 
 /* USER CODE BEGIN 1 */
 
 
 /* USER CODE END 1 */
 
 
 
 /* MCU Configuration--------------------------------------------------------*/
 
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 
 HAL_Init();
 
 
 /* USER CODE BEGIN Init */
 
 
 /* USER CODE END Init */
 
 
 /* Configure the system clock */
 
 SystemClock_Config();
 
 
 /* USER CODE BEGIN SysInit */
 
 
 /* USER CODE END SysInit */
 
 
 /* Initialize all configured peripherals */
 
 MX_GPIO_Init();
 
 MX_USART2_UART_Init();
 
 MX_CAN_Init();
 
 MX_SPI1_Init();
 
 /* USER CODE BEGIN 2 */
 
 
 
 CAN_FilterTypeDef sFilterConfig;
 
 CAN_TxHeaderTypeDef TxHeader;
 
 CAN_RxHeaderTypeDef RxHeader;
 
 uint8_t TxData[8];
 
 uint8_t RxData[8];
 
 uint32_t TxMailbox;
 
 
 
 /* USER CODE BEGIN 2 */
 
 sFilterConfig.FilterBank         = 0;
 
 sFilterConfig.FilterMode         = CAN_FILTERMODE_IDMASK;
 
 sFilterConfig.FilterScale         = CAN_FILTERSCALE_32BIT;
 
 sFilterConfig.FilterIdHigh      = 0x0000;
 
 sFilterConfig.FilterIdLow         = 0x0000;
 
 sFilterConfig.FilterMaskIdHigh   = 0x0000;
 
 sFilterConfig.FilterMaskIdLow      = 0x0000;
 
 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
 
 sFilterConfig.FilterActivation   = ENABLE;
 
 sFilterConfig.SlaveStartFilterBank = 14;
 
 
 if(HAL_CAN_ConfigFilter(&hcan, &sFilterConfig)!=HAL_OK){
 
    /* Filter configuration Error */
 
    Error_Handler();
 
 }
 
 
 if(HAL_CAN_Start(&hcan)!=HAL_OK){
 
    /* Start Error */
 
    Error_Handler();
 
 }
 
 
 if(HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING |CAN_IT_TX_MAILBOX_EMPTY)!=HAL_OK){
 
    /* Notification Error */
 
    Error_Handler();
 
 }
 
 
 TxHeader.StdId = 0x321;
 
 TxHeader.ExtId = 0x01;
 
 TxHeader.RTR  = CAN_RTR_DATA;
 
 TxHeader.IDE  = CAN_ID_STD;
 
 TxHeader.DLC  = 8;
 
 TxHeader.TransmitGlobalTime = DISABLE;
 
 TxData[0] = 1;
 
 TxData[1] = 2;
 
 TxData[2] = 3;
 
 TxData[3] = 4;
 
 TxData[4] = 5;
 
 TxData[5] = 6;
 
 TxData[6] = 7;
 
 TxData[7] = 8;
 
 
 while(1){
 
    /* USER CODE BEGIN 3 */
 
    HAL_CAN_AddTxMessage(&hcan,&TxHeader,TxData,&TxMailbox);
 
    HAL_Delay(500);
 
    TxData[7]=TxData[7]+1;
 
 }
 
 
 
 /* Infinite loop */
 
 /* USER CODE BEGIN WHILE */
 
 while (1)
 
 {
 
   /* USER CODE END WHILE */
 
 
   /* USER CODE BEGIN 3 */
 
 }
 
 /* USER CODE END 3 */
 

}

So far so good,

so my PORT Map is defined as follows:

PA12 = CAN_TX

PA11 = CAN_RX

PA3 = external IRQ

PA5 = SPI SCK

PA6 = SPI MISO

PA7 = SPI MOSI

PA8 = SPI CS_SS

My System Core -> NVIC Configuration:

...

CAN TX Interrupt = CHECKED

CAN RX0 Interrupt = CHECKED

CAN RX1 Interrupt = CHECKED

CAN SCE Interrupt = CHECKED

Connectivity -> CAN

MASTER MODE = CHECKED

In my opinion everything should be configured fine, so by running the main nothing happens on the pins using my oscilloscope:

PA11 -> D10

PA12 -> D2

Did I miss something to configure?

1 REPLY 1
MP.17
Associate II

EDIT:

Seems to be an IDE problem: @ CAN CONFIG, IT SEEMS "ENABLE" in in reality "DISABLE" so inverted?!

Ok got it. Seems something with your introduction PDF is wrong:

0690X000008w1r3QAA.png

After ENABLING the red marked CAN Config, the CAN BUS starts working as expected with your example:

0690X000008w1sfQAA.png