ESP8266 Developer Zone The Official ESP8266 Forum 2015-01-12T11:07:59+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=131 2015-01-12T11:07:59+08:00 2015-01-12T11:07:59+08:00 https://bbs.espressif.com:443/viewtopic.php?t=131&p=478#p478 <![CDATA[Re: driver/uart.h: error in definition of parity and stop bi]]>
I just post some driver of uart , pleace download and update.
Use the api to config the uart registers.
RTOS version driver is more recommended.


--> viewtopic.php?f=7&t=48&p=173#p173

Statistics: Posted by costaud — Mon Jan 12, 2015 11:07 am


]]>
2015-01-11T18:11:36+08:00 2015-01-11T18:11:36+08:00 https://bbs.espressif.com:443/viewtopic.php?t=131&p=475#p475 <![CDATA[driver/uart.h: error in definition of parity and stop bits ?]]> the default configuration of the UART is 8N1: 8 data bits, no parity , one stop bit.
I need to change this settings, i.e. 7E2.
In "driver/uart.h" there are some definitions to do that:

Code:

typedef enum {
    FIVE_BITS = 0x0,
    SIX_BITS = 0x1,
    SEVEN_BITS = 0x2,
    EIGHT_BITS = 0x3
} UartBitsNum4Char;

typedef enum {
    ONE_STOP_BIT             = 0,
    ONE_HALF_STOP_BIT        = BIT2, //0x00000004
    TWO_STOP_BIT             = BIT2
} UartStopBitsNum;

typedef enum {
    NONE_BITS = 0,
    ODD_BITS   = 0,
    EVEN_BITS = BIT4 //0x00000010
} UartParityMode;

typedef enum {
   STICK_PARITY_DIS = 0,
   STICK_PARITY_EN = BIT3 | BIT5 // 0x00000008| 0x00000020
} UartExistParity;

In uart_config(uint8 uart_no), defined in "driver/uart.c", this enum are used to set the UART register.
Here I added the typecasts to show the enum typedefs.

Code:

WRITE_PERI_REG(UART_CONF0(uart_no), (UartExistParity) UartDev.exist_parity
                 | (UartParityMode) UartDev.parity
                 | ((UartStopBitsNum)UartDev.stop_bits << UART_STOP_BIT_NUM_S)
                 | ((UartBitsNum4Char)UartDev.data_bits << UART_BIT_NUM_S));

with

Code:

#define UART_CONF0( i )                         (REG_UART_BASE( i ) + 0x20)
#define REG_UART_BASE( i )  (0x60000000+(i)*0xf00)
#define UART_STOP_BIT_NUM_S 4
#define UART_BIT_NUM_S 2

this definition conflict at bit 3:
UartDev.data_bits << 2 => the bits of UartBitsNum4Char are now in bit 2+3
UartDev.exist_parity => STICK_PARITY_EN = BIT3 | BIT5

I found in this forum Uart_reg_release_141118.xls with the register definition:

UART_CONF0 UART_CONF0
...
stop_bit_num [5:4] 2'd1 R/W Set stop bit: 1:1bit 2:1.5bits 3:2bits
bit_num [3:2] 2'd3 R/W Set bit num: 0:5bits 1:6bits 2:7bits 3:8bits
parity_en [1] 1'b0 R/W Set this bit to enable uart parity check
parity [0] 1'b0 R/W Set parity check: 0:even 1:odd

If this definition are correct, so the above typedefs in "driver/uart.h" must be:

Code:

 typedef enum {
   STICK_PARITY_DIS = 0,  // No parity
   STICK_PARITY_EN = BIT1
} UartExistParity;

typedef enum {
   ODD_BITS = BIT0,
   EVEN_BITS = 0
} UartParityMode;

typedef enum {
   ONE_STOP_BIT = 1,
   ONE_HALF_STOP_BIT = 2,
   TWO_STOP_BIT = 3
} UartStopBitsNum;

Then the function call in uart_config(uint8 uart_no)

Code:

WRITE_PERI_REG(UART_CONF0(uart_no), UartDev.exist_parity
                 | UartDev.parity
                 | (UartDev.stop_bits << UART_STOP_BIT_NUM_S)
                 | (UartDev.data_bits << UART_BIT_NUM_S));

correspond with Uart_reg_release_141118.xls

uart.c contain
// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;

The initialized value from rom code of (UartStopBitsNum) UartDev.stop_bits is 0.
But this value is not in the register documentation:
stop_bit_num [5:4] 2'd1 R/W Set stop bit: 1:1bit 2:1.5bits 3:2bits
So it should set to ONE_STOP_BIT = 1.
What happen if the register bits stop_bit_num are set to 0?

Peter

Statistics: Posted by Peter — Sun Jan 11, 2015 6:11 pm


]]>