I'm connecting an ESP32 to an instrument via a 5V non standard synchronous serial protocol. Like SPI but not quite SPI.
When I decode the serial data on my oscilloscope, every message is perfect, all the data is good. There are no bad messages.
I've written 3 different ESP32 routines to decode these messages. 2 are bit bang ISRs and one uses the ESP32 SPI port. In every one of these routines I'm getting bad messages coming back from the instrument. Sometimes a bit is missing, sometimes a byte will be missing one bit, etc.
With the bit bang routines I've tried sampling the data bit on the rising edge, falling edge, etc. all to no avail. I've tried pull up and pull down configurations with the same outcome.
I'm pretty sure it isn't a software issue. I'm pretty sure I'm dealing with a hardware issue. The signal is pretty clean. I can drop the decoding threshold voltage on my oscilloscope below 0.5V and not get any message errors.
The digital output from the instrument is 5V. I'm connecting it directly to an ESP32 GPIO pin with no level shifting. Could this be causing the issue ? Are GPIO pins prone to pick up noise internally ? What else might cause a GPIO pin or the SPI port to incorrectly read a bit ?
Thanks
Bad data when reading GPIO levels and UART data in ISR ? Pin noise, 5V input, ?
-
MicroController
- Posts: 2661
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Bad data when reading GPIO levels and UART data in ISR ? Pin noise, 5V input, ?
Don't do that.The digital output from the instrument is 5V. I'm connecting it directly to an ESP32 GPIO pin with no level shifting.
Depending on the frequency of the signal, handling one interrupt per bit may or may not be reliable. Up to a few kHz it should work ok.
Can you share some specs of the protocol you want to process?
Re: Bad data when reading GPIO levels and UART data in ISR ? Pin noise, 5V input, ?
The bits are roughly 10 us wide (between edges) The ISR takes 4 us to run. There is a 2 us delay from the time the edge changes until the ISR is running. So typically the ISR is done at 6 us.
I have checks in the ISR for it being executed a second time while the first instance is still running. I also have a check for receiving 2 consecutive high or low edges.
I have the ISR priority set to 3. The code uses FreeRTOS and runs the ESP HTTP server.
Like I said, the signal looks perfect on the scope and yet we get missing edges and bad data. We also get bad data when reading it with the SPI hardware.
Any and all thoughts and advice will be greatly appreciated.
I have checks in the ISR for it being executed a second time while the first instance is still running. I also have a check for receiving 2 consecutive high or low edges.
I have the ISR priority set to 3. The code uses FreeRTOS and runs the ESP HTTP server.
Like I said, the signal looks perfect on the scope and yet we get missing edges and bad data. We also get bad data when reading it with the SPI hardware.
Any and all thoughts and advice will be greatly appreciated.
-
MicroController
- Posts: 2661
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Bad data when reading GPIO levels and UART data in ISR ? Pin noise, 5V input, ?
This leaves a window of 4-8us, meaning that you'll depend on interrupts never being disabled for longer than those 4-8us to not risk losing bits. I would not bet this works reliably.The bits are roughly 10 us wide ... There is a 2 us delay ... typically the ISR is done at 6 us.
I wonder why the SPI peripheral would be losing bits. Probably a software/configuration issue.
But first of all, stop feeding 5V into a 3.3V IO pin; at the very least put a resistor in series to limit the short-circuit current between the 5V output and the 3.3V rail of the ESP.
Who is online
Users browsing this forum: No registered users and 4 guests