esp32_can icon indicating copy to clipboard operation
esp32_can copied to clipboard

Auto baud-rate

Open Deivik12 opened this issue 5 years ago • 9 comments

Hi, thanks for sharing and maintaining this source code it really does the job. Currently Im using built in canbus with vd230 transceiver. I was wondering is it possible some how in easy way to add auto baud rate?

Deivik12 avatar Mar 04 '20 03:03 Deivik12

Yes. The easiest approach to doing autobaud is this:

  1. Set the CAN hardware to listen only mode.
  2. Set a speed you think "might" be it
  3. Wait several hundreds of milliseconds
  4. See if any traffic came in
  5. If it did then that CAN speed must be correct. Turn listen only mode off. You're done.
  6. If nothing came in then go back to step 1 and try a different speed.

This, of course, requires that two other nodes are on the CAN bus and talking. Naturally you can't do autobaud without some traffic to analyze.

collin80 avatar Mar 04 '20 17:03 collin80

Thanks for information. Everything is clear, just not the step 1 one. Ive read how I can setup listen-only mode with esp-idf, but Im not sure how it should be done in arduino with your stack. Can you let me know how to set it to listen-only mode?

Deivik12 avatar Mar 05 '20 01:03 Deivik12

Depending on whether you're using the built-in CAN or one of the add-ons (MCP2515, MCP2517FD):

CAN0.setListenOnlyMode(true); or CAN1.setListenOnlyMode(true);

Then, obviously you can turn that off with setListenOnlyMode(false);

On Wed, Mar 4, 2020 at 8:42 PM Deivik12 [email protected] wrote:

Thanks for information. Everything is clear, just not the step 1 one. Ive read how I can setup listen-only mode with esp-idf, but Im not sure how it should be done in arduino with your stack. Can you let me know how to set it to listen-only mode?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/collin80/esp32_can/issues/16?email_source=notifications&email_token=AAQLWZLCJ72TYHB56RGNIETRF37R5A5CNFSM4LA2K4P2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEN3LSLA#issuecomment-594983212, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQLWZN2ARMDMOX67WZJYBLRF37R5ANCNFSM4LA2K4PQ .

collin80 avatar Mar 05 '20 01:03 collin80

Thanks, you are the best!

Deivik12 avatar Mar 05 '20 23:03 Deivik12

I have small issue, I was testing autobaud. In my application baud speed can be either 250kbps or 500kbps. Problem Im facing is that CAN0.setListenOnlyMode(true); allows any baud speed traffic thru. Simple example Im checking 500kbps baud rate can bus with 250kbps setup:

` void setup() { Serial.begin(115200); CAN0.setListenOnlyMode(true); CAN0.begin(250000); CAN0.watchFor(); }

void loop() { CAN_FRAME message; if(CAN0.read(message)) { Serial.println(message.id, HEX); } } ` it outputs can bus traffic which is running at 500kbps, even tho Ive tried to read it with CAN0.begin(250000); because of that, I cant make autobaud to work. I think it shouldnt output canbus traffic? If I remove CAN0.setListenOnlyMode(true); it not gonna output any canbus traffic until I set proper canbus speed. I was wondering should listenonlymode and begin work like that? could you show maybe small example of auto baud?

Deivik12 avatar Mar 09 '20 04:03 Deivik12

I did more testing, I found that if you are trying to do CAN0.setListenOnlyMode(true); while can bus speed is 500kbps, it will somehow automatically detect canbus speed, doesnt matter what speed you choose in CAN0.begin();

Also Ive found that CAN0.setListenOnlyMode(true); doesnt work on 250kbps canbus speed. example: CAN0.setListenOnlyMode(true); CAN0.begin(500000); It will stop canbus completely. also it will allow send canbus frames if I choose CAN0.begin(250000);.

In conclusion setListenOnlyMode(); is buggy and doesnt work for all speeds how it shoud. Is there other way for autobaud or maybe you can check this issue sometime?

Deivik12 avatar Mar 10 '20 02:03 Deivik12

Alright, I will look into this. It does sound like something is broken in the listen only mode.

collin80 avatar Mar 10 '20 03:03 collin80

Hi ! I got the same problem when i did testing with Auto Baud. i did call Can0.beginAutoSpeed() and Can1.beginAutoSpeed(); but it did not work. And i found that the esp32_can_builtin.cpp ! Nothing inside this uint32_t ESP32CAN::beginAutoSpeed() {

} Others work perfectly ! You did a great Work ! Sir @collin80 ! Thanks so much for this libary !

kietDubai avatar Jun 28 '20 13:06 kietDubai

beginAutoSpeed is certainly implemented in the both the built-in driver and the MCP2517FD driver as it sits right now. Limited testing has been done, I should test them more but the code is there now.

collin80 avatar May 03 '23 00:05 collin80