Direct access to UART1 TX FIFO
Posted: Sun May 24, 2020 7:09 pm
Hey,
on the ESP8266 (Arduino Framework) it was pretty easy to access the UART registers. All relevant registers were exposed in the esp8266_peri.h I used UART1 to generate a precise timed pulse using:
On the ESP32 (Arduino Framework) it is pretty hard to figure out how to access the relevant registers... At least for me. The HardwareSerial.cpp uses a lot of internal APIs.
So far I found out how to set the pin matrix to route the UART1 TX to GPIO2 and set the clock divider:
But I was not able to find the FIFO to write to... Using Serial1.write() blocks the CPU.
Can someone help me out here? Thx!
on the ESP8266 (Arduino Framework) it was pretty easy to access the UART registers. All relevant registers were exposed in the esp8266_peri.h I used UART1 to generate a precise timed pulse using:
- // Initial Setup
- pinMode(2, SPECIAL); // Set GPIO2 as UART1 TX
- U1S |= 0x01 << USTXC; // Set UART1 TX FIFO length
- U1D = 10*duration; // Set pulse duration using divider
- // To generate one pulse whenever I want without blocking CPU
- U1F = 0x80; // Pulse
On the ESP32 (Arduino Framework) it is pretty hard to figure out how to access the relevant registers... At least for me. The HardwareSerial.cpp uses a lot of internal APIs.
So far I found out how to set the pin matrix to route the UART1 TX to GPIO2 and set the clock divider:
- // Initial Setup
- Serial1.begin(9600); // Needed for Serial1.write to work (want to get rid of)
- pinMode(2, OUTPUT);
- pinMatrixOutAttach(2, U1TXD_OUT_IDX, false, false);
- WRITE_PERI_REG(UART_CLKDIV_REG(1), 10*duration); // requires <soc/uart_reg.h>
- // To generate one pulse
- Serial1.write(0x80);
But I was not able to find the FIFO to write to... Using Serial1.write() blocks the CPU.
Can someone help me out here? Thx!