Page 1 of 1

RMT peripheral and reading a pin

Posted: Mon Aug 06, 2018 7:56 pm
by stoikos
This is what I am trying to achieve:

Code: Select all

do for 25 times:
        set PIN_OUT for output
        set PIN_IN for input
        send 1 microsecond pulse to PIN_OUT (HIGH for 1 microsecond, LOW for the next microsecond)
        immediately read  PIN_IN status (HIGH or LOW)
        store value

I think using RMT should do it but when I tried it didn't seem to work. Any suggestions or sample code?

Re: RMT peripheral and reading a pin

Posted: Wed Aug 08, 2018 5:21 am
by kolban
If it were me, I'd probably look at some low-level bit banging ... some function similar to the following (pseudo code)

Code: Select all

int doPulse() {
   Disable interrupts;
   write PIN_OUT HIGH;
   wait 1uS
   write PIN_OUT_LOW;
   wait 1uS
   int val = read PIN_IN;
   Enable interrupts;
   return value;
}
while it certainly isn't nearly as elegant as leveraging an underlying hardware peripheral, it does somehow feel useful.

Another alternative that we might want to examine is potentially seeing if we could leverage the SPI protocol.

It almost feels like you have an output clock that is at 2MHz. Perhaps we could use SPI CLK and MISO?

I'd also look to clarify your specification. Do we read when PIN_OUT goes low or do we read 1uS after PIN_OUT goes low?

Re: RMT peripheral and reading a pin

Posted: Fri Aug 10, 2018 12:28 am
by stoikos
Hi Neil,
The code you wrote was my initial guess. When looking for 1us delay that only thing I found was ets_delay_us() which I believe it is not recommended. I could use I think esp_timer_get_time() but I have read some recommendations about using RMT. RMT is based on interrupts so disabling them is not a good idea. I played around it but I wasn't very successful. if using ets_delay_us() is ok I assume your code would work like a charm :)

Re: RMT peripheral and reading a pin

Posted: Tue Aug 14, 2018 4:33 pm
by keckert
The RMT peripheral has an interrupt:
  • The RMT transmitter has finished transmitting the signal - rmt_set_tx_intr_en()
You could transmit your short sequence with the RMT and read your input pin with the interrupt service routine.
Sorry, I do not have example code.

Re: RMT peripheral and reading a pin

Posted: Tue Aug 14, 2018 4:49 pm
by fly135
Just for reference, I just put some code in the beginning of the 2nd stage bootloader that needed to delay. I created a loop that read the time and calculated a timeout and toggled a pin every loop and the loop was around 40usec. I modded it to just a loop count test and could achieve a pulse width of 1.4 usec. That's before anything even gets set up in the 2nd stage. So a pulse width of 1 usec with bit banging is not likely.

John A