-
Notifications
You must be signed in to change notification settings - Fork 7.6k
how to use esp32-hal in arduino,example esp32-hal-uart.h for serial interrupt in arduino? #6102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @zouzhe1 This can be achieved using a Free RTOS Task that keeps waiting for an event to arrive in its queue, based on IDF call uart_driver_install(), as described in IDF Ref - uart_driver_install The event UART_DATA is the one that you are looking for. An example of this task and functionality can be found in IDF Queue Processing Specific Questions
Correct, Please note that PlatformIO is still using ESP32 Arduino Core version 1.0.6, thus it is an old version of the UART driver. Currently we don't support it anymore and there won't be any updates to this version.
|
@SuGlider Thank you for your answer |
Both versions 1.06 and 2.0.2 use serial port hardware interrupt to provide an Arduino Serial Hardware API to users. The software architecture makes 2.0.2 and 1.0.6 so different. Currently there is no implemented Arduino API IRQ call back functionality in both cases, 1.0.6 nor 2.0.2. So I think that none of them will solve your request at this time.
IDF 4.4 is fully included in the ESP32 Arduino Core 2.0.0+. You can use IDF calls as it is part of your Arduino Sketch code. Note that the current Serial Hardware code in Arduino Layer is builton top of IDF calls, for example, Serial.begin() becomes: You may use this code to create your own Serial Begin(), for instance, by creating your own MySerialBegin() and adding the IDF piece of code to deal with UART Events plus a Task to treat those events. At the end everything is just C code.
Arduino as an ESP-IDF component is a different way to build an application based on Arduino API.
I am sure that there is excellent Chinese language based web sites, blogs, forums, and other Intenet resources. ESPRESSIF has a Chinese version about the documentation and a Chinese Forum Site- I hope it suits your needs: |
A potential solution is being implemented. As soon as any data arrives UART RX, Example: void UART_RX_IRQ(){
uint16_t size = Serial.available();
Serial.printf("Got %d bytes on Serial to read\n", size);
while(Serial.available()) {
Serial.write(Serial.read());
}
Serial.printf("\nSerial data processed!\n");
}
void setup() {
Serial.begin(115200);
Serial.onReceive(UART_RX_IRQ);
Serial.println("Send data to UART0 in order to activate the RX callback");
}
void loop() {
Serial.println("Sleeping for 10 seconds...");
delay(10000);
} Would that work for you? |
@SuGlider Thank you very much for adding this new feature. |
Thanks a lot! This works great and to addon, Because it doesn't recognise user defined global variables. |
Not sure what exactly is the goal with the "global variable X". // this will make UART0 work for any case (using or not USB)
#if ARDUINO_USB_CDC_ON_BOOT
#define UART0 Serial0
#else
#define UART0 Serial
#endif
String X = ""; // global variable to keep the results from onReceive()
const uint32_t communicationTimeout_ms = 500; // a pause of half second in the UART transmission is considered end of transmission.
void UART_RX_IRQ() {
uint32_t now = millis(); // track timeout
while ( (millis() - now) < communicationTimeout_ms) {
if (UART0.available()) {
X += (char) UART0.read();
now = millis(); // reset the timer
}
}
}
void setup() {
UART0.begin(115200);
UART0.onReceive(UART_RX_IRQ);
UART0.println("Send data to UART0 in order to activate the RX callback");
}
uint32_t counter = 0;
void loop() {
if (X.length() > 0) {
// process the received data from UART0 - example, just print it beside a counter
UART0.print("[");
UART0.print(counter++);
UART0.print("] ");
UART0.println(X);
X = ""; // reset X for the next UART reading.
}
UART0.println("Sleeping for 1 second...");
delay(1000);
}
|
Board
esp32
Device Description
esp32
Hardware Configuration
esp32
Version
latest master
IDE Name
platformio
Operating System
win10
Flash frequency
40
PSRAM enabled
no
Upload speed
9600
Description
i want to use serial hardware interrupt in arduino,but i found the arduino api serialEvent() is not really hardware serial interrupt.so,i fonud some in .platformio\packages\framework-arduinoespressif32\cores\esp32 ,esp32-hal-uart.c and esp32-hal-uart.h
i think this two file can help me. but i dont find any help document about this HAL file.
//example this function
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted);
what uart_nr? what config? what queueLen?i dontknow rev data len. what inverted?
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: