ESP32 and AVR UART communication issue
Posted: Wed Feb 08, 2023 2:51 pm
Hi, so I`m using UART communication between ESP32 and AVR chip. Having issue with TX response rate.
AVR is sending 5 bytes, first two are command bytes and last 3 are data bytes:
And on the ESP side its using RX interrupt to get and store data into another buffer and xTaskResumeFromISR to do something with recieved data:
This is function where it processes that data:
Data im getting is correct and here is glimpse of ESP_LOGE:
So my issue is that it takes about 5 milliseconds to uart_write_bytes() (so it also means that function takes 5ms to complete?):
This is a closeup of packet:
Trying to send response on every data packed received, but it looks like it just sends every ~30 packet.
I`m assuming that its something to do with how long time it takes to resume task or another task is interrupting this task?
How can i increase response time?
Your`e response will be greatly appreciated
AVR is sending 5 bytes, first two are command bytes and last 3 are data bytes:
Code: Select all
//command
Serial2.write(0x01);
Serial2.write(0x62);
//data
Serial2.write(0x69); //high byte
Serial2.write(0x70); //low byte
Serial2.write(0x71); //data
delayMicroseconds(150);
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);
}
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 is where data will be stored into esp nvs
//and send 0x01 back to AVR so it knows that datas has been stored succesfully
uart_write_bytes(EX_UART_NUM, &txDataBuff[1], 1);
vTaskSuspend(NULL);
}
}
Code: Select all
E (2290198) uart: Address: 26992, 71
E (2290198) uart: Address: 26992, 71
E (2290208) uart: Address: 26992, 71
E (2290208) uart: Address: 26992, 71
E (2290218) uart: Address: 26992, 71
E (2290218) uart: Address: 26992, 71
This is a closeup of packet:
Trying to send response on every data packed received, but it looks like it just sends every ~30 packet.
I`m assuming that its something to do with how long time it takes to resume task or another task is interrupting this task?
How can i increase response time?
Your`e response will be greatly appreciated