Page 1 of 1

ESP32-C3 UART IRDA support

Posted: Sun May 22, 2022 10:06 pm
by tom_jf
Hi
i am trying to implement a project that involves IRDA data communication.
In all the docs it is stated, that the ESP32 UART can be configured to act as IRDA encoder/decoder and directly control an IRDA tranceiver. Based on that I did my design.
Now either me or the ESP-Software have some flaws.
I got inspired by this post: viewtopic.php?t=2766
and did this:

void setup() {
pinMode(0,OUTPUT);
digitalWrite(0, HIGH);
Serial.begin(115200);
USBSerial.begin(115200);
WRITE_PERI_REG( 0x3FF40020 , READ_PERI_REG(0x3FF50020) | (1<<16 ) | (1<<10 ) ); //UART_IRDA_EN + UART_IRDA_TX_EN
for (uint8_t n = 0;n<10; n++) {
Serial.printf("UART-OK[%d] ", n);
USBSerial.printf("USB-OK[%d] ", n);
delay(500);
if (!(n&0x7)){
Serial.println();
USBSerial.println();
}
}

As soon as I include the WRITE_PERI_REG call, the result is a boot loop, no mater what I try:

ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x403818be
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x438
load:0x403ce000,len:0x90c
load:0x403d0000,len:0x2358
SHA-256 comparison failed:
Calculated: a9753a4fc647c6545c1b919ef08db429130a48592727edca270f1e5a3da0d0a9
Expected: 3bf6ef2cf3b9eefcd4b3c70cc5d1ce5138292d101a5cb1d5db6fbebf081b0a19
Attempting to boot anyway...
entry 0x403ce000

What is wrong here? A bug? Me?
Any input highly appreciated.
Regards
Thomas

Re: ESP32-C3 UART IRDA support

Posted: Mon May 23, 2022 5:49 am
by ESP_Sprite
That bit of code contains a peripheral address that is valid for the original, non-C3 ESP32 only. (Also, it may be wrong, it reads from 0x3FF50020 but writes to 0x3FF40020...)

I don't know Arduino good enough, but you could try this:

Code: Select all

#include "soc/uart_struct.h" //put this at the top of your program

//change the WRITE_PERI_REG line to this:
UART0.conf0.irda_en=1;
UART0.conf0.irda_tx_en=1;
If it works, it should also make your code compatible with most other ESP32s.

Re: ESP32-C3 UART IRDA support

Posted: Mon May 23, 2022 7:02 am
by lbernstone
Looks like the equivalent register is at 0x6001_0020 for UART1 in ESP32-C3 and the bytes are packed the same as ESP32.

Re: ESP32-C3 UART IRDA support

Posted: Mon May 23, 2022 7:04 am
by lbernstone
But the API is better :)

Re: ESP32-C3 UART IRDA support

Posted: Mon May 23, 2022 7:28 am
by tom_jf
Ii's a good day today.
"UART0.conf0.irda_en=1"... works well. I can now continue with my project.
timing.PNG
timing.PNG (38.88 KiB) Viewed 2823 times
The image shows what happens on the lines. Middle is the the sender, top the receiver and the lower is a toggle after Serial.flush().
All perfect.
I think I just need to "UART0.conf0.irda_tx_en=0;" after Serial.flush() when I want to switch to RECEIVE after send is complete, right?
Thank you for making may day...
Best regards
Thomas