Closed
Description
Related area
UART
Hardware specification
UART
Is your feature request related to a problem?
Currently ( with arduino v3 and idf v5 ) I can register callback functions for onReceive
and onReceiveError
.
When I receive a packet I immidiately want to write the next. It is not possible because the UART
is still busy.
I had to implement a logic to wait for the UART
to become available before I can write.
A cb function would be good if the UART
is available again.
Describe the solution you'd like
// Pass a cb just like in the case of onReceive
Serial1.onAvailable([](){
// UART is avaiable again. Can write the next packet.
});
Describe alternatives you've considered
Before I want to write I call this wrapper function
while( isUartBusy() ){}
This is the implementation
bool Modbus::isUartBusy(){
return uart_wait_tx_done(UART_NUM_1, 0) == ESP_ERR_TIMEOUT;
}
This is not ideal because it freezes the task which wants to write.
Additional context
Here is how I use the UART right now.
void Modbus::init() {
Serial1.begin(MBUS_BAUD, SERIAL_8N1, MBUS_RX, MBUS_TX);
Serial1.setPins(-1, -1, -1, MBUS_RTS);
Serial1.setMode(UART_MODE_RS485_HALF_DUPLEX);
Serial1.setRxTimeout(MBUS_RX_TIMEOUT);
Serial1.onReceive(
std::bind(&Modbus::handlePacket, this),
PACKET_TRIGGER_ONLY_ON_TIMEOUT
);
Serial1.onReceiveError(std::bind(&Modbus::handleReceiveError, this, std::placeholders::_1));
}
I have checked existing list of Feature requests and the Contribution Guide
- I confirm I have checked existing list of Feature requests and Contribution Guide.
Metadata
Metadata
Assignees
Type
Projects
Status
Done