cancel
Showing results for 
Search instead for 
Did you mean: 

CAN communication only working when the reciever is reset?

tim_licen123
Associate II

The goal of my project is to turn on an LED on the recieving side through CAN. Both my reciever and transmitter have the transciever circuit. Both are Nucleo boards, TX: F303RE, RX: F446RE.

The data i am sending through is 16-bit, but as long as my reciever is not in reset copnstantly (as in me holding the reset button when the program is running), the transmitted and recieved data is not correct, its far to short. The data is the same on TX and RX, but wrong. But when i hold reset on the reciever the data that comes through looks right. 

I cant figure out what the problem is, i have measured the connections on the transcievers a million times, measured the RX, TX pin, CAN_H and L and always come back to the same issue. 

I am programming the boards in Cube_IDE. The pictures below are of the boards and the signals i recieve. Please help. I dont see how this could be a hardware problem but maybe I missed something, i am still a begginer. 

 

The reciever board is part of another project, but i used it, since it has the transciever circuit and that way there was no soldering needed. And the reciver board worked on the previous project of my friend.

The boards

tim_licen123_0-1755069761730.jpeg

The signal when the RX is not reset:

tim_licen123_1-1755069806967.jpeg

The signal when it is reset:

tim_licen123_2-1755069830704.jpeg

Any help is appreciated ! The codes i put as txt files. 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

1- However I'm wondering how F446 is reading CAN data?! You have this filter configuration for CAN1:

  cancanfilter.FilterBank = 10;
  cancanfilter.SlaveStartFilterBank = 0;

SlaveStartFilterBank = 0 means all the filters are allocated to CAN2 which is not used!

Refer to this article: STM32 in dual CAN configuration: bxCAN Filter bank explanation and relation with CAN2 Start Bank parameter : "If SlaveStartFilterBank = 0: all filters are allocated to CAN2. In that case CAN1 is not usable, but CAN1 APB clock should be enabled since it is a master as mentioned previously."

In the case of CAN1 instance, SlaveStartFilterBank needs to be > FilterBank

2- For F3:

You have an issue with the filter setting especially the FIFO number. You seems using FIFO1 but you are setting FIFO0 for the filter:

cancanfilter.FilterFIFOAssignment = CAN_FILTER_FIFO0;

Change it as the following:

cancanfilter.FilterFIFOAssignment = CAN_FILTER_FIFO1;

 

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

18 REPLIES 18
STuser2
Senior

As a first try if you have a CAN tool use it and verify if the messages that are transmitted are received properly on the tool and then you can go in steps of transmitting messages from the tool etc.

I dont have a CAN tool. I have an osciloscope. I have verified that i recieve the same message that i transmitt. I have also noticed another problem, my TX stops sending data after a period of time and needs a reset, then it starts sending data (wrong data again). Hope this maybe is a useful clue. Thanks for replying !

 

The truncated message is probably because there is an error on the BUS.
1) Do You have the 2 x 120R termination resistors on the Bus?
2) If Yes then You probably have different baud-rates on the two nods (or CAN-H and CAN-L inverted).
P.S. To have a stable CAN-Bus you should use an external crystal or oscillator, the HSI oscillator is not suitable because of the frequency tolerance.

Thanks for replying. I have two terminators. The baud rates are also the same (100 kbits/s). Here are the pictures of the CAN_H and L. 

The signal on CAN-H is not ok, You can see the error frame from the RX node, but not the data from the TX node.

Check the connetion between the Transceiver and the cable. If this is OK the You have a broken Transceiver on the TX module.

Between the transciever and CAN_H, L cable? 

See if you have continuity between the CAN_H pin of the TX Board Driver and the CAN_H pin on the RX Board Driver (You did not mention your Driver, but if it is a 8 pin type, the CAN_H ins normally Pin 7).

MHoll2_0-1755092974818.png

 

tim_licen123
Associate II

Now i tottaly redid the code and the issue is, I never recieve data/enter the interrupt?. On the reciever, the data on the TX pin is the same as on the transmitter, but on the RX pin, there is just one single pulse from logic high to low, what could be the issue here. It seems as if I transmit data to the TX pin instead of the RX pin? 

Please help, bellow is the main.c, for my reciever. The TX part now works perfectly, with no need to reset anything, now the problem is not recieving the data. 

 

 

Check the error counters all CAN peripherals have. There are two of them one for Tx (Transmit Error Counter) and an Receive Error Counter for Rx. The naming might be a bit different in the STM peripheral, but the CAN standard requires those.

Both a 8-bit counters, which influence failure behavior. After a certain number of Tx errors (default 128), a node goes into "error passive" mode, not sending anymore. Upon the second limit (default 255), the node goes into "bus off" mode, separating itself from the bus for a certain period.
This behavior is defined in the CAN standard, you can read it up.

Check these counters in your firmware after each Tx attempt, I'm sure they are counting up.
If this happens, either your cabling is incorrect, or the bus timing settings.

You can try a direct connection of CAN-Tx and CAN-Rx between both nodes (and GND, of course).
That would prove the timing is correct, and the problem is the transceiver hardware or cabling.