refactor(rmt): refactored RMT loopback example (#11221)
* feat(rmt): refactored RMT loopback example * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
parent
8e8b1cbd31
commit
2647cbbbc2
1 changed files with 31 additions and 18 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2023 Espressif Systems (Shanghai) PTE LTD
|
||||
// Copyright 2025 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
|
@ -35,14 +35,11 @@
|
|||
rmt_data_t my_data[256];
|
||||
rmt_data_t data[256];
|
||||
|
||||
static EventGroupHandle_t events;
|
||||
|
||||
#define RMT_FREQ 10000000 // tick time is 100ns
|
||||
#define RMT_NUM_EXCHANGED_DATA 30
|
||||
#define RMT_NUM_EXCHANGED_DATA 32
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
events = xEventGroupCreate();
|
||||
|
||||
if (!rmtInit(RMT_TX_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, RMT_FREQ)) {
|
||||
Serial.println("init sender failed\n");
|
||||
|
|
@ -50,25 +47,41 @@ void setup() {
|
|||
if (!rmtInit(RMT_RX_PIN, RMT_RX_MODE, RMT_MEM_RX, RMT_FREQ)) {
|
||||
Serial.println("init receiver failed\n");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println("RMT tick set to: 100ns");
|
||||
|
||||
// End of transmission shall be detected when line is idle for 2us = 20*100ns
|
||||
rmtSetRxMaxThreshold(RMT_RX_PIN, 20);
|
||||
// Disable Glitch filter
|
||||
rmtSetRxMinThreshold(RMT_RX_PIN, 0);
|
||||
|
||||
Serial.println("real tick set to: 100ns");
|
||||
Serial.printf("\nPlease connect GPIO %d to GPIO %d, now.\n", RMT_TX_PIN, RMT_RX_PIN);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Init data
|
||||
int i;
|
||||
for (i = 0; i < 255; i++) {
|
||||
data[i].val = 0x80010001 + ((i % 13) << 16) + 13 - (i % 13);
|
||||
// create multiple pulses with different width to be sent
|
||||
for (int i = 0; i < 255; i++) {
|
||||
data[i].level0 = 1; // HIGH
|
||||
data[i].duration0 = 1 + 13 - (i % 13); // number of Tick on High
|
||||
data[i].level1 = 0; // LOW
|
||||
data[i].duration1 = 1 + (i % 13); // number of Ticks on Low
|
||||
my_data[i].val = 0;
|
||||
}
|
||||
data[255].val = 0;
|
||||
Serial.println();
|
||||
Serial.println("====================================================================================================");
|
||||
Serial.println("Preloaded Data that will sent (time in 0.1us):");
|
||||
// Printout the received data plus the original values
|
||||
for (int i = 0; i < RMT_NUM_EXCHANGED_DATA; i++) {
|
||||
Serial.printf("%08lx=[%c 0x%02x|%c 0x%02x] ", data[i].val, data[i].level0 ? 'H' : 'L', data[i].duration0, data[i].level1 ? 'H' : 'L', data[i].duration1);
|
||||
|
||||
if (!((i + 1) % 4)) {
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
Serial.println("====================================================================================================");
|
||||
Serial.printf("Please connect GPIO %d to GPIO %d, now.", RMT_TX_PIN, RMT_RX_PIN);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Start an async data read
|
||||
size_t rx_num_symbols = RMT_NUM_EXCHANGED_DATA;
|
||||
rmtReadAsync(RMT_RX_PIN, my_data, &rx_num_symbols);
|
||||
|
|
@ -84,13 +97,13 @@ void loop() {
|
|||
Serial.printf("Got %d RMT symbols\n", rx_num_symbols);
|
||||
|
||||
// Printout the received data plus the original values
|
||||
for (i = 0; i < 60; i++) {
|
||||
for (int i = 0; i < RMT_NUM_EXCHANGED_DATA; i++) {
|
||||
Serial.printf("%08lx=%08lx ", my_data[i].val, data[i].val);
|
||||
if (!((i + 1) % 4)) {
|
||||
Serial.println("");
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
Serial.println("\n");
|
||||
Serial.println();
|
||||
|
||||
delay(500);
|
||||
delay(2000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue