cancel
Showing results for 
Search instead for 
Did you mean: 

CANBUS Working on Loopback but not in normal

PatTheTrickster
Associate III

I am trying to set up a CANBUS connection between two STM32L4 Microcontrollers and while having has been setup correctly and none of the microcontrollers are sending error messages I cannot seem to get a Receive message from either CAN transceiver.

The two Microcontrollers I have are a Nucleo-L4R5ZI-P and a NUCLEO-L4A6ZG. The goal I am trying to achieve is the user button on the L4R5ZI-P and having it flash a light on the L4A6ZG.

The configuration I have for The L4R5ZI-P is: 

CAN_FilterTypeDef canfilterconfig;

canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 18;
canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
canfilterconfig.FilterIdHigh = 0x103<<5;
canfilterconfig.FilterIdLow = 0;
canfilterconfig.FilterMaskIdHigh = 0x103<<5;
canfilterconfig.FilterMaskIdLow = 0x0000;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 20;

HAL_CAN_ConfigFilter(&hcan1, &canfilterconfig);

Configuration for the L4A6ZG is: 

/* USER CODE BEGIN CAN1_Init 2 */
CAN_FilterTypeDef canfilterconfig;

canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 10;
canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO1;
canfilterconfig.FilterIdHigh = 0x446<<5;
canfilterconfig.FilterIdLow = 0;
canfilterconfig.FilterMaskIdHigh = 0x446<<5;
canfilterconfig.FilterMaskIdLow = 0x0000;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 0; //doesn't matter in single can controllers

HAL_CAN_ConfigFilter(&hcan1, &canfilterconfig);
/* USER CODE END CAN1_Init 2 */

 

Attached I have the CAN settings for both Microcontrollers and also the clock Setup for both of them, I also have the main.c file for the master, the slave is similar and only difference is the configuration and Slave does not have a EXTI function for the user button. The two microcontrollers are connected to a single PC and I am using a TJA1050 CANBUS Controller Module Transceiver, I also have a 120 ohm resistor on the end of both buses.I have the CAN_RX and CAN_TX Pin of the Microcontrollers connected to the TX and RX pins of the Transceiver. CANL is connected to CANL, CANH is connected to CANH for the transceiver. The RX pin on both microcontrollers are also pulled high.  Let me know if there's any more information I can provide

2 REPLIES 2

This requires consistent execution, and uniformity of settings. Loop-back tends to work because the receiver / transmitter are the SAME,and configured with the SAME settings, implicitly.  Would probably be easier to use two of the same boards. 

Not sure why you've configured one at 16 MHz, with a CAN bit rate of 1 Mbit. Previously you were using 250 Kbit

The Filter mask for an 11-bit messages is surely 0x7FF << 5

You've opened three threads on materially the same topic.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Could you expand on what you mean by the filter mask should surely be 0x7FF << 5? Currently I'm trying to change the configuration to 80MHZ and using the MCO as a clock source but I can't use 80MHZ apparently with HSE so im stuck on that front.