Need help regarding UART1 and UART2 communication for ESP32

User avatar
rudi ;-)
Posts: 1729
Joined: Fri Nov 13, 2015 3:25 pm

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby rudi ;-) » Wed Oct 26, 2016 11:50 am

ESP_Me-no-dev wrote:@rudi I especially committed a change so you can safely include Arduino.h in C files as well
thank you , i use here in the test windows binary from espressif, usually i am on linux - i will test later again.
thanks for your effort again - you did SPI ( ESP8266 ) in briliant work - so i am sure - the mistake is here on my desk.

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
rudi ;-)
Posts: 1729
Joined: Fri Nov 13, 2015 3:25 pm

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby rudi ;-) » Wed Oct 26, 2016 12:27 pm

ESP_Me-no-dev wrote:@rudi I especially committed a change so you can safely include Arduino.h in C files as well
feedback: perfect!
Thanks! compile without error! ( win binary )

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby Ritesh » Wed Oct 26, 2016 5:20 pm

Hi,

Can anyone provide sample code to write any character or string buffer on UART1 and to read data from same UART1?

Also provide me startup UART1 configuration to till how to send and receive data.

It will be helpful for me if anyone can provide me ASAP.
Regards,
Ritesh Prajapati

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby kolban » Wed Oct 26, 2016 5:32 pm

The hardware abstraction layer samples and code found as part of the Arduino ESP32 library look like they provide what you need:

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

The following APIs seem to be present
  • uartBegin
  • uartEnd
  • uartAvailable
  • uartRead
  • uartPeek
  • uartWrite
  • uartWriteBuf
  • uartFlush
  • uartSetBaudRate
  • uartGetBaudRate
  • uartSetDebug
  • uartGetDebug
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby Ritesh » Wed Oct 26, 2016 5:52 pm

Hi,

Yes. I have checked UART c file in which all above APIs are defined which you have mentioned in your reply.

I just want sample code sequence if anyone has used that code to write/read data for UART1 into Arduino board which will be helpful for me.
Regards,
Ritesh Prajapati

User avatar
rudi ;-)
Posts: 1729
Joined: Fri Nov 13, 2015 3:25 pm

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby rudi ;-) » Wed Oct 26, 2016 7:28 pm

Ritesh wrote:Hi,

Yes. I have checked UART c file in which all above APIs are defined which you have mentioned in your reply.

I just want sample code sequence if anyone has used that code to write/read data for UART1 into Arduino board which will be helpful for me.
Hi,
have you read this?
http://esp32.com/viewtopic.php?f=19&t=328#p1398
best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby Ritesh » Wed Oct 26, 2016 7:47 pm

Hi,

Yes. I checked that thread and it seems like that they are going to turn on serial UART2 using Arduino code and I am working on ESP-idf RTOS SDK.

So, let me check compatible functions and configurations for that and will let you know if need any help.

But, it will be more helpful for me if you can provide exact sample code relevant to EPP-idf RTOS SDK as per functions defined in UART driver file.
Regards,
Ritesh Prajapati

User avatar
ESP_Me-no-dev
Posts: 80
Joined: Mon Jan 04, 2016 6:30 pm

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby ESP_Me-no-dev » Thu Oct 27, 2016 5:26 am

Ritesh, you can look into HardwareSerial.cpp as well and see what happens when you start arduino Serial :) it's pretty straight forward.

Code: Select all

#include "esp32-hal.h"

uart_t* uart1;

bool startUart(uint32_t baudrate, int8_t rxPin, int8_t txPin){
  uart1 = uartBegin(1, baud, SERIAL_8N1, rxPin, txPin, 256, false);
  return uart1 != NULL;
}

void sendSomeData(){
  const char * message = "Hello UART! ESP32 here :)";
  uartWriteBuf(uart1, (const uint8_t *)message, strlen(message));
}

void checkForData(){
  int i;
  size_t available = uartAvailable(uart1);
  if(available){
    uint8_t out[available];
    for(i=0; i<available;i++){
      out[i] = uartRead(uart1);
    }
    //out now contains all of the available data
  }
}

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby Ritesh » Thu Oct 27, 2016 8:29 am

Hi,

Thanks for code snippet.. I have verified on UART2 and it seems working fine without any issue.

I will also check on UART1 as well and will let you know if any difficulty for that.

Thank you very much again.
Regards,
Ritesh Prajapati

User avatar
rudi ;-)
Posts: 1729
Joined: Fri Nov 13, 2015 3:25 pm

Re: Need help regarding UART1 and UART2 communication for ESP32

Postby rudi ;-) » Thu Oct 27, 2016 9:59 am

ESP_Me-no-dev wrote:Ritesh, you can look into HardwareSerial.cpp as well and see what happens when you start arduino Serial :) it's pretty straight forward.

Code: Select all

#include "esp32-hal.h"

uart_t* uart1;

bool startUart(uint32_t baudrate, int8_t rxPin, int8_t txPin){
  uart1 = uartBegin(1, baud, SERIAL_8N1, rxPin, txPin, 256, false);
  return uart1 != NULL;
}

void sendSomeData(){
  const char * message = "Hello UART! ESP32 here :)";
  uartWriteBuf(uart1, (const uint8_t *)message, strlen(message));
}

void checkForData(){
  int i;
  size_t available = uartAvailable(uart1);
  if(available){
    uint8_t out[available];
    for(i=0; i<available;i++){
      out[i] = uartRead(uart1);
    }
    //out now contains all of the available data
  }
}
Thanks - confirm, compile without errors in windows (7, 10 ) environment ( without VM and win binary )
me-no-dev, can u please give a snippy to make INTR on checkForData? ( Rx ) how you like to do this?
can we create (gpio) ISR too on "(rx) gpio way" and do a callback then? (anyedge?)
or do we this with timer and lookup?
thanks for your brilliant work! (Have misjudged you sry )

best wishes rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Who is online

Users browsing this forum: markkuk and 377 guests