Hello,
I am new to Arduino, so I have a few questions. I have this loop in my main program and want to move it to an interrupt based routine:
while (Serial1.available()) {
Serial.print(char(Serial1.read()));
};
It echoes the received data to the default uart0.
So I made a class in a header file with these routines:
#define WH24P_UART_NUM UART_NUM_1
#define Weather_RXD 37
#define Weather_TXD 38
#define Weather_Baudrate 9600
const int TX_uart_buffer_size = 30;
const int RX_uart_buffer_size = 512;
const uart_config_t uart_config = {
.baud_rate = Weather_Baudrate,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
void InitWH24P ()
{
ESP_ERROR_CHECK(uart_param_config(WH24P_UART_NUM, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(WH24P_UART_NUM, Weather_TXD, Weather_RXD, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_driver_install(WH24P_UART_NUM, TX_uart_buffer_size * 2, RX_uart_buffer_size * 2, 0, NULL, 0));
ESP_ERROR_CHECK(uart_isr_free(WH24P_UART_NUM));
ESP_ERROR_CHECK(uart_isr_register(WH24P_UART_NUM,SerialEvent1, NULL, ESP_INTR_FLAG_IRAM, NULL));
ESP_ERROR_CHECK(uart_enable_rx_intr(WH24P_UART_NUM));
}
//static void IRAM_ATTR SerialEvent1(void *arg){ // doesn't work
static void SerialEvent1(void *arg){ // UART RX event
while (Serial1.available()) {
Serial.print(char(Serial1.read()));
};
uart_clear_intr_status(WH24P_UART_NUM, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
}
Why can I not use IRAM_ATTR? The code compiles without IRAM_ATTR. I get these errors with IRAM_ATTR : .iram1[WH24P::SerialEvent1(void*)]+0x3): dangerous relocation: l32r: literal placed after use:...
I saw that it had something to do with -mlongcalls. How can I check and change the compiler options? Please keep it stupid simple. Something like go to path c:\blabla and edit file file.ext. That would help.
I am using an ESP32 by the way.
Another question. The interrupt routine only constantly produces garbage on uart0. why is that? The routine was working well in my main program (echo data on uart0). Data is only received once every 16 seconds (21 bytes@9600Baud from the RS485 transceiver every 16 seconds).
I hope someone can help me. Thank you.
Best regards,
Mark