Page 1 of 4

Need help regarding UART1 and UART2 communication for ESP32

Posted: Tue Oct 25, 2016 12:34 pm
by Ritesh
Hi,

I have one ESP32 chip based custom board in which UART1 and UART2 are connected with other controller chip and I am working on ESP32-idf RTOS SDK.

Now, I want to enable both UART1 and UART2 and want to send and receive some data over UART interface.

Does anyone has any idea regarding code point of view to initialize UART1 and UART2 and send/receive data for ESP32?

Please let me know ASAP.

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Tue Oct 25, 2016 4:02 pm
by kolban
I have been super impressed with the work done by mr "me-no-dev" on the Arduino libraries. He seems to have decoded much of the ESP32 hardware interfaces. Either he is extraordinarily talented in comprehending technical documents or he has spent a lot of time on it or a mixture of both ... but either way his contributions are huge.

Within the Arduino code there are "hardware abstraction libraries" which provide C consumable interfaces to the underlying hardware. For example, this source file seems to wrap the UART functions in what appears to be all three of the hardware UARTs:

https://github.com/espressif/arduino-es ... hal-uart.c

You might be able to study this for your answers or maybe even lift it as-is.

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Tue Oct 25, 2016 5:12 pm
by Ritesh
Hi,

Thanks for update...

It seems information is enough for me though I am working on ESP32-idf RTOS SDK.

I will check and will let you know if need any other help.

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Tue Oct 25, 2016 9:18 pm
by ESP_Me-no-dev
@Ritesh esp32 Arduino can be used as an IDF component in your IDF projects, so you can access the drivers and familiar API from there while having full control of everything else.
In the root of your project, create a folder named "components". Open terminal/console into that folder and

Code: Select all

git clone https://github.com/espressif/arduino-esp32 arduino
. From then on, you can include Arduino.h in your files and have access to the api.

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Tue Oct 25, 2016 11:15 pm
by rudi ;-)
ESP_Me-no-dev wrote:@Ritesh esp32 Arduino can be used as an IDF component in your IDF projects, so you can access the drivers and familiar API from there while having full control of everything else.
In the root of your project, create a folder named "components". Open terminal/console into that folder and

Code: Select all

git clone https://github.com/espressif/arduino-esp32 arduino
. From then on, you can include Arduino.h in your files and have access to the api.
thanks, got small error on class Print :)

Code: Select all


In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Print.h:27:0,
                 from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Stream.h:26,
                 from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:136,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Printable.h:25:1: error: unknown type name 'class'
 class Print;
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Printable.h:33:1: error: unknown type name 'class'
 class Printable
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Printable.h:34:1: error: expected '=', ',', ';', 'asm' or
'__attribute__' before '{' token
 {
 ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Stream.h:26:0,
                 from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:136,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Print.h:34:1: error: unknown type name 'class'
 class Print
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Print.h:35:1: error: expected '=', ',', ';', 'asm' or '__a
ttribute__' before '{' token
 {
 ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:136:0,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Stream.h:38:1: error: unknown type name 'class'
 class Stream: public Print
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Stream.h:38:13: error: expected '=', ',', ';', 'asm' or '_
_attribute__' before ':' token
 class Stream: public Print
             ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:139:0,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/IPAddress.h:29:1: error: unknown type name 'class'
 class IPAddress: public Printable
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/IPAddress.h:29:16: error: expected '=', ',', ';', 'asm' or
 '__attribute__' before ':' token
 class IPAddress: public Printable
                ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/IPAddress.h:91:1: error: unknown type name 'IPAddress'
 const IPAddress INADDR_NONE(0, 0, 0, 0);
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/IPAddress.h:91:29: error: expected declaration specifiers
or '...' before numeric constant
 const IPAddress INADDR_NONE(0, 0, 0, 0);
                             ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/IPAddress.h:91:32: error: expected declaration specifiers
or '...' before numeric constant
 const IPAddress INADDR_NONE(0, 0, 0, 0);
                                ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/IPAddress.h:91:35: error: expected declaration specifiers
or '...' before numeric constant
 const IPAddress INADDR_NONE(0, 0, 0, 0);
                                   ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/IPAddress.h:91:38: error: expected declaration specifiers
or '...' before numeric constant
 const IPAddress INADDR_NONE(0, 0, 0, 0);
                                      ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:140:0,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Client.h:26:1: error: unknown type name 'class'
 class Client: public Stream
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Client.h:26:13: error: expected '=', ',', ';', 'asm' or '_
_attribute__' before ':' token
 class Client: public Stream
             ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:141:0,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Server.h:25:1: error: unknown type name 'class'
 class Server: public Print
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Server.h:25:13: error: expected '=', ',', ';', 'asm' or '_
_attribute__' before ':' token
 class Server: public Print
             ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:142:0,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Udp.h:41:1: error: unknown type name 'class'
 class UDP: public Stream
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Udp.h:41:10: error: expected '=', ',', ';', 'asm' or '__at
tribute__' before ':' token
 class UDP: public Stream
          ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:143:0,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/HardwareSerial.h:35:1: error: unknown type name 'class'
 class HardwareSerial: public Stream
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/HardwareSerial.h:35:21: error: expected '=', ',', ';', 'as
m' or '__attribute__' before ':' token
 class HardwareSerial: public Stream
                     ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/HardwareSerial.h:74:1: error: unknown type name 'HardwareS
erial'
 extern HardwareSerial Serial;
 ^
In file included from C:/college/floh/01_hello_world/components/arduino/cores/esp32/Arduino.h:144:0,
                 from C:/college/floh/01_hello_world/main/PIR_Nano32.c:36:
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Esp.h:51:1: error: unknown type name 'class'
 class EspClass
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Esp.h:52:1: error: expected '=', ',', ';', 'asm' or '__att
ribute__' before '{' token
 {
 ^
C:/college/floh/01_hello_world/components/arduino/cores/esp32/Esp.h:83:1: error: unknown type name 'EspClass'
 extern EspClass ESP;
 ^
make[1]: *** [c:/sdk32/esp-idf/make/component_common.mk:111: PIR_Nano32.o] Error 1
make[1]: Leaving directory '/c/college/floh/01_hello_world/build/main'
make: *** [c:/sdk32/esp-idf/make/project.mk:251: main-build] Error 2


Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Wed Oct 26, 2016 12:48 am
by ESP_Me-no-dev
you are trying to call CPP classes from C file :) You can use esp32-hal-*.h in C, the rest only in C++

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Wed Oct 26, 2016 1:56 am
by Ritesh
Hi,

Thanks for quick reply...

Let me try in my code and will contact if any issue in compilation or configuration stuffs.

So, it seems using this Arduino components I can send or receive data to both UART on ESP32. Correct?

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Wed Oct 26, 2016 8:55 am
by rudi ;-)
ESP_Me-no-dev wrote:you are trying to call CPP classes from C file :) You can use esp32-hal-*.h in C, the rest only in C++
thanks Me-no-dev, i did try with .c -> .cpp but this worked not in second try, i will try your #include esp32-hal-*.h next step, thanks!

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Wed Oct 26, 2016 9:14 am
by Ritesh
Hi,

I have cloned it using following commands into components and compiled my application in which whole Arduino module is compiled successfully without any issue.
cd esp-idf/components
git clone https://github.com/espressif/arduino-esp32 arduino
I have also called some functions for that without any compilation error.

Please let me know if you are still getting any compilation error.

Re: Need help regarding UART1 and UART2 communication for ESP32

Posted: Wed Oct 26, 2016 11:29 am
by ESP_Me-no-dev
@rudi I especially committed a change so you can safely include Arduino.h in C files as well