ESP32 and AVR UART TX response rate issue

1337ralfy
Posts: 3
Joined: Wed Mar 02, 2022 11:55 am

ESP32 and AVR UART TX response rate issue

Postby 1337ralfy » Wed Feb 08, 2023 3:43 pm

Hi, I`m having issue with UART communication between AVR and ESP32. Issue is with TX response rate.

Here is what I`m sending with AVR, first 2 bytes are command, last 3 are data:

Code: Select all

//command
Serial2.write(0x01);
Serial2.write(0x62);
//data
Serial2.write(0x69);
Serial2.write(0x70);
Serial2.write(0x71);
  
delayMicroseconds(150);
Here is esp side, I`m using RX interrupt to get data form avr and store it into global variable and resuming task when right data/command comes:

Code: Select all

static void IRAM_ATTR uart_intr_handle(void *arg)
{
    uint16_t i = 0;
    uint16_t rx_fifo_len = 0;
    rx_fifo_len = UART1.status.rxfifo_cnt; // read number of bytes in UART buffer
    
    while(rx_fifo_len){
    rxbuf[i++] = UART1.fifo.rw_byte; // read all bytes

        if(rxbuf[i] == 0x01 && rxbuf[i+1] == 0x62){
            dataBuff[0] = rxbuf[i + 2];
            dataBuff[1] = rxbuf[i + 3];
            dataBuff[2] = rxbuf[i + 4];

            xTaskResumeFromISR(xHandle);
        }

        if(rxbuf[i] == 0x02 && rxbuf[i+1] == 0x63){
            // xTaskResumeFromISR(xHandle2);
        }

        rx_fifo_len--;
    }
    uart_clear_intr_status(EX_UART_NUM, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
}
Here is that task:

Code: Select all

void task(void *arg){
    while(1){
        char writeAddress[6];
        uint16_t tempAddress = dataBuff[1] | (dataBuff[0]<<8);
        uint8_t writeData = dataBuff[2];
        
        sprintf(writeAddress, "%d", tempAddress);
        ESP_LOGE("uart", "Address: %s, %x", writeAddress, writeData);
        
        //not implemented yet, but here will function to store data into esp nvs
        //and after data is stored into nvs, esp will send 0x01 to avr, so it knows that data is stored succesfully 

        uart_write_bytes(EX_UART_NUM, &txDataBuff[1], 1);

        vTaskSuspend(NULL);
    }
}
But issue is that is sends out data every 5 miliseconds, not on every packet:
Image
Here is a closeup of packet:
Image

So I`m assuming that it takes 5ms to uart_write_bytes(), because of delay of resuming that function, or because another task is interrupting this task?

How could i increase TX response rate, so it responds to every packet, no like every ~30th one? :D

Your`e answer will be greatly appreciated :)

Who is online

Users browsing this forum: Bing [Bot] and 64 guests