Skip to content

About serial port verification format #118

@4061N

Description

@4061N

Arduino 8E1 format is 8 bits of data, one even check, one stop, a total of 10 bits of data.

The traditional CH32 and STM32 are 7-bit data one-bit check, so there is one less.
To solve this problem, the databits needs to be incremented by one when there is a check bit.

For example, this is the code for HardwareSerial::begin in the stm32duino project:
`void HardwareSerial::begin(unsigned long baud, byte config)
{
uint32_t databits = 0;
uint32_t stopbits = 0;
uint32_t parity = 0;

_baud = baud;
_config = config;

// Manage databits
switch (config & 0x07) {
case 0x02:
databits = 6;
break;
case 0x04:
databits = 7;
break;
case 0x06:
databits = 8;
break;
default:
databits = 0;
break;
}

if ((config & 0x30) == 0x30) {
parity = UART_PARITY_ODD;
databits++;
} else if ((config & 0x20) == 0x20) {
parity = UART_PARITY_EVEN;
databits++;
} else {
parity = UART_PARITY_NONE;
}

if ((config & 0x08) == 0x08) {
stopbits = UART_STOPBITS_2;
} else {
stopbits = UART_STOPBITS_1;
}

switch (databits) {
#ifdef UART_WORDLENGTH_7B
case 7:
databits = UART_WORDLENGTH_7B;
break;
#endif
case 8:
databits = UART_WORDLENGTH_8B;
break;
case 9:
databits = UART_WORDLENGTH_9B;
break;
default:
case 0:
Error_Handler();
break;
}

uart_init(&_serial, (uint32_t)baud, databits, parity, stopbits);
enableHalfDuplexRx();
uart_attach_rx_callback(&_serial, _rx_complete_irq);
}`

It can be see that the databits is incremented when there are check bits. I think this part of CH32 also needs to be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions