Help in using Interrupts With RMT driver For IR receiver

Manveen
Posts: 5
Joined: Wed Jun 13, 2018 10:11 am

Help in using Interrupts With RMT driver For IR receiver

Postby Manveen » Mon Dec 24, 2018 9:11 am

HI

I am making an IR based proximity sensor.
I am using The RMT peripheral . I want to use an interrupt based system.
But i can not understand the using interrupt part of the system.
I want to use a custom ISR for when i start receiving , (or fully receive the signal.)


Here is the official guide to the topic.

https://docs.espressif.com/projects/esp ... interrupts

my few queries are as follows

1. How do i apply my custom configs if i can not use rmt_driver_install() .
2. I tried to use rmt_set_rx_intr_en() . but i was not able to clear any interrupt there. HOW DO i clear my interrupt ?
3. I tried to understand how to following quote but i was not able to understand anything .
When servicing an interrupt within an ISR, the interrupt need to explicitly cleared. To do so, set specific bits described as RMT.int_clr.val.chN_event_name and defined as a volatile struct in soc/esp32/include/soc/rmt_struct.h, where N is the RMT channel number [0, 7] and the event_name is one of four events described above.
How to set that particular bit ?

Do i do this

Code: Select all

RMT.int_clr.ch0_rx_end = 1;
4. I also dont understand this interrupt level : rmt_isr_register(&led, NULL, ESP_INTR_FLAG_LEVEL1,NULL);
How does this come into play ?

Code: Select all

/* Copyright (c) 2017 pcbreflux. All Rights Reserved.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, version 3.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program. If not, see <http://www.gnu.org/licenses/>.

   Based on the Code from Neil Kolban: https://github.com/nkolban/esp32-snippets/blob/master/hardware/infra_red/receiver/rmt_receiver.c
*/
#include "ESP32_IR_Remote.h"
#include "soc/rmt_struct.h"

// Clock divisor (base clock is 80MHz)
#define CLK_DIV 100

// Number of clock ticks that represent 10us.  10 us = 1/100th msec.
#define TICK_10_US (80000000 / CLK_DIV / 100000)

static RingbufHandle_t ringBuf;

#define TAG "IR_TASK"

#define NEC_BITS          32
#define NEC_HDR_MARK    9000
#define NEC_HDR_SPACE   4500
#define NEC_BIT_MARK     560
#define NEC_ONE_SPACE   1690
#define NEC_ZERO_SPACE   560
#define NEC_RPT_SPACE   2250



extern int gpionum = 19;
extern int rmtport = 0;

const int RECV_PIN = 19; // pin on the ESP32
const int LED1_PIN = 2; // pin on the ESP32
const int LED2_PIN = 2; // pin on the ESP32

//ESP32_IRrecv irrecv(RECV_PIN,3);
static uint8_t command = 0;
static uint8_t led1_stat = 0;
//static uint8_t led2_stat=0;
bool led_state = false;
volatile int flag = 0;
//rmt_dev_t RMT;

void led(void *args)
{
  led_state = !led_state;
  digitalWrite(LED1_PIN, led_state);   // turn the LED initialy off (0)
  Serial.println("inside isr...");
  flag = 1;
  // RMT.int_clr.val.ch0_rx_end = 1;
  RMT.int_clr.ch0_rx_end = 1;
  // rmt_clr_intr_enable_mask(ESP_INTR_FLAG_LEVEL1);
}

void setup()
{
  Serial.begin(115200);
  Serial.println("Initializing...");
  // RMT.int_clr.val=0;
  rmt_config_t config;
  config.rmt_mode = RMT_MODE_RX;
  config.channel = (rmt_channel_t)rmtport;
  config.gpio_num = (gpio_num_t)gpionum;
  config.mem_block_num = 2;
  config.rx_config.filter_en = 1;
  config.rx_config.filter_ticks_thresh = 100; // 80000000/100 -> 800000 / 100 = 8000  = 125us
  config.rx_config.idle_threshold = TICK_10_US * 100 * 20;
  config.clk_div = CLK_DIV;




  ESP_ERROR_CHECK(rmt_config(&config));

  // rmt_isr_register(&led, NULL, ESP_INTR_FLAG_LEVEL1,NULL);
  rmt_set_rx_intr_en((rmt_channel_t) rmtport, true);

  ESP_ERROR_CHECK(rmt_driver_install(config.channel, 5000, 0));

  rmt_get_ringbuf_handle(config.channel, &ringBuf);
  // dumpStatus(config.channel);
  rmt_rx_start(config.channel, 1);

  //  irrecv.init();
  Serial.println("Init complete");
  pinMode(LED1_PIN, OUTPUT);
  digitalWrite(LED1_PIN, led_state);   // turn the LED initialy off (0)

}

void loop()
{
  if (flag)
  {
    // readIR();
  }
  //  rmt_dev_t RMT;
  RMT.int_clr.ch0_rx_end = 1;
  // rmt_set_intr_enable_mask(ESP_INTR_FLAG_LEVEL1);
}


I just want to read the sent IR code using interrupts.
Attachments
ESP32_IR_Remote.cpp
(6.95 KiB) Downloaded 739 times
ESP32_IR_Remote.h
(1.94 KiB) Downloaded 778 times

Who is online

Users browsing this forum: No registered users and 46 guests