UART parity in driver usart_001.h incorrect

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART parity in driver usart_001.h incorrect

1,219 Views
vivienwong
Contributor I

Hi,

 

    I am currently using the lpc_ip driver usart_001.h and realized that there is an error in the definition of the UART parity bits:    The driver sets it to:

typedef enum IP_UART_PARITY {

    UART_PARITY_NONE = 0,                                    /*!< No parity */

    UART_PARITY_ODD = (4 << 3),                                /*!< Odd parity */

    UART_PARITY_EVEN = (5 << 3),                            /*!< Even parity */

    UART_PARITY_SP_1 = (6 << 3),                            /*!< Forced "1" stick parity */

    UART_PARITY_SP_0 = (7 << 3)                                /*!< Forced "0" stick parity */

} IP_UART_PARITY_T;

However, based on the LPC18xx user manual, I believe this should be set to

typedef enum IP_UART_PARITY {

    UART_PARITY_NONE = 0,                                    /*!< No parity */

    UART_PARITY_ODD = (1 << 3),                                /*!< Odd parity */

    UART_PARITY_EVEN = (3 << 3),                            /*!< Even parity */

    UART_PARITY_SP_1 = (5 << 3),                            /*!< Forced "1" stick parity */

    UART_PARITY_SP_0 = (7 << 3)                                /*!< Forced "0" stick parity */

} IP_UART_PARITY_T;

  I have debug on my board and confirm that this could be an error on the driver.

Labels (1)
0 Kudos
7 Replies

933 Views
vivienwong
Contributor I

Great! Thank you

0 Kudos

933 Views
kerryzhou
NXP TechSupport
NXP TechSupport

If this post answers your question, please click the Correct Answer button. Thank you!

0 Kudos

933 Views
vivienwong
Contributor I

Hi,

  Thank you for confirming that my change is correct.

I got this file from LPCOpen Platform:

LPCOpen Platform: C:/nxp/v1.03/lpcopen_v1.03/lpcopen/software/lpc_core/lpc_ip/usart_001.h Source Fil...

See line 406.

  I didn't write this myself but downloaded from NXP. I inherited this code from a colleague so I'm not exactly sure where he downloaded it but it's definitely not written by him. It was from NXP.

0 Kudos

933 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vivien,

  Thank you for your more information, your lpcopen code is really the older version, it is v1.3, but now, we have v2.xx now, please refer to the newest lpcopen code:

LPCOpen Software for LPC18XX|NXP

  This problem has been fixed in the new version, just as I post it in the floor 2.

Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

933 Views
vivienwong
Contributor I

Hi,

  I agree that your snapshots are correct. I didn't think these were wrong in the first place. The user manual and the #defines are correct. It is the enum definition that is incorrect.

However in that same usart_001.h file, the enum,definition is what i think is incorrect. You can find this lower in the file after the #defines.

typedef enum IP_UART_PARITY {

    UART_PARITY_NONE = 0,                                    /*!< No parity */

    UART_PARITY_ODD = (4 << 3),                                /*!< Odd parity */

    UART_PARITY_EVEN = (5 << 3),                            /*!< Even parity */

    UART_PARITY_SP_1 = (6 << 3),                            /*!< Forced "1" stick parity */

    UART_PARITY_SP_0 = (7 << 3)                                /*!< Forced "0" stick parity */

} IP_UART_PARITY_T;

I don't think this is correct and it should be:

typedef enum IP_UART_PARITY {

    UART_PARITY_NONE = 0,                                    /*!< No parity */

    UART_PARITY_ODD = (1 << 3),                                /*!< Odd parity */

    UART_PARITY_EVEN = (3 << 3),                            /*!< Even parity */

    UART_PARITY_SP_1 = (5 << 3),                            /*!< Forced "1" stick parity */

    UART_PARITY_SP_0 = (7 << 3)                                /*!< Forced "0" stick parity */

} IP_UART_PARITY_T;

0 Kudos

933 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vivien,

      Did you write the usart_001.h by yourself?  I can't find this header file. Did you get this file from the official website?

     odd parity, even parity, forced'1' and forece'0' stick parity are all bit 5:4 in the LCR register, enable disable parity is bit 3..

  Take your post code as an example:

You think incorrect item:

typedef enum IP_UART_PARITY {

    UART_PARITY_NONE = 0,                                    /*!< No parity */

    UART_PARITY_ODD = (4 << 3),                                /*!< Odd parity */

    UART_PARITY_EVEN = (5 << 3),                            /*!< Even parity */

    UART_PARITY_SP_1 = (6 << 3),                            /*!< Forced "1" stick parity */

    UART_PARITY_SP_0 = (7 << 3)                                /*!< Forced "0" stick parity */

} IP_UART_PARITY_T;

UART_PARITY_NONE =0;    bit3 is 0x0, disable parity should be 0

UART_PARITY_ODD = 0x20; bit5,4 is 0X2, but odd parity should be 0x0;  bit3 should be 1, not correct.

UART_PARITY_EVEN=0X28;  bit5,4 is 0X2, but even parity should be 0x1; not correct.

UART_PARITY_SP_1=0X30;  bit5,4 is 0X3, but SP_1 parity should be 0x2;  bit3 should be 1, not correct.

UART_PARITY_SP_0=0X38; bit5,4 is 0X3, but SP_0 parity should be 0x3; correct.

You think correct item:

typedef enum IP_UART_PARITY {

    UART_PARITY_NONE = 0,                                    /*!< No parity */

    UART_PARITY_ODD = (1 << 3),                                /*!< Odd parity */

    UART_PARITY_EVEN = (3 << 3),                            /*!< Even parity */

    UART_PARITY_SP_1 = (5 << 3),                            /*!< Forced "1" stick parity */

    UART_PARITY_SP_0 = (7 << 3)                                /*!< Forced "0" stick parity */

} IP_UART_PARITY_T;

  

UART_PARITY_NONE =0;    bit3 is 0x0, disable parity should be 0; correct.

UART_PARITY_ODD = 0x08; bit5,4 is 0X0,  odd parity should be 0x0; correct.

UART_PARITY_EVEN=0X18;  bit5,4 is 0X1, even parity should be 0x1; correct.

UART_PARITY_SP_1=0X28;  bit5,4 is 0X2, SP_1 parity should be 0x2; correct.

UART_PARITY_SP_0=0X38;  bit5,4 is 0X3, SP_0 parity should be 0x3; correct.

so, after the analysis, your modified enum IP_UART_PARITY is correct.

  


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

933 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vivien,

  Please tell us where you get  usart_001.h?

  I have check the lpcopen for LPC1857 from this link:

LPCOpen Software for LPC18XX|NXP

  The partity is defined like this:

82.jpg

And from the datasheet, we can get that:

83.jpg

  So, the lpcopen driver uart parity definition is correct, you can refer to our lpcopen driver.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos