(Solved) RMT driver for software UART with 22 bit data possible?

dzungpv
Posts: 36
Joined: Thu Mar 26, 2020 4:52 am

Re: RMT driver for software UART with 22 bit data possible?

Postby dzungpv » Thu Nov 28, 2024 1:04 pm

MicroController wrote:
Thu Nov 28, 2024 12:06 pm
dzungpv wrote:
Thu Nov 28, 2024 11:40 am
```
00155557 00155ff7 001d5f5f 00155557 00155557 0015f557 001dd57f 001557ff 00155557 0015575f 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
```
But receive only this raw data:
```
55 aa 55 80 57 e8 55 aa 55 aa f5 aa 77 fa 55 ff 55 aa 55 eb
```
I don't know why. the TX work fine.
1) You're receiving 10x22 'bits', but decoding it to 20 bytes. Make sure you ignore/remove the stuffing bits.
2) Make sure you also remove the parity bits from the decoded data.
I am not decode it, i try to read original encode data first.
the
```
00155557 00155ff7 001d5f5f 00155557 00155557 0015f557 001dd57f 001557ff 00155557 0015575f 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
```
is the raw data send in 22 bit encode in hexa. But I am not receive the original data.
I decode like this:

```
items = (rmt_item32_t*)xRingbufferReceive(rrc->rb, &length, ticks_to_wait);
if (items) {
for (size_t i = 0; i < length / 4; ++i)
{
ESP_LOGD(TAG, "\trmt rx item %02d: duration0: %d level0: %d duration1: %d level1: %d", i, items.duration0, items.level0, items.duration1, items.level1);
fill_bits(ctx, items.duration0, items.level0);
fill_bits(ctx, items.duration1, items.level1);
}
vRingbufferReturnItem(rrc->rb, (void*)items);

ESP_LOGD(TAG, "\trx is complete byte_num=%d", rrc->byte_num);
printf("rmt rx ");
for (int i = 0; i < rrc->byte_num; ++i)
printf("%02x ", rrc->bytes);
printf("\n\n");
}

static void fill_bits(rmt_uart_contex_t* ctx, uint32_t duration, uint32_t level)
{
rmt_uart_contex_rx_t* rrc = &ctx->rmt_uart_contex_rx;
rmt_uart_contex_rx_t* rrc = &ctx->rmt_uart_contex_rx;
int rmt_bit_numbers = round_closest(duration, ctx->rmt_bit_len);
// all remaining bits are high
if (rmt_bit_numbers == 0 && level) {
rmt_bit_numbers = 11 - rrc->bit_num;
}

int from = rrc->bit_num;
int to = rrc->bit_num + rmt_bit_numbers;
for (int j = from; j < to; ++j) {
rrc->bit_num++;
rrc->raw_data |= (level << j);
if (rrc->bit_num == 11) {
rrc->raw_data >>= 1;
rrc->raw_data &= 0x00FF;
rrc->bytes[rrc->byte_num] = rrc->raw_data;
ESP_LOGD(TAG, "\trmt rx data=%d", rrc->raw_data);
rrc->byte_num++;
rrc->bit_num = 0;
rrc->raw_data = 0;
}
}
```

I tested the github code with normal UART 19200 8N the code work fine. The code above modified for 22 bit data

User avatar
ok-home
Posts: 98
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: RMT driver for software UART with 22 bit data possible?

Postby ok-home » Thu Nov 28, 2024 1:26 pm

So the things write in the docs may not accurate, because RMT mostly use for IR data, and they do not long like my data.
it is checked in practice
I don't know how balancing units are set in the protocol but the decoder in the driver is set to start/data/parity/stop otherwise it will show anything

rmt_config_t rmt_config_rx = RMT_DEFAULT_CONFIG_RX(uart_config-&gt;rx_io_num, uart_num);
rmt_config_t rmt_config_tx = RMT_DEFAULT_CONFIG_TX(uart_config-&gt;tx_io_num, uart_num + 1);
rmt_config_rx.mem_block_num = (uart_config-&gt;mode == RMT_UART_MODE_RX_ONLY) ? 2 : 1;

plus as far as I can see the driver is not set to accept maximum number of characters at least according to only 1 block rmt 128 bits - transitions 0/1- 1/0
rmt_config_rx.rx_config.idle_threshold = 10 * bit_len;

reception will be interrupted if there is a pause in transmission of more than 10 zeros or 10 ones.

dzungpv
Posts: 36
Joined: Thu Mar 26, 2020 4:52 am

Re: RMT driver for software UART with 22 bit data possible?

Postby dzungpv » Thu Nov 28, 2024 1:56 pm

ok-home wrote:
Thu Nov 28, 2024 1:26 pm
So the things write in the docs may not accurate, because RMT mostly use for IR data, and they do not long like my data.
it is checked in practice
I don't know how balancing units are set in the protocol but the decoder in the driver is set to start/data/parity/stop otherwise it will show anything

rmt_config_t rmt_config_rx = RMT_DEFAULT_CONFIG_RX(uart_config-&gt;rx_io_num, uart_num);
rmt_config_t rmt_config_tx = RMT_DEFAULT_CONFIG_TX(uart_config-&gt;tx_io_num, uart_num + 1);
rmt_config_rx.mem_block_num = (uart_config-&gt;mode == RMT_UART_MODE_RX_ONLY) ? 2 : 1;

plus as far as I can see the driver is not set to accept maximum number of characters at least according to only 1 block rmt 128 bits - transitions 0/1- 1/0
rmt_config_rx.rx_config.idle_threshold = 10 * bit_len;

reception will be interrupted if there is a pause in transmission of more than 10 zeros or 10 ones.
I change it to the 22 bit, it is: rmt_config_rx.rx_config.idle_threshold = 22 * bit_len; but the same result.
The github origin code work fine with 19200 8N1 it is 10 bit, I just change the idle_threshold and the decode function. It must be working but it not. With the results seem that 128 bit is whar it can handle, that why I only receive 16 bytes and later 4 bytes sequence, 16 byte is 128bit, so whatever buffer size and settings, the old driver only can handle 128 bit, at least with the ESP32 I tested.

But it is never decode 0x15, include in the encode data 22 bit: 0x00155557

With TX code I encode data in only 11 rmt_item32_t for 22 bit data, it send fine and can be receive with my old bit-bang code.
I still not clearly understand how the RMT work.

Code: Select all

    if (ctx->rmt_uart_config.data_bits == RMT_UART_DATA_22_BITS) {
        uint32_t encoded_data = 0;
        byte_encode(byte, &encoded_data); // encode 8 bit to 22 bit data, example 0x00 will be 0x00155557
        encoded_data <<= 10;
        rmt_uart_contex_tx_t* rtc = &ctx->rmt_uart_contex_tx;
        // We only need 11 rmt_item32_t for 22 bit data
        for (int i = 0; i < 22; i += 2) {
            rmt_item32_t* item = &rtc->items[rtc->item_index];
            bool bit1 = ((encoded_data << i) & 0x80000000);  // Extract LSB
            item->level0 = bit1 ^ 1;  // Inverse bit
            item->duration0 = ctx->rmt_bit_len;
            bool bit2 = ((encoded_data << (i + 1)) & 0x80000000);  // Extract LSB
            item->level1 = bit2 ^ 1;  // Inverse bit
            item->duration1 = ctx->rmt_bit_len;
            rtc->item_index++;
            if (rtc->item_index >= (ctx->rmt_uart_config.buffer_size / sizeof(rmt_item32_t))) {
                ESP_LOGE(TAG, "DATA TOO LONG");
                return -1;
            }
            // ESP_LOGD(TAG, "\trmt tx item %02d: duration0: %d level0: %d  duration1: %d level1: %d", rtc->item_index, item->duration0, item->level0, item->duration1, item->level1);
        }
        return 0;
    } 
   

User avatar
ok-home
Posts: 98
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: RMT driver for software UART with 22 bit data possible?

Postby ok-home » Thu Nov 28, 2024 2:47 pm

you can see

Code: Select all

ESP_LOGD(TAG, "\trmt rx item %02d: duration0: %d level0: %d duration1: %d level1: %d", i, items.duration0, items.level0, items.duration1, items.level1);

add up all duration0+duration1
divided by bit_len this will be approximately the number of bits in the received packet

change memory allocation

Code: Select all

 rmt_config_t rmt_config_rx = RMT_DEFAULT_CONFIG_RX(uart_config-&gt;rx_io_num, 1); 
 rmt_config_t rmt_config_tx = RMT_DEFAULT_CONFIG_TX(uart_config-&gt;tx_io_num, 0); 
 rmt_config_rx.mem_block_num = 7

MicroController
Posts: 1818
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: RMT driver for software UART with 22 bit data possible?

Postby MicroController » Thu Nov 28, 2024 2:50 pm

Understanding the RMT is one thing. The other thing is that the RMT-UART code will look for 1 start bit, 1 stop bit, 1 parity bit in the 'bitstream' from the RMT, but from the Home Bus you get two 'bits' for every bit of a frame, including 2 'bits' for start (0b01), 2 'bits' for stop (0b11), 2 'bits' for parity (0b01 or 0b11).

Also, there's another frame length hardcoded as 11 in the code:

Code: Select all

// all remaining bits are high
if (rmt_bit_numbers == 0 && level) {
rmt_bit_numbers = 11 - rrc->bit_num;
}

dzungpv
Posts: 36
Joined: Thu Mar 26, 2020 4:52 am

Re: RMT driver for software UART with 22 bit data possible?

Postby dzungpv » Thu Nov 28, 2024 3:17 pm

ok-home wrote:
Thu Nov 28, 2024 2:47 pm
you can see

Code: Select all

ESP_LOGD(TAG, "\trmt rx item %02d: duration0: %d level0: %d duration1: %d level1: %d", i, items.duration0, items.level0, items.duration1, items.level1);

add up all duration0+duration1
divided by bit_len this will be approximately the number of bits in the received packet

change memory allocation

Code: Select all

 rmt_config_t rmt_config_rx = RMT_DEFAULT_CONFIG_RX(uart_config-&gt;rx_io_num, 1); 
 rmt_config_t rmt_config_tx = RMT_DEFAULT_CONFIG_TX(uart_config-&gt;tx_io_num, 0); 
 rmt_config_rx.mem_block_num = 7
You are super, now it receive full data, but it ignore all 0x00000000 data, only first 10s. Now I count the total duration it is: 11070, for 220 bits, it is: 52*220 = 11440 us, so lost 11440-11070 = 370 us, about 7 bits, but it may cause by framing delay. I will check with oscilloscope.
MicroController wrote:
Thu Nov 28, 2024 2:50 pm
Understanding the RMT is one thing. The other thing is that the RMT-UART code will look for 1 start bit, 1 stop bit, 1 parity bit in the 'bitstream' from the RMT, but from the Home Bus you get two 'bits' for every bit of a frame, including 2 'bits' for start (0b01), 2 'bits' for stop (0b11), 2 'bits' for parity (0b01 or 0b11).

Also, there's another frame length hardcoded as 11 in the code:

Code: Select all

// all remaining bits are high
if (rmt_bit_numbers == 0 && level) {
rmt_bit_numbers = 11 - rrc->bit_num;
}
But the original code on github not use parity bit and can send and receive the standard UART data

I also try to decode with new algorithm like when encode the data, but it still wrong.

Code: Select all

        // Fill the existing 22-bit buffer and process as needed.
        // Change rrc->raw_data to uint32_t
        rmt_uart_contex_rx_t* rrc = &ctx->rmt_uart_contex_rx;
        int rmt_bit_numbers = round_closest(duration, ctx->rmt_bit_len);
        if (rmt_bit_numbers == 0) {
            rmt_bit_numbers = 22 - rrc->bit_num;
        }
        int from = rrc->bit_num;
        int to = rrc->bit_num + rmt_bit_numbers;
        for (int j = from; j < to; ++j) {
            rrc->bit_num++;
            rrc->raw_data |= (level << j);
            if (rrc->bit_num == 22) {
                rrc->raw_data >>= 1;
                // rrc->raw_data &= 0x00FF;
                rrc->bytes[rrc->byte_num] = rrc->raw_data;
                ESP_LOGD(TAG, "\trmt rx data=%08lx", rrc->raw_data);
                rrc->byte_num++;
                rrc->bit_num = 0;
                rrc->raw_data = 0;
            }
        }
Receive data: 001d5555 001dff55 001f5f57 001d5555 001d5555 001d55f5 001fd577 001ffd55 003aaaaa 003ebaaa
Original raw data when send: 00155557 00155ff7 001d5f5f 00155557 00155557 0015f557 001dd57f 001557ff 00155557 0015575f

So, what wrong with this? The data encode from the raw duration data I am not think it wrong.

Updated: I change the RMT_DIV to 80, so it is more accurate with 19200 data and now the total duration is: 11484 it is nearly 11440, but the decode data still the same, it is more 5 number but not match send data:
001d5555 001dff55 001f5f57 001d5555 001d5555 001d55f5 001fd577 001ffd55 001d5555 001f5d55

dzungpv
Posts: 36
Joined: Thu Mar 26, 2020 4:52 am

Re: RMT driver for software UART with 22 bit data possible?

Postby dzungpv » Fri Nov 29, 2024 4:12 am

I nearly give up, it take 2 days and still not working.

The send data in hexa: 00155557 00155ff7 001d5f5f 00155557 00155557 0015f557 001dd57f 001557ff 00155557 0015575f

The send data in binary 220 bits, 52us period for both 1 and 0 data, uart like frame: 0101010101010101010111 0101010111111111011111 1110110101111101011111 0101010101010101010111 0101010101010101010111 0101111101010101010111 1110111010101011111111 0101010111111111111111 0101010101010101010111 0101010111111101011111

When sending, 220 bits data can encode and send successful with 110 rmt_item32_ts, the encode function I post in previous reply.

When RMT receive, the array of rmt_item32_t print for debug with level and duration, 80 bytes data:

Code: Select all

D (8418) rmt-uart: 	rmt rx item 00: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8418) rmt-uart: 	rmt rx item 01: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8422) rmt-uart: 	rmt rx item 02: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8430) rmt-uart: 	rmt rx item 03: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8438) rmt-uart: 	rmt rx item 04: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8446) rmt-uart: 	rmt rx item 05: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8453) rmt-uart: 	rmt rx item 06: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8461) rmt-uart: 	rmt rx item 07: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8469) rmt-uart: 	rmt rx item 08: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8477) rmt-uart: 	rmt rx item 09: duration0: 53 level0: 0  duration1: 175 level1: 1
D (8485) rmt-uart: 	rmt rx data=001d5555
D (8489) rmt-uart: 	rmt rx item 10: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8497) rmt-uart: 	rmt rx item 11: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8504) rmt-uart: 	rmt rx item 12: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8512) rmt-uart: 	rmt rx item 13: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8520) rmt-uart: 	rmt rx item 14: duration0: 53 level0: 0  duration1: 475 level1: 1
D (8528) rmt-uart: 	rmt rx item 15: duration0: 52 level0: 0  duration1: 175 level1: 1
D (8536) rmt-uart: 	rmt rx data=001dff55
D (8540) rmt-uart: 	rmt rx item 16: duration0: 53 level0: 0  duration1: 158 level1: 1
D (8548) rmt-uart: 	rmt rx item 17: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8556) rmt-uart: 	rmt rx item 18: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8563) rmt-uart: 	rmt rx item 19: duration0: 52 level0: 0  duration1: 264 level1: 1
D (8571) rmt-uart: 	rmt rx item 20: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8579) rmt-uart: 	rmt rx item 21: duration0: 53 level0: 0  duration1: 280 level1: 1
D (8587) rmt-uart: 	rmt rx data=001f5f57
D (8591) rmt-uart: 	rmt rx item 22: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8599) rmt-uart: 	rmt rx item 23: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8607) rmt-uart: 	rmt rx item 24: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8614) rmt-uart: 	rmt rx item 25: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8622) rmt-uart: 	rmt rx item 26: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8630) rmt-uart: 	rmt rx item 27: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8638) rmt-uart: 	rmt rx item 28: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8646) rmt-uart: 	rmt rx item 29: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8653) rmt-uart: 	rmt rx item 30: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8661) rmt-uart: 	rmt rx item 31: duration0: 52 level0: 0  duration1: 175 level1: 1
D (8669) rmt-uart: 	rmt rx data=001d5555
D (8673) rmt-uart: 	rmt rx item 32: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8681) rmt-uart: 	rmt rx item 33: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8689) rmt-uart: 	rmt rx item 34: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8697) rmt-uart: 	rmt rx item 35: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8704) rmt-uart: 	rmt rx item 36: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8712) rmt-uart: 	rmt rx item 37: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8720) rmt-uart: 	rmt rx item 38: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8728) rmt-uart: 	rmt rx item 39: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8736) rmt-uart: 	rmt rx item 40: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8743) rmt-uart: 	rmt rx item 41: duration0: 53 level0: 0  duration1: 178 level1: 1
D (8751) rmt-uart: 	rmt rx data=001d5555
D (8755) rmt-uart: 	rmt rx item 42: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8763) rmt-uart: 	rmt rx item 43: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8771) rmt-uart: 	rmt rx item 44: duration0: 53 level0: 0  duration1: 264 level1: 1
D (8779) rmt-uart: 	rmt rx item 45: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8787) rmt-uart: 	rmt rx item 46: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8794) rmt-uart: 	rmt rx item 47: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8802) rmt-uart: 	rmt rx item 48: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8810) rmt-uart: 	rmt rx item 49: duration0: 53 level0: 0  duration1: 175 level1: 1
D (8818) rmt-uart: 	rmt rx data=001d55f5
D (8822) rmt-uart: 	rmt rx item 50: duration0: 52 level0: 0  duration1: 159 level1: 1
D (8830) rmt-uart: 	rmt rx item 51: duration0: 52 level0: 0  duration1: 158 level1: 1
D (8838) rmt-uart: 	rmt rx item 52: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8846) rmt-uart: 	rmt rx item 53: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8853) rmt-uart: 	rmt rx item 54: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8861) rmt-uart: 	rmt rx item 55: duration0: 52 level0: 0  duration1: 386 level1: 1
D (8869) rmt-uart: 	rmt rx data=001fd577
D (8873) rmt-uart: 	rmt rx item 56: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8881) rmt-uart: 	rmt rx item 57: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8889) rmt-uart: 	rmt rx item 58: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8897) rmt-uart: 	rmt rx item 59: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8904) rmt-uart: 	rmt rx item 60: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8912) rmt-uart: 	rmt rx item 61: duration0: 53 level0: 0  duration1: 596 level1: 1
D (8920) rmt-uart: 	rmt rx data=001ffd55
D (8924) rmt-uart: 	rmt rx item 62: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8932) rmt-uart: 	rmt rx item 63: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8940) rmt-uart: 	rmt rx item 64: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8948) rmt-uart: 	rmt rx item 65: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8955) rmt-uart: 	rmt rx item 66: duration0: 52 level0: 0  duration1: 53 level1: 1
D (8963) rmt-uart: 	rmt rx item 67: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8971) rmt-uart: 	rmt rx item 68: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8979) rmt-uart: 	rmt rx item 69: duration0: 53 level0: 0  duration1: 52 level1: 1
D (8987) rmt-uart: 	rmt rx item 70: duration0: 53 level0: 0  duration1: 53 level1: 1
D (8994) rmt-uart: 	rmt rx item 71: duration0: 52 level0: 0  duration1: 175 level1: 1
D (9002) rmt-uart: 	rmt rx data=001d5555
D (9006) rmt-uart: 	rmt rx item 72: duration0: 53 level0: 0  duration1: 53 level1: 1
D (9014) rmt-uart: 	rmt rx item 73: duration0: 52 level0: 0  duration1: 53 level1: 1
D (9022) rmt-uart: 	rmt rx item 74: duration0: 53 level0: 0  duration1: 52 level1: 1
D (9030) rmt-uart: 	rmt rx item 75: duration0: 53 level0: 0  duration1: 53 level1: 1
D (9038) rmt-uart: 	rmt rx item 76: duration0: 52 level0: 0  duration1: 53 level1: 1
D (9045) rmt-uart: 	rmt rx item 77: duration0: 53 level0: 0  duration1: 158 level1: 1
D (9053) rmt-uart: 	rmt rx item 78: duration0: 53 level0: 0  duration1: 52 level1: 1
D (9061) rmt-uart: 	rmt rx item 79: duration0: 53 level0: 0  duration1: 0 level1: 1
D (9069) rmt-uart: 	rmt rx data=001f5d55
The function use to decode:

Code: Select all

static void fill_bits(rmt_uart_contex_t* ctx, uint32_t duration, uint32_t level)
{
        // Fill the existing 22 bit buffer and process as needed.
        // rrc->raw_data and bytes is uint32_t to store 22 bit data
        rmt_uart_contex_rx_t* rrc = &ctx->rmt_uart_contex_rx;
        int rmt_bit_numbers = round_closest(duration, ctx->rmt_bit_len);
        if (rmt_bit_numbers == 0) {
            rmt_bit_numbers = 22 - rrc->bit_num;
        }
        int from = rrc->bit_num;
        int to = rrc->bit_num + rmt_bit_numbers;
        for (int j = from; j < to; ++j) {
            rrc->bit_num++;
            rrc->raw_data |= (level << j);
            if (rrc->bit_num == 22) {
                rrc->raw_data >>= 1;
                rrc->raw_data &= 0x03FFFFF;
                rrc->bytes[rrc->byte_num] = rrc->raw_data;
                ESP_LOGD(TAG, "\trmt rx data=%08lx", rrc->raw_data);
                rrc->byte_num++;
                rrc->bit_num = 0;
                rrc->raw_data = 0;
            }
        }
}
Any expert in RMT help me decode the data? What wrong with the receive rmt_item32_ts?

What I don't clearly understand is that I can send the data with 110 rmt_item32_ts, but when receive it is 80? So that why the decode not successful. But the first 22 of the receiving data not match with binary data too.

dzungpv
Posts: 36
Joined: Thu Mar 26, 2020 4:52 am

Re: RMT driver for software UART with 22 bit data possible?

Postby dzungpv » Fri Nov 29, 2024 6:12 am

I try the new driver with example https://github.com/espressif/esp-idf/tr ... ransceiver.
The receive frame is 80, same with old driver. I change

Code: Select all

.mem_block_symbols = 256, // amount of RMT symbols that the channel can store at a time
and

Code: Select all

    // the following timing requirement is based on 19200 baud 22 bit protocol
    rmt_receive_config_t receive_config = {
        .signal_range_min_ns = 1250,     // the shortest duration for uart signal is 52us, 1250ns < 52us, valid signal won't be treated as noise
        .signal_range_max_ns = 27456000, // the longest duration for uart 19200 baud 22 bit signal is 1144us, 27456000ns > 1144us, the receive won't stop early
    };
The symbols receive is:

Code: Select all

UART frame start---
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:175}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:474}
{0:53},{1:175}
{0:53},{1:158}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:264}
{0:52},{1:53}
{0:53},{1:280}
{0:53},{1:52}
{0:53},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:52},{1:175}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:178}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:264}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:53},{1:52}
{0:53},{1:175}
{0:52},{1:159}
{0:52},{1:158}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:386}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:53},{1:596}
{0:53},{1:52}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:52},{1:175}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:52}
{0:53},{1:53}
{0:52},{1:53}
{0:53},{1:158}
{0:53},{1:52}
{0:53},{1:0}
---UART frame end: W (59524)
 example: total symbol_num: 80

User avatar
ok-home
Posts: 98
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: RMT driver for software UART with 22 bit data possible?

Postby ok-home » Fri Nov 29, 2024 6:57 am

Hi
I have corrected my rmt driver for your requirements, today-tomorrow I will check it, I will post it on github (if it works).
the only question - how data goes in protocol MSB first or LSB first ?

dzungpv
Posts: 36
Joined: Thu Mar 26, 2020 4:52 am

Re: RMT driver for software UART with 22 bit data possible?

Postby dzungpv » Fri Nov 29, 2024 7:11 am

ok-home wrote:
Fri Nov 29, 2024 6:57 am
Hi
I have corrected my rmt driver for your requirements, today-tomorrow I will check it, I will post it on github (if it works).
the only question - how data goes in protocol MSB first or LSB first ?
It is UART base, so it is LSB

Who is online

Users browsing this forum: Bing [Bot] and 60 guests