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);
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 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);
}
}
![Image](https://i.postimg.cc/gXDHxZxX/20230208-163451.jpg)
Here is a closeup of packet:
![Image](https://i.postimg.cc/qg1G02fW/20230208-163457.jpg)
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?
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Your`e answer will be greatly appreciated
![Smile :)](./images/smilies/icon_e_smile.gif)