Skip to main content
APatel1
Associate
April 4, 2022
Question

CAN Communication b/w STM32F753Z8 and Arduino Board

Hello Everyone,

I have a two arduino boards communicating with each other on a CAN Bus. Arduino is connected to CAN Bus via MCP2515 .

Both arduino are communicating correctly with each other. Here is an example of my transmitter on arduino:

/*************************************************/

#include <SPI.h>

#include <mcp2515.h>

/*******************MESSAGES DEFINITIONS*****************/

#include <SPI.h>

#include <mcp2515.h>

struct can_frame canMsg1;

struct can_frame canMsg2;

MCP2515 mcp2515(10);

void setup() {

 canMsg1.can_id = 0x0F6;

 canMsg1.can_dlc = 8;

 canMsg1.data[0] = 0x8E;

 canMsg1.data[1] = 0x87;

 canMsg1.data[2] = 0x32;

 canMsg1.data[3] = 0xFA;

 canMsg1.data[4] = 0x26;

 canMsg1.data[5] = 0x8E;

 canMsg1.data[6] = 0xBE;

 canMsg1.data[7] = 0x86;

 canMsg2.can_id = 0x036;

 canMsg2.can_dlc = 8;

 canMsg2.data[0] = 0x0E;

 canMsg2.data[1] = 0x00;

 canMsg2.data[2] = 0x00;

 canMsg2.data[3] = 0x08;

 canMsg2.data[4] = 0x01;

 canMsg2.data[5] = 0x00;

 canMsg2.data[6] = 0x00;

 canMsg2.data[7] = 0xA0;

  

 while (!Serial);

 Serial.begin(115200);

 mcp2515.reset();

 mcp2515.setBitrate(CAN_250KBPS, MCP_8MHZ);

 mcp2515.setNormalMode(); 

 Serial.println("Example: Write to CAN");

}

void loop() {

 mcp2515.sendMessage(&canMsg1);

 mcp2515.sendMessage(&canMsg2);

 Serial.println("Messages sent"); 

 delay(100);

}

/*************************/

Now I'm trying to receive data on an STM32F753Z8 with a ICTCAN33C71XXXXXXX00 transceiver module but nothing is being received in the STM32F753Z8 from the arduino side. Since the arduino's are communicating to each other.

I ahve also tried to receive the data on Arduino side fro the STM32. But I couldn't get success.

My code for STM32 is attached in a file. Any thoughts on what I'm doing wrong or what I'm missing?

I have set the NVIC interrupt on CAN2 RX1 intr.

Baudrate :250kbps

ABP1 peripheral Clock: 13.5 mHZ

This topic has been closed for replies.

1 reply

mƎALLEm
ST Technical Moderator
September 23, 2026

Hello,

I review your code and seems the CAN bitrate is not set at 250kb/s but rather to non standard bitrate 843750bit/s!!

From your code:

RCC config:

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}

CAN bit time settings: 

  hcan1.Init.Prescaler = 2;
hcan1.Init.TimeSeg1 = CAN_BS1_5TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;

I did the simulation in the CubeMx where the APB1 = 13.5 with CAN prescaler = 2, BS1 = 5 and BS2 = 2

Its gives the following:

PS: there is no part number: STM32F753Z8

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.