tanner87661 / IoTT-Video10

Support Documents for IoTT Video #10
1 stars 0 forks source link

Suggestion for sensing LocoNet Busy State #1

Open kiwi64ajs opened 5 years ago

kiwi64ajs commented 5 years ago

Hi Hans, Looking at the ESP32 Technical Reference Manual the UART_STATUS_REG (0x1C) has a bit field (bits 8..11) called UART_ST_URX_OUT which has the current state of the Rx part of the UART, which I believe is exactly what we need to know what is happening on the LocoNet. Here is the description of the states from the data sheet:

UART_ST_URX_OUT This register stores the value of the receiver’s finite state machine. 0: RX_IDLE; 1: RX_STRT; 2: RX_DAT0; 3: RX_DAT1; 4: RX_DAT2; 5: RX_DAT3; 6: RX_DAT4; 7: RX_DAT5; 8: RX_DAT6; 9: RX_DAT7; 10: RX_PRTY; 11: RX_STP1; 12:RX_STP2; 13: RX_DL1. (RO)

So if we were to check the state of the UART RX State = RX_IDLE just before doing a TX then we can be pretty sure the LocoNet is idle. I've not been able to confirm the code yet but it might be as simple as

      if( UART[uartNr]->status.st_urx_out == 0)

HTH

Regards Alex Shepherd

atanisoft commented 5 years ago

Alex, I discussed this with @me-no-dev as well, this may be a bit more complicated since we may also need to check UART[uartNr]->int_st.rxfifo_tout (rx timeout).