CAN ...read the status or error-register

ThomasK
Posts: 25
Joined: Wed Mar 20, 2019 2:33 am

CAN ...read the status or error-register

Postby ThomasK » Thu Jan 16, 2020 6:15 pm

Hello
I use the Arduino-library for the ESP32-CAN controller, it works well for sending and receiving messages.
But how can I get the information whether a CAN-transmission was sent correctly?
Example: A CAN-message is not transmitted because the bus is not connected, or no other station is connected to the bus. The program should recognize the CAN-error and therefore should not stop.
Thanx for your help.

ThomasK
Posts: 25
Joined: Wed Mar 20, 2019 2:33 am

Re: CAN ...read the status or error-register

Postby ThomasK » Wed Jan 22, 2020 12:56 pm

Is there really no way to monitor the CAN status? :cry:

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: CAN ...read the status or error-register

Postby ESP_Dazz » Wed Jan 22, 2020 5:54 pm

ThomasK wrote: But how can I get the information whether a CAN-transmission was sent correctly?
Check the Transmission Complete Status (TCS) bit of the status register. Once the TX buffer is freed (meaning that the current transmission is not being retried), the TCS bit should be set to 1 if the transmission was successful, and 0 if the transmission was unsuccessful.
ThomasK wrote: Example: A CAN-message is not transmitted because the bus is not connected, or no other station is connected to the bus. The program should recognize the CAN-error and therefore should not stop.
It should already do that. Unless you have the ESP32 CAN peripheral configured into self-test mode, it should keep transmitting indefinitely if "the bus is not connected or no other station is connected to the bus".

The CAN 2.0B protocol is designed in a way where the unconnected transmitter will be able to re-transmit indefinitely without going into the BUS OFF state (refer to the rules specified in the Fault Confinement section of the CAN 2.0B protocol specification).

ThomasK
Posts: 25
Joined: Wed Mar 20, 2019 2:33 am

Re: CAN ...read the status or error-register

Postby ThomasK » Wed Jan 22, 2020 9:56 pm

Thank you. But sorry, I must have expressed myself awkwardly. In my good old world of microcontrollers in C- programming, I would read out the register directly and react, no problem. I need your help as I must read out and use this information from this C++ library. I'm not a software freak... :roll:
The problem is specifically the following:
If I send a CAN message and there is no CAN bus connected, the program only runs until I send a CAN message the second time. Then it waits... until the CAN is connected and then runs normally. But I have to react to this "not connected CAN bus". I need a status information before I send a message next time, otherwise my program-loop will waits for ever. :cry:
So is it possible to read out the status in this CAN-library for Arduino? If so, please give me 3 program lines as an example.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: CAN ...read the status or error-register

Postby ESP_Dazz » Thu Jan 23, 2020 6:54 am

Is this library the one you are using? If so...
ThomasK wrote: If I send a CAN message and there is no CAN bus connected, the program only runs until I send a CAN message the second time.
The reason it gets stuck is because CAN_write_frame() internally takes a semaphore with a timeout of portMAX_DELAY. This effectively blocks your thread (i.e., your loop()) until the transmission is complete (the ISR gives the semaphore to indicate transmission has completed/errors out).

However, as mentioned my previous post, the CAN peripheral is designed to retransmit indefinitely when there is no CAN bus connected, thus the transmission never completes, the ISR doesn't run, and CAN_write_frame() waits for the semaphore indefinitely.

Therefore, I don't think you read out the status using this CAN Arduino library, unless you are willing to modify/add a few functions to it yourself.

ThomasK
Posts: 25
Joined: Wed Mar 20, 2019 2:33 am

Re: CAN ...read the status or error-register

Postby ThomasK » Thu Jan 23, 2020 9:15 pm

thank you, that's exactly right. Thanks for the information about the program lines.
My knowledge of C++ is unfortunately limited in order to insert suitable changes there. But I'm going to experiment a little... :?

Who is online

Users browsing this forum: Baidu [Spider] and 83 guests