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 Serial1 crash... #47

Open
janokylaszlo opened this issue May 23, 2023 · 2 comments
Open

ESP32 Serial1 crash... #47

janokylaszlo opened this issue May 23, 2023 · 2 comments

Comments

@janokylaszlo
Copy link

Dear Iwanders,

I would like to use OBD9141 on an ESP32 SIM800C board, where the 16/17 pins are not available. Unfortunately the Serial1 RX_PIN 4 and TX_PIN 2 configurations crash :( What am I doing wrong?

Thanks a lot!
LJ

The code:

#define RX_PIN 4 // connect to transceiver Rx for ESP32
#define TX_PIN 2 // connect to transceiver Tx

bool init_success;
OBD9141 obd;

void setup(){
    Serial.begin(115200);
    obd.begin(Serial1, RX_PIN, TX_PIN);

Serial output:
rst:0x8 (TG1WDT_SYS_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13836
load:0x40080400,len:3608
entry 0x400805f0
ets Jul 29 2019 12:21:4

@janokylaszlo
Copy link
Author

I found the reason:
the serial initialization is done in line 29. of OBD9141.cpp, but here rx_pin and tx_pin are not included in the this->serial->begin() call, so the default pins are assigned. This code:
this->serial->begin(OBD9141_KLINE_BAUD, this->tx_pin, this->rx_pin);
already sets the pins assigned to the serial.

@iwanders
Copy link
Owner

Yeah, so the object only needs tx and rx to be able to set the pullups. The problem is that the arduino ecosystem only specifies the baudrate as argument for begin(), the pin numbers are usually implicit and based on whether Serial, Serial1 or SerialN is used.

This is also why the esp example doesn't set the pins either. The esp api deviates a bit here in supporting it I think...

Even setting them once with a begin() call outside of the set_port function wouldn't work. they get reset to defaults if you don't pass them when calling begin() after an end() call.

I guess we could wrap it in a preprocessor directive, I'd be happy to accept a PR that updates this and only for ESP32s performs this->serial->begin(OBD9141_KLINE_BAUD, this->tx_pin, this->rx_pin); instead of the begin() call without arguments.

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