Skip to main content
CBrun.5
Associate
August 11, 2022
Question

STM32F446ZET6 - Struggling to get the CAN running

  • August 11, 2022
  • 1 reply
  • 420 views

Hi,

I'm struggling to get the CAN working on a project I'm working on with the STM32F446ZET6. With the project below (CastletRestart) i just get a flat line of 3.3V high on the TX line for CAN1, this is being tested in loop back mode, with the TUT_CAN_F446 project the can works (downloaded from a tutorial) in loopback mode, as far as i can see ive replicated everything across but it still isnt working.

Its likely to be something silly and i do apologise for this being the case but i cannot see what ive missed having reviewed the code countless times.

P.s. i am aware the Tutorial project is targeted at a different micro, but the CAN1 ports are the same.

Any advice welcomed, thank you for your time

Chris

This topic has been closed for replies.

1 reply

mƎALLEm
ST Technical Moderator
September 22, 2026

Hello,

You didn’t mention what problem you’ve faced? 

I assume the issue is the Rx side of TUT_CAN_F446.

By reviewing your code, 

This code is from “CastletRestart” side:

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define DEBUG_LOOP 1u

CAN_TxHeaderTypeDef txHeader;
uint8_t data[2] = {0x55, 0xAA};
uint32_t mailbox;
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
* @brief The application entry point.
* @retval int
*/
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_CAN1_Init();
//MX_CAN2_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
HAL_ADC_Start_IT(&hadc1);
HAL_CAN_Start(&hcan1);
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
#if DEBUG_LOOP
static bool toggle = false;
HAL_GPIO_WritePin(DIAG_LED2_GPIO_Port, DIAG_LED2_Pin, toggle);
HAL_GPIO_WritePin(DIAG_LED1_GPIO_Port, DIAG_LED1_Pin, toggle);
toggle = !toggle;


HAL_CAN_AddTxMessage(&hcan1,&txHeader,&data[0], &mailbox);
HAL_Delay(500);
#endif
}
/* USER CODE END 3 */
}

→ Here you didn’t initialize the txHeader structure therefore the ID sent by  “CastletRestart” is undefined.

In the same hand you are configuring a filter from the “TUT_CAN_F446” side:

  canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
canfilterconfig.FilterIdHigh = 0x103<<5;
canfilterconfig.FilterIdLow = 0;
canfilterconfig.FilterMaskIdHigh = 0x103<<5;
canfilterconfig.FilterMaskIdLow = 0x0000;

→ most probably that undefined ID sent by “CastletRestart” doesn’t pass this filter. So instead set pass-all-IDs filter:

  canfilterconfig.FilterIdHigh = 0x0000;
canfilterconfig.FilterIdLow = 0x0000;
canfilterconfig.FilterMaskIdHigh = 0x0000;
canfilterconfig.FilterMaskIdLow = 0x0000;

In other hand, please avoid HSI for the CAN communication in Normal mode. You have this from “CastletRestart” side:

Also avoid low BSx values for the CAN bit time setting such as BS1=BS2=2.

You can review these articles:

Hope that helps you as well as others ..

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.