Using rmt_set_pin to change the pin bound to an RMT channel

szguyer
Posts: 19
Joined: Thu Jan 11, 2018 5:41 pm

Using rmt_set_pin to change the pin bound to an RMT channel

Postby szguyer » Sun Apr 22, 2018 2:32 am

Hello!

I am using the RMT peripheral to drive RGB LEDs, and I have a general driver for the FastLED library that supports up to eight outputs using the eight available RMT channels.

Recently, I have been working on a new version that supports more outputs by reusing RMT channels when they complete their transmission. For this to work, however, I need to be able to change the gpio pin associated with a particular RMT channel. What I am doing right now looks like this:

0. Attach two RGB strips (e.g., WS2812) to pins X and Y (the exact numbers are not important)
1. configure channel 0 for pin X
2. send all data on channel 0
3. change channel 0 to pin Y using rmt_set_pin
4. send all data on channel 1

I don't get any explicit errors, but the output is all mixed up. It looks sort of like the data is going to *both* pins in step (4) -- the LEDs are displaying the right colors, but on *both* strips.

For comparison, if I run the exact same code, but use a different RMT channel for steps (3) and (4), it all works perfectly.

Am I missing something here? Do I need to explicitly tell the gpio matrix thing *not* to use pin X anymore?

Any help would be greatly appreciated!
Thanks!

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

Re: Using rmt_set_pin to change the pin bound to an RMT channel

Postby ESP_Sprite » Mon Apr 23, 2018 1:39 am

Effectively, 'configuring the RMT for a pin' configures the GPIO matrix to use the specified pin as an output for the RMT; it does not tell it to de-configure the output for the existing pin. (This allows you to output the same signal on multiple pins, as you inadvertently found out.) To de-configure the output, either tweak the GPIO matrix yourself (using gpio_matrix_out) or just configure the offending pin back into a GPIO by calling e.g. gpio_output_enable.

szguyer
Posts: 19
Joined: Thu Jan 11, 2018 5:41 pm

Re: Using rmt_set_pin to change the pin bound to an RMT channel

Postby szguyer » Mon Apr 23, 2018 3:07 am

That worked! I used the following call to turn off output to the old pin:

Code: Select all

gpio_matrix_out(old_pin, 0x100, 0, 0);
Thank you!

michaelu
Posts: 8
Joined: Sun Jan 28, 2018 5:29 pm
Location: München (Munich, Germany)

Re: Using rmt_set_pin to change the pin bound to an RMT channel

Postby michaelu » Sat Feb 02, 2019 6:43 am

Instead of rmt_set_pin (and rmt_clear_pin, which I don't know if it exists), you may be using

Code: Select all

			
pinMode(pin, OUTPUT);
pinMatrixOutAttach(pin, RMT_SIG_OUT0_IDX + chan, 0, 0);

.. use chan with pin, then

pinMatrixOutDetach(pin, 0, 0);


Who is online

Users browsing this forum: forrest and 65 guests