jeelabs / esp-link

esp8266 wifi-serial bridge, outbound TCP, and arduino/AVR/LPC/NXP programmer
Other
2.82k stars 720 forks source link

Support for inverted TTL serial #472

Open mr-sneezy opened 4 years ago

mr-sneezy commented 4 years ago

I apologize if I have missed this someplace in the menus or notes and it's already a feature...

I found a device that uses true RS232 signalling at TTL levels that I want to interface to ESP-link, and to do that I need to invert the signaling back to TTL serial with an bi-directional inverter.

If the ESP8266 UART hardware supports inverted signalling, can that be a new feature to avoid a piece of hardware in between ?

uzi18 commented 4 years ago

any link to informations about such support in esp?

jcw commented 4 years ago

It looks like this is technically possible, see p.80 in the ESP8266 reference manual (PDF):

Each input and output UART signals can reverse configuration internal.
#define UART_DTR_INV (BIT(24))
#define UART_RTS_INV (BIT(23))
#define UART_TXD_INV (BIT(22))
#define UART_DSR_INV (BIT(21))
#define UART_CTS_INV (BIT(20))
#define UART_RXD_INV (BIT(19))
Set the corresponding register,you can reverse the corresponding signal line input / output.
Interface: void UART_SetLineInverse (uint8 uart_no, UART_LineLevelInverse inverse_mask);

There will be some work involved in creating a corresponding user setttings web interface.

mr-sneezy commented 4 years ago

Thanks, had a read of P.80. I'm not sure if all line bits should get set to inverted or not, but since most simple serial comms uses just TXD & RXD (as in the case I just implemented also) the GUI might just set those only with one check box, and leave the flow control lines alone. Open to an experts thought there...

The setup I recently made with the RS232 chip attached was a temporary lash up. I have a new D1 Mini board now to fit into the control panel, I could test a beta with TX & RX inversion when doing that if that helps any dev coders who may attempt it.

uzi18 commented 4 years ago

@jcw nice catch :) @mr-sneezy so it is possible :+1: now someone need to find time to add it, what is your esp flash size?

mr-sneezy commented 4 years ago

Yes true, although it should be a useful feature long term. The flash size is 4Mb (25Q32 chip).

uzi18 commented 4 years ago

W25Q32: 32M-bit / 4M-byte

uzi18 commented 4 years ago

@mr-sneezy my time is limited, but will try to prepare test build for you

mr-sneezy commented 4 years ago

Nice, no rush.

tsang commented 4 years ago

Hi, I would be interested in this change, I was wondering if there was a test build available? I have a 1mbyte flash board.

uzi18 commented 4 years ago

https://github.com/esp8266/Arduino/issues/4896

mr-sneezy commented 4 years ago

esp8266/Arduino#4896

Hi, followed that thread, but not sure if it all means the feature is in or out at this point ? If it's in I can setup a new ESP8266 board and test it.

uzi18 commented 4 years ago

added reference here as it looks like API function UART_SetLineInverse does not work correctly, stay tuned :)

tsang commented 4 years ago

FWIW, the device I want to interface to with RS232 is +-6V so close enough to TTL so I assume if inverted I can skip using a MAX3232.

On Apr 30, 2020, at 7:09 PM, Bartłomiej Zimoń notifications@github.com wrote:

 added reference here as it looks like API function UART_SetLineInverse does not work correctly, stay tuned :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

mr-sneezy commented 4 years ago

No, it needs to be 3.3V logic levels. Above that could blow the I/O in the ESP. In your case it's ideal to use a MAX232 in between to get the logic inversion and level shifting to the ESP. I use these when that's necessary. https://www.banggood.com/Mini-RS232-to-TTL-Converter-Module-Board-Adapter-MAX3232-120kbps-3-5V-Serial-Port-p-1487275.html

bluearcus commented 4 years ago

I would really like this functionality to be added. However, for my use case if introduced and added to the UI, it should really allow selection of individual pins to invert.

mr-sneezy commented 3 years ago

I would really like this functionality to be added. However, for my use case if introduced and added to the UI, it should really allow selection of individual pins to invert.

It still seems ambiguous by following the other git issues threads as to if it's even possible. I have to install another module soon and will need the external inversions again sadly.

de-wolff commented 3 years ago

I have a working implementation of this feature now. I need some time to make my quick and dirty solution sme better, then I will post a pull request

mr-sneezy commented 3 years ago

I have a working implementation of this feature now. I need some time to make my quick and dirty solution sme better, then I will post a pull request

Thanks de-wolff this feature will be a great one. Also, I can test this as soon as it's available on the hardware I need to use.

de-wolff commented 3 years ago

Also, I can test this as soon as it's available on the hardware I need to use.

If you want to test it, you can already download the code at https://github.com/de-wolff/esp-link.git, and checkout branch add_invert_uart_lines

And I also notes it is almost the first anniversary of this question ;)

mr-sneezy commented 3 years ago

Yes it is. I had a quick look through the branch above. Is there a binary for Node-MCU in there ? If I can flash a binary to a fresh board it will make it quick to test in between other tasks today.

de-wolff commented 3 years ago

Yes it is. I had a quick look through the branch above. Is there a binary for Node-MCU in there ? If I can flash a binary to a fresh board it will make it quick to test in between other tasks today.

I do not like add binaries to a source control system, but if you send me an email, I will reply with the binaries

Jaap

uzi18 commented 3 years ago

You can compress to zip and attach here

de-wolff commented 3 years ago

esp-link-v3.2.47.alpha.17-ged634e8-dirty.gz Is a tgz file, but this file type is not supported by github ;)

mr-sneezy commented 3 years ago

I have now done some testing with an attempt to use the inverted serial. The GUI seems very easy to follow, and the settings seemed to change as expected as far as the GUI went.

Unfortunately I never was able to receive any data when the Invert option was used. This may NOT be the code though, it might be that my HW I'm connecting to does not work at TTL levels like I thought. I was seeing 3.3V levels on one of the two data pins so I made the assumption. Now I'm unsure, as the HW works fine with a standard USB-RS232 cable at higher voltage signalling (8V IIRC). I have added a RS232-TTL converter in between like I did last time I setup the previous example of the hardware, and the ESPlink works fine in non-inverted mode again on this one. So it's inconclusive at this point. My HW is about to get installed at another house so I'll have to setup a breadboard and another Wemos D1 mini to test with something else that I know if TTL inverted serial. Maybe a 'hello world' test with an Arduino etc.

emmrichd commented 2 years ago

Hello, Thanks a lot for your efforts. I am trying to use your binaries. However, whenever I tick "pin invert" and press change afterwards, the tick is being removed again. Is this a bug?

However, I can confirm that is seems to work for me.