cancel
Showing results for 
Search instead for 
Did you mean: 

Getting problems with CAN on a NUCLEO-F207ZG Board

ChristianNo
Associate II

Hello everyone,

 

for a project I try to build a small CAN Bus with several Nucleo 144F207 Boards. Sadly, I have a really hard time to get it to work even though it should be rather simple. The minimum setup consists of two boards and two CAN Tranciever PCB's:

https://www.amazon.de/AZDelivery-CAN-Bus-Transceiver-Breakout-Board-Hochgeschwindigkeits-Physische-kompatibel-Standard/dp/B0CBKLH6SS/ref=sr_1_3?keywords=can%2Btransceiver&qid=1701683744&sr=8-3&th=1

Code is configured/generated via the CubeIDE. The Main Funktion looks like this:

Spoiler

int app_main(void)

{

CAN_TxHeaderTypeDef txHeader;

uint8_t txData[8] = {0};

uint32_t txMailbox;

txHeader.IDE = CAN_ID_STD;

txHeader.StdId = 0x2AA;

txHeader.RTR = CAN_RTR_DATA;

txHeader.DLC = 2;

txData[0] = 50;

txData[1] = 0xAA;

CAN_RxHeaderTypeDef rxHeader; //CAN Bus Transmit Header

uint8_t canRX[8] = {0,0,0,0,0,0,0,0}; //CAN Bus Receive Buffer

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, 0);

// Actual main loop.

while(1)

{

 

HAL_CAN_AddTxMessage(&hcan1, &txHeader, txData, &txMailbox);

 

HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, canRX);

 

if(canRX[1]>0){

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); // Toggle LED

}

}

The Identifier is different for each Board.The configuration in CubeIDE looks as follows:

CAN configurationCAN configuration

Both Boards use CAN1. When I run it in Debugging mode and set a Breakpoint at AddTxMessage and then execute the command I get the following Scope Picture:

Rx(yellow),Tx(blue) BUS(Green/Purple))Rx(yellow),Tx(blue) BUS(Green/Purple))The Tx/Rx lines are at the sending Board in debugging mode. The Rx at the recieving Board gets the signal at the Pin after the Tranciever, but no Arbitration seems to start. I get no other Signals on the bus even with a bigger sampling Window. Does anyone have an Idea why?

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Attached a proposal of CAN bitrate communication @500Kb/s

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

View solution in original post

5 REPLIES 5
SofLit
ST Employee

Hello,

These are not correct parameters for CAN bitrate. 

SofLit_0-1705050176346.png

BS1 =1, B2 = 1, Prescaler = 200! -> very low values for BS1 and BS2 and very High prescaler value!

What is the bitrate you're looking for?

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

Hi,

 

for testing I was aiming at 50kbit/s. The finished system would be closer to 500kBit/s.

Ok, first you need to change BS1, BS2 and prescaler values as I've already suggested: maximize BS1 and BS2 values and minimize the prescaler with BS1 ~=75% (BS1+BS2)

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
SofLit
ST Employee

Attached a proposal of CAN bitrate communication @500Kb/s

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
ChristianNo
Associate II

The Provided configuration worked! Thanks for your help!