Browse Source

esp32/machine_uart: Change sendbreak time to be at least 15 bit times.

It used to be 10 bit times, which is too short.  The break state must be
longer than a regular character time, at least 13 bit times.  This is now
implemented by reducing the baudrate while sending the "0".  The break time
will now vary with data length and parity setting, but will at least be 15
bit times.

Tested with a GENERIC_SPIRAM, GENERIC_C3 and UM_TINYS2 board.
pull/9089/head
robert-hh 2 years ago
committed by Damien George
parent
commit
13dceaa4ea
  1. 23
      ports/esp32/machine_uart.c

23
ports/esp32/machine_uart.c

@ -399,28 +399,19 @@ STATIC mp_obj_t machine_uart_sendbreak(mp_obj_t self_in) {
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
// Save settings
uart_word_length_t word_length;
uart_parity_t parity;
uart_get_word_length(self->uart_num, &word_length);
uart_get_parity(self->uart_num, &parity);
uint32_t baudrate;
uart_get_baudrate(self->uart_num, &baudrate);
// Synthesise the break condition by either a longer word or using even parity
// Synthesise the break condition by reducing the baud rate,
// and cater for the worst case of 5 data bits, no parity.
uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000));
if (word_length != UART_DATA_8_BITS) {
uart_set_word_length(self->uart_num, UART_DATA_8_BITS);
} else if (parity == UART_PARITY_DISABLE) {
uart_set_parity(self->uart_num, UART_PARITY_EVEN);
} else {
// Cannot synthesise break
mp_raise_OSError(MP_EPERM);
}
uart_set_baudrate(self->uart_num, baudrate * 6 / 15);
char buf[1] = {0};
uart_write_bytes(self->uart_num, buf, 1);
uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000));
// Restore original settings
uart_set_word_length(self->uart_num, word_length);
uart_set_parity(self->uart_num, parity);
// Restore original setting
uart_set_baudrate(self->uart_num, baudrate);
return mp_const_none;
}

Loading…
Cancel
Save