I'm trying to use the CAN of STM32F3, but I'm having some troubles. I read some tutorials and followed the instructions, but I think I'm making some mistakes. The code bellow is running as a freeRTOS task, and should work as polling to CAN Rx.
#include "FreeRTOS.h"
#include "cmsis_os.h"
#include "stdio.h"
#include "stm32f3xx_hal_can.h"
#include "can.h"
#include "usart.h"
void canRx(void const *argument)
{
/* USER CODE BEGIN canRx */
/* Infinite loop */
uint8_t receivedMessage[8];
CAN_RxHeaderTypeDef RxHeader;
HAL_CAN_Start(&hcan);
for (;;)
{
if(HAL_CAN_GetRxFifoFillLevel(&hcan, CAN_RX_FIFO0) != 0)
{
HAL_CAN_GetRxMessage(&hcan, CAN_RX_FIFO0, &RxHeader, receivedMessage);
}
HAL_UART_Transmit(&huart2, receivedMessage, 8, portMAX_DELAY);
osDelay(200);
}
/* USER CODE END canRx */
}
I just want to read the Rx data sent from a arduino which works as an other CAN node. The arduino loop has a counter which is incremented of 1 each 200ms and is sent to STM via CAN.
I want receive in the UART2 the ID and Message from CAN receiver(the STM32). I'll compare these data with the data from the sender, I get this data from an Arduino Serial, and check the hit rate(I hope 100%).
How to make it work well?