Good day!
I want to implement simple exchange protocol between esp32(master) - arduino nano(slave).
I send request message to slave, and after try to read response, but it doesn’t recieve.
a part of example code:
struct mbuf inputBuffer;
void uart_read_recieved_data_cb(int uart_no, void *arg)
{
size_t resp_size = mgos_uart_read_avail(2);
LOG(LL_INFO, ("Response message size: %d", resp_size));
if (resp_size)
{
mgos_uart_read_mbuf(2, &inputBuffer, resp_size);
print_resp_msg();
}
else
{
return;
}
}
void get_data_from_device_cb(void *arg)
{
const char identification_msg[] = { 0x55, 0x01, 0xFE, 0x00, 0x00, 0x00, 0xAB };
mgos_uart_set_dispatcher(2, uart_read_recieved_data_cb, NULL);
mgos_uart_write(2, &identification_msg, sizeof(identefication_msg));
}
enum mgos_app_init_result mgos_app_init(void)
{
struct mgos_uart_config ucfg;
mgos_uart_config_set_defaults(2, &ucfg);
ucfg->baud_rate = 9600;
ucfg->num_data_bits = 8;
ucfg->stop_bits = MGOS_UART_STOP_BITS_1;
ucfg->parity = MGOS_UART_PARITY_NONE;
if (!mgos_uart_configure(2, &ucfg)
{
LOG(LL_ERROR, ("Failed to configure UART%d", 2));
return MGOS_APP_INIT_ERROR;
}
mgos_set_timer(5000, MGOS_TIMER_REPEAT, get_data_from_device_cb, NULL);
return MGOS_APP_INIT_SUCCESS;
}
In debug terminal I can always see a lot of these messages for one request
Response message size: 0
Response message size: 0
Response message size: 0
Response message size: 0
Response message size: 0
…
Why there is no bytes in rx buffer?
Or is there other way to implement write-read functions with uart?
P.S. I can get response message from slave using PC terminal.
P.P.S. I listened to the line master-slave with Advanced Serial Port Monitor - all is ok! I can see request and response