I am trying to understand how to use the RMT peripheral. I want to send a sequence of pulses (3,4,5 to 100 pulses) by setting the rmt_set_tx_thr_intr_en to the number of pulses, and stopping the rmt when that number is reached. My code however is not working. What I see is the initial pulses (and that is the wrong number too. I see 4 pulses on the scope when I send 3 ) and then nothing.
So the issues are:
1. why do I see 4 instead of 3 pulses the first time.
2. how does one start and stop the rmt after changing the alarm value for the interrupt.
Could anyone please comment on what is wrong with this code:
Code: Select all
#define RMT_TX_CHANNEL RMT_CHANNEL_0
#define RMT_TX_GPIO
uint32_t intr_st = 0;
void IRAM_ATTR rmt_isr_handler(void *arg)
{
RMT.int_clr.val = intr_st;
rmt_tx_stop(RMT_TX_CHANNEL);
}
void app_main(void *ignore)
{
rmt_isr_handle_t xHandler = NULL;
rmt_config_t config;
config.rmt_mode = RMT_MODE_TX;
config.channel = RMT_TX_CHANNEL;
config.gpio_num = RMT_TX_GPIO;
config.mem_block_num = 1;
config.tx_config.loop_en = true;
config.tx_config.carrier_en = false;
config.tx_config.idle_output_en = 1;
config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
config.tx_config.carrier_level = RMT_CARRIER_LEVEL_HIGH;
config.clk_div = 80; // 80MHx / 80 = 1MHz 0r 1uS per count
intr_st = RMT.int_st.val;
int MAX_PULSES = 3;
rmt_item32_t items[2];
items[0].duration0 = 3;
items[0].level0 = 1;
items[0].duration1 = 3;
items[0].level1 = 0;
items[0].duration0 = 0; //termination
items[0].level0 = 0;
rmt_config(&config);
rmt_set_tx_thr_intr_en(RMT_TX_CHANNEL, true, MAX_PULSES);
rmt_fill_tx_items(RMT_TX_CHANNEL, (rmt_item32_t *)items, 2, 0);
rmt_isr_register(rmt_isr_handler, NULL, ESP_INTR_FLAG_LEVEL1, &xHandler);
rmt_tx_start(RMT_TX_CHANNEL, true);
for (int i = 4; i < 100; i++)
{
printf("Setting %i pulses\n", i);
rmt_set_tx_thr_intr_en(RMT_TX_CHANNEL, true, i);
rmt_tx_start(RMT_TX_CHANNEL, false);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Progit