Hardware Arduino Uno, ESP32 (DOIT Dev V1), Dorji drf1268ds (2 of)
Knowledge level - advanced
This post does not focus on a problem to be solved, it provides information I've learned that may be useful to others.
I have an application which uses half duplex serial comms between an Arduino Uno and an ESP32. The comms is set up in a Master-Slave format, where the master sends a command/value pair of bytes to the slave and the slave processes the value according to the command, then the slave responds with a type/value pair, whereon the master processes the value according to the type.
The serial comms is over LORA using DRF1268DS, which does not expose an SPI interface, but exposes UART Serial. Managing contention has been challenging and I've experimented with several approaches, some partially successful and some not at all.
Recently I scoped the serial data and AU activity during test send and receive comms.
In receive mode (times are approximated and vary):
AU goes low about 2ms before the received data from the radio link is sent to the host MCU.
It remains low until the data is completely sent to the MCU receive buffer.
This is a documented feature.
In Send mode:
The data from the host is sent to the DRF1268DS while the AU pin is high.
The AU pin goes low about 2ms after the send is complete.
The AU pin remains low until the data is sent to the radio link, then returns high.
I've not found this documented anywhere, but it enables the contention issue to be resolved.
I use the following, to ensure transmission in send mode is complete before doing any further radio activity:
void serialSend(int command) {
while (au == LOW) {} // Wait for radio to be idle
softSerial.write(command); // write the byte to the buffer
while (au == HIGH) {} // Wait for transmit to start
while (au == LOW) {} // Wait for transmit to end
}