arduinoesp32arduino-c++

trouble setting up a rmt channel


I am learning to use the esp32 for some projects. I was attempting to set up an rmt channel as per the documentation however when I try to create a new RMT channel I get an invalid argument error here is my code.

#include "driver/rmt_tx.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_err.h"
#include <Arduino.h>

rmt_channel_handle_t tx_chan = NULL;

void setup() {
    Serial.begin(9600);
    
    
    rmt_tx_channel_config_t tx_chan_config = {
        .gpio_num = GPIO_NUM_16,              
        .clk_src = RMT_CLK_SRC_DEFAULT,       
        .resolution_hz = 1 * 1000 * 1000,     
        .mem_block_symbols = 4,             
    };

    esp_err_t err = rmt_new_tx_channel(&tx_chan_config, &tx_chan);
    if (err != ESP_OK) {
        Serial.printf("Error creating RMT TX channel: 0x%x\n", err);
    } else {
        Serial.println("RMT TX channel created successfully!");
    }
}

void loop() {
   
}

Here is the error I am getting when I upload to my esp32

DE (10) rmt: rmt_new_tx_channel(208): invalid argument

Error creating RMT TX channel: 0x102

If it matters I have a esp32 ESP-WROOM-32 ESP32 ESP-32S Development Board.

I tried making a rx channel to see if that was the issue but it threw the same error


Solution

  • The complete rmt_tx_channel_config_t object should look like this:

        rmt_tx_channel_config_t tx_chan_config = {
            .gpio_num = GPIO_NUM_16,              
            .clk_src = RMT_CLK_SRC_DEFAULT,       
            .resolution_hz = 1 * 1000 * 1000,     
            .mem_block_symbols = 64, 
            .trans_queue_depth = 4            
        };
    
    1. You are missing the .trans_queue_depth setting.

    2. The mem_block_symbols need to be at least 64 (i.e. 64 * 4 = 256 bytes).