Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32, NMEA2000_esp32: Half speed (125kbps)? #10

Open
rhsmith1715 opened this issue Jul 14, 2022 · 5 comments
Open

ESP32, NMEA2000_esp32: Half speed (125kbps)? #10

rhsmith1715 opened this issue Jul 14, 2022 · 5 comments

Comments

@rhsmith1715
Copy link

Hi,
First let me start by saying how much I appreciate the NMEA2000 project and I have already used it successfully with a couple of Arduino MEGAs although way through to talking with a Garmin display -- This is a great project! The MEGAs worked fine on the NMEA side, but I needed more processing power on the hardware control side so I upgraded to an ESP32-Wroom-DA. This worked fine with the temperature sample as well as my application code when streamed to the serial port and an Actisense reader (brilliant instrumentation method BTW). However, it didn't work with my Garmin display and I determined that the but rate was half speed with an oscilloscope. I think I found the reason -- The chip manufacturer changed added a bit that toggles the CAN bus to half speed by default. I also think I found where this is dealt with by the NMEA2000_esp32.CPP:

//enable all interrupts
MODULE_CAN->IER.U = 0xef;  // bit 0x10 contains Baud Rate Prescaler Divider (BRP_DIV) bit

I changed this by what I thought was the correct bit, but the speed didn't change on my scope. I even set it 0x00 and 0xff and it did not change. Didn't seem to affect it either way...

I then tried to force the speed to 500KPS by changing the CAN speed in the following and I did not see it affect the output either..

tNMEA2000_esp32::tNMEA2000_esp32(gpio_num_t _TxPin, gpio_num_t _RxPin) :
tNMEA2000(), IsOpen(false),
speed(CAN_SPEED_250KBPS), TxPin(_TxPin), RxPin(_RxPin),
RxQueue(NULL), TxQueue(NULL) {
}

I think the fix is already in the files, but I'm just not seeing what is probably right before my eyes.. I'm more of a hardware guy, so I can use all the help I can get!

Please let me know if anyone can provide guidance...

Thanks!
Randy

@ttlappalainen
Copy link
Owner

ttlappalainen commented Jul 24, 2022

Could this have something to do with peripherial clock frequency, which should be 80 MHz for proper dividers?

If you changed speed(CAN_SPEED_500KBPS), didn't it change bus speed on oscilloscope? Setting effects directly to the prescaler setting.

Setting MODULE_CAN->IER.U = 0xef; enables all interrupts, but leaves bit4 to zero. So setting this to 0, disables all interrupts and it will not work for sure.

I could not find anything from technical reference.

@ttlappalainen
Copy link
Owner

Can you point some test module with ESP32-Wroom-DA

@rhsmith1715
Copy link
Author

rhsmith1715 commented Jul 26, 2022 via email

@ttlappalainen
Copy link
Owner

As stated in commenst on NMEA2000_CAN.h you can set nearly any pins by setting e.g.,:
#define ESP32_CAN_TX_PIN GPIO_NUM_16
#define ESP32_CAN_RX_PIN GPIO_NUM_17
#include <NMEA2000_CAN.h>

With this you override default pins 16/4

@rhsmith1715
Copy link
Author

Hi Timo,

I think the root cause of my issues was that I was using a wrong piece of pin assignment documentation for the ESP32-Wroom-DA... It turns out that there are several of these modules with the same chip, but different pin assignments on the PCBs. I noticed the markings on the board didn't align with the pin assignment chart when I was rebuilding my test set-up. After getting through the document issue, everything worked exactly as you stated, including the ability to re-assign the pins from the default to the ones I needed to use. Sorry for the false alarm on the baud rate issue and thanks for helping me through this!

Best Regards,

Randy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants