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.
CAN ...read the status or error-register
Re: CAN ...read the status or error-register
Is there really no way to monitor the CAN status?
Re: CAN ...read the status or error-register
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: But how can I get the information whether a CAN-transmission was sent correctly?
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".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.
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).
Re: CAN ...read the status or error-register
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...
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.
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.
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.
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.
Re: CAN ...read the status or error-register
Is this library the one you are using? If so...
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.
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).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.
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.
Re: CAN ...read the status or error-register
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...
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], Bing [Bot], Masoud123456 and 63 guests