2024-01-12 12:54 AM - last edited on 2024-01-12 02:14 AM by SofLit
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:
Code is configured/generated via the CubeIDE. The Main Funktion looks like this:
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:
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:
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?
Solved! Go to Solution.
2024-01-12 02:31 AM
Attached a proposal of CAN bitrate communication @500Kb/s
2024-01-12 01:04 AM - edited 2024-01-12 01:05 AM
Hello,
These are not correct parameters for CAN bitrate.
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?
2024-01-12 01:46 AM
Hi,
for testing I was aiming at 50kbit/s. The finished system would be closer to 500kBit/s.
2024-01-12 01:50 AM - edited 2024-01-12 01:53 AM
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)
2024-01-12 02:31 AM
2024-01-12 02:51 AM
The Provided configuration worked! Thanks for your help!