Page 1 of 1

Help with RMT RX

Posted: Fri Sep 06, 2019 3:27 am
by Neuromodulator
Hello!

I've been trying to use the RMT library but I still can't get it to work as I want. I want to use the whole 512 memory blocks to make some measurements, but I still can't figure how to do that. Just to test the RMT code i connected through a cable pin 4 to pin 21. An ouput signal is generated on pin 4 at different spacing intervals and pin 21 is used with the RMT to measure the high and low state durations of pin 4.

My code is as follows:

Code: Select all

#include "arduino.h"
#include "driver/rmt.h"

rmt_config_t rmt_rx;

void setup()
{
    rmt_rx.rmt_mode = RMT_MODE_RX;
    rmt_rx.channel = RMT_CHANNEL_0;
    rmt_rx.clk_div = 1;
    rmt_rx.gpio_num = GPIO_NUM_21;
    rmt_rx.mem_block_num = 8;
    rmt_rx.rx_config.filter_en = false;
    rmt_rx.rx_config.idle_threshold = 0xffff;;

    rmt_config(&rmt_rx);
    rmt_rx_start(rmt_rx.channel, true);

    pinMode(4, OUTPUT);

    Serial.begin(115200);
}

int count = 0;
unsigned long t = 0;

void loop()
{
    usleep(1 * count);
    digitalWrite(4, 0);
    usleep(2 * count);
    digitalWrite(4, 1);

    if (millis() - t > 500)
    {
        t = millis();
        count = (count + 1) & 0x1F;

        rmt_memory_rw_rst(rmt_rx.channel);

        rmt_item32_t* item = (rmt_item32_t*)RMT_CHANNEL_MEM(rmt_rx.channel);

        printf("H: %d, ",  item->level0 * item->duration0 +  item->level1 * item->duration1);
        printf("L: %d\n", !item->level0 * item->duration0 + !item->level1 * item->duration1);
   }
}
For some reason this code does not work at all, unless "rmt_memory_rw_rst()" is moved out of the loop. What am I doing wrong?

Thanks!

Re: Help with RMT RX

Posted: Fri Sep 06, 2019 6:40 am
by Neuromodulator
Don't worry, fixed the issue. I was getting to idle and didn't restart the capture.

Re: Help with RMT RX

Posted: Sun Dec 06, 2020 8:49 am
by lippih
Would you kindly explain the exact solution to your problem? If RMT goes to idle, it doesn't restart automatically capturing, when new pulses comming in?

Thanks

lippih