Skip to content

Commit 52bda1c

Browse files
authored
RMT(feat): Create RMT_EndOfTransmissionState.ino example
1 parent a8133e7 commit 52bda1c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#define BLINK_GPIO 2
2+
#define EOT_INITIAL_STATE_TIME_MS 1000
3+
4+
// BLINK_GPIO shall start at RMT_EOT (HIGH or LOW) as initial state for EOT_INITIAL_STATE_TIME_MS,
5+
// BLINK: 1 second ON, 1 second OFF and then return/stay to RMT_EOT level at the end.
6+
#define RMT_EOT HIGH
7+
8+
// RMT is at 400KHz with a 2.5us tick
9+
// This RMT data sends a 0.5Hz pulse with 1s High and 1s Low signal
10+
rmt_data_t blink_1s_rmt_data[] = {
11+
// 400,000 x 2.5us = 1 second ON
12+
{25000, 1, 25000, 1,},
13+
{25000, 1, 25000, 1,},
14+
{25000, 1, 25000, 1,},
15+
{25000, 1, 25000, 1,},
16+
{25000, 1, 25000, 1,},
17+
{25000, 1, 25000, 1,},
18+
{25000, 1, 25000, 1,},
19+
{25000, 1, 25000, 1,},
20+
// 400,000 x 2.5us = 1 second OFF
21+
{25000, 0, 25000, 0,},
22+
{25000, 0, 25000, 0,},
23+
{25000, 0, 25000, 0,},
24+
{25000, 0, 25000, 0,},
25+
{25000, 0, 25000, 0,},
26+
{25000, 0, 25000, 0,},
27+
{25000, 0, 25000, 0,},
28+
{25000, 0, 25000, 0,},
29+
// Looping mode needs a Zero ending data to mark the EOF
30+
{0, 0, 0, 0}
31+
};
32+
33+
void setup() {
34+
Serial.begin(115200);
35+
Serial.println("Starting Blink testing...");
36+
Serial.flush();
37+
38+
// 1 RMT Block has 64 RMT_SYMBOLS (ESP32|ESP32S2) or 48 RMT_SYMBOLS (ESP32C3|ESP32S3)
39+
if (!rmtInit(BLINK_GPIO, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 400000)) { //2.5us tick
40+
Serial.println("===> rmtInit Error!");
41+
}
42+
43+
// sets the End of Transmission Level to HIGH, after writing to the pin. DEFAULT is LOW.
44+
rmtSetEOT(BLINK_GPIO, RMT_EOT);
45+
// set initial RMT state by writing a single RMT data
46+
rmt_data_t initStateSetup_rmt_data[] = { {1, RMT_EOT, 0, 0} };
47+
rmtWrite(BLINK_GPIO, initStateSetup_rmt_data, RMT_SYMBOLS_OF(initStateSetup_rmt_data), RMT_WAIT_FOR_EVER);
48+
Serial.printf("\nLED GPIO%d start in the inital level %s\n", BLINK_GPIO, RMT_EOT == LOW ? "LOW" : "HIGH");
49+
delay(EOT_INITIAL_STATE_TIME_MS); // set initial state of the LED is set by RMT_EOT.
50+
51+
// Send the data and wait until it is done - set EOT level to HIGH
52+
Serial.printf("\nLED GPIO%d Blinks 1 second HIGH - 1 second LOW.\n", BLINK_GPIO);
53+
if (!rmtWrite(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 2, RMT_WAIT_FOR_EVER)) {
54+
Serial.println("===> rmtWrite Blink 1s Error!");
55+
}
56+
Serial.printf("\nLED GPIO%d goes to the EOT level %s\n", BLINK_GPIO, RMT_EOT == LOW ? "LOW" : "HIGH");
57+
}
58+
59+
void loop(){}

0 commit comments

Comments
 (0)