Simple RMT pulse receiver

bkgoodman
Posts: 45
Joined: Fri Feb 17, 2017 12:41 pm

Simple RMT pulse receiver

Postby bkgoodman » Thu Jun 08, 2023 11:26 pm

I need to write RMT code that doesn't use the RMT driver, and instead bit-bashes and manually sets up GPIOs and interrupts to work. (It has to do with EVENTUALLY needing this to work in conjunction with another piece of code that transmits - and the driver's difficulty to do both at the same time).

I know from a hardware perspective things are good - because when I use a more standard piece of code to do this (RMT driver, same hardware, GPIO) things are fine. But this simple little test _should_ at least receive a pulse and trigger an interrupts - but gives me nothing at all.

Any idea on what I am missing?

#include "driver/rmt.h"
#include "soc/rmt_reg.h"
#include "esp_intr_alloc.h"

#define RMT_CHANNEL RMT_CHANNEL_2
#define RMT_GPIO_NUM GPIO_NUM_18
#define RMT_CLK_DIV 80
#define RMT_RX_FILTER_THRES 100

volatile uint16_t test=0;
void rmt_isr(void* arg) {
test++;
}

intr_handle_t rmt_intr_handle;
void app_main() {
// Configure GPIO pin for input mode
gpio_set_direction(RMT_GPIO_NUM, GPIO_MODE_INPUT);

// Configure RMT module
RMT.conf_ch[RMT_CHANNEL].conf0.div_cnt = 80; // Set clock divider for desired tick duration
RMT.conf_ch[RMT_CHANNEL].conf0.mem_size = 1;
RMT.conf_ch[RMT_CHANNEL].conf0.carrier_en = 0;
RMT.conf_ch[RMT_CHANNEL].conf0.carrier_out_lv = 1;
RMT.conf_ch[RMT_CHANNEL].conf0.mem_pd = 0;
RMT.conf_ch[RMT_CHANNEL].conf0.idle_thres = 100;

// Enable RMT channel
RMT.conf_ch[RMT_CHANNEL].conf1.rx_filter_en = 1;
RMT.conf_ch[RMT_CHANNEL].conf1.rx_filter_thres = 100;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_wr_rst = 1;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_owner = RMT_MEM_OWNER_RX;
RMT.conf_ch[RMT_CHANNEL].conf1.rx_en = 1;

// Enable RMT receiver
RMT.int_ena.val |= 0xffff;

// Enable RMT interrupts
esp_intr_alloc(ETS_RMT_INTR_SOURCE, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1,&rmt_isr,0L,&rmt_intr_handle);

// Loop to continuously read pulse widths
while (1) {
ESP_LOGI(TAG,"%u",test);
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Simple RMT pulse receiver

Postby ESP_Sprite » Fri Jun 09, 2023 1:02 am

Make sure to also de-clockgate and un-reset the RMT peripheral.

bkgoodman
Posts: 45
Joined: Fri Feb 17, 2017 12:41 pm

Re: Simple RMT pulse receiver

Postby bkgoodman » Fri Jun 09, 2023 1:19 pm

> Make sure to also de-clockgate and un-reset the RMT peripheral.

@ESP_sprite how do I do that? I added the following - still no interrupts:
#include "driver/rmt.h"
#include "soc/rmt_reg.h"
#include "soc/rmt_struct.h"
#include "esp_intr_alloc.h"

#define RMT_CHANNEL RMT_CHANNEL_2
#define RMT_GPIO_NUM GPIO_NUM_18
#define RMT_CLK_DIV 80
#define RMT_RX_FILTER_THRES 100

volatile uint16_t test=0;
void rmt_isr(void* arg) {
test++;
}

intr_handle_t rmt_intr_handle;
void app_main() {

rmt_driver_install(RMT_CHANNEL, 0, 0);
RMT.conf_ch[RMT_CHANNEL].conf1.rx_en = 0;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_rd_rst = 1;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_wr_rst = 1;
RMT.conf_ch[RMT_CHANNEL].conf1.tx_start = 0;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_rd_rst = 0;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_wr_rst = 0;

// Configure GPIO pin for input mode
gpio_set_direction(RMT_GPIO_NUM, GPIO_MODE_INPUT);

// Configure RMT module
RMT.conf_ch[RMT_CHANNEL].conf0.div_cnt = 80; // Set clock divider for desired tick duration
RMT.conf_ch[RMT_CHANNEL].conf0.mem_size = 1;
RMT.conf_ch[RMT_CHANNEL].conf0.carrier_en = 0;
RMT.conf_ch[RMT_CHANNEL].conf0.carrier_out_lv = 1;
RMT.conf_ch[RMT_CHANNEL].conf0.mem_pd = 0;
RMT.conf_ch[RMT_CHANNEL].conf0.idle_thres = 100;

// Enable RMT channel
RMT.conf_ch[RMT_CHANNEL].conf1.rx_filter_en = 1;
RMT.conf_ch[RMT_CHANNEL].conf1.rx_filter_thres = 100;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_wr_rst = 1;
RMT.conf_ch[RMT_CHANNEL].conf1.mem_owner = RMT_MEM_OWNER_RX;
RMT.conf_ch[RMT_CHANNEL].conf1.rx_en = 1;

// Enable RMT receiver
RMT.int_ena.val |= 0xffff;

// Enable RMT interrupts
esp_intr_alloc(ETS_RMT_INTR_SOURCE, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1,&rmt_isr,0L,&rmt_intr_handle);

// Loop to continuously read pulse widths
while (1) {
ESP_LOGI(TAG,"%u",test);
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}

MicroController
Posts: 1709
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Simple RMT pulse receiver

Postby MicroController » Fri Jun 09, 2023 4:13 pm

Last edited by MicroController on Sun Jun 11, 2023 1:59 pm, edited 1 time in total.

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Simple RMT pulse receiver

Postby ESP_Sprite » Sun Jun 11, 2023 3:07 am

MicroController is correct. Also, I don't see you routing the RMT channel to the GPIO pin you indicated anywhere.

Who is online

Users browsing this forum: Google [Bot] and 90 guests