how to set EVEN-7BIT-1 STOP BIT SETTING FOR FRDMK64

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

how to set EVEN-7BIT-1 STOP BIT SETTING FOR FRDMK64

Jump to solution
2,612 Views
sudhakarp
Contributor V

HI,

     I am using FRDMK64f120 controller, KDS2.0 and KSDK 1.1.0 example am using. i tried to set

following setting in hello example project but its not working. how to solve this problem.

 

E-Even parity,     7,8-bit      1,2-stop bit

1)E71

2)E82

3)O71

4)N82

 

its working fine with NOne ,8bit and 1 stop bit. but i need above setting how to solve this problem.

please give some idea.

 

regards,

sudhakar p

Labels (1)
0 Kudos
Reply
1 Solution
1,835 Views
isaacavila
NXP Employee
NXP Employee

Hello Sudhakar,

First of all, you should understand data format in UART module, lets suppose LSB is sent first.

If you select 8-bit data format and enable parity bit, 7 are reserved for data and the one (MSB) is reserved for parity (either odd or even) as shown below:

Data Format E81.jpgInternal hardware checks parity bit according to parity mode selected (even or odd) and it sets/clears the flag if there is a parity error on received character, so, if you are using this mode, you should read 8 bits and then mask the 8th bit to discard parity bit (hardware already checks for parity error):

uint8_t received_data, parity, real_data;

UART_HAL_Getchar(base, &received_data);

real_data = received_data & 0x7F;

parity = (received_data & 0x80) >> 7;

When you try to use 8 data bits and add an aditional parity bit, you should enable 9 bit transmission (8 data + 1 parity) and data format is:

Data Format E91.jpg

In this case, we need to read 9 bits (8 bits are read in UARTx_D register and MSB bit is read in UARTx_C3[R8] flag),so, it is neccesary to read C3 before reading D register. Again, internal hardware checks for parity bit and sets/clears correspoding flag if there is a parity error. For KSDK 1.2.0 drivers, there is a function that allows user to read/write 9 bits:

UART_HAL_Getchar9(base, &data_16_bits);

Current UART driver in KSDK does use 8 bit data format with no parity, so, you should consider masking the MSB bit if parity is enabled.

Attach you can find a basic project using UART_HAL functions that KSDK provides in order to read 8 or 9 bits. I check both versions and it works well (even though i had problems on 8 bit format because Putty does not uses 7 data + 1 parity bit but if you apply this technique when communicating two boards you will see that communication is stablished correctly.)

I hope this can serve as guidance in order to create your own driver.

Note: For Stop bits, it should be no problem when chaning from 1 to 2, due these bits are internally managed.

Best Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------------------------

View solution in original post

5 Replies
1,836 Views
isaacavila
NXP Employee
NXP Employee

Hello Sudhakar,

First of all, you should understand data format in UART module, lets suppose LSB is sent first.

If you select 8-bit data format and enable parity bit, 7 are reserved for data and the one (MSB) is reserved for parity (either odd or even) as shown below:

Data Format E81.jpgInternal hardware checks parity bit according to parity mode selected (even or odd) and it sets/clears the flag if there is a parity error on received character, so, if you are using this mode, you should read 8 bits and then mask the 8th bit to discard parity bit (hardware already checks for parity error):

uint8_t received_data, parity, real_data;

UART_HAL_Getchar(base, &received_data);

real_data = received_data & 0x7F;

parity = (received_data & 0x80) >> 7;

When you try to use 8 data bits and add an aditional parity bit, you should enable 9 bit transmission (8 data + 1 parity) and data format is:

Data Format E91.jpg

In this case, we need to read 9 bits (8 bits are read in UARTx_D register and MSB bit is read in UARTx_C3[R8] flag),so, it is neccesary to read C3 before reading D register. Again, internal hardware checks for parity bit and sets/clears correspoding flag if there is a parity error. For KSDK 1.2.0 drivers, there is a function that allows user to read/write 9 bits:

UART_HAL_Getchar9(base, &data_16_bits);

Current UART driver in KSDK does use 8 bit data format with no parity, so, you should consider masking the MSB bit if parity is enabled.

Attach you can find a basic project using UART_HAL functions that KSDK provides in order to read 8 or 9 bits. I check both versions and it works well (even though i had problems on 8 bit format because Putty does not uses 7 data + 1 parity bit but if you apply this technique when communicating two boards you will see that communication is stablished correctly.)

I hope this can serve as guidance in order to create your own driver.

Note: For Stop bits, it should be no problem when chaning from 1 to 2, due these bits are internally managed.

Best Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------------------------

1,835 Views
sudhakarp
Contributor V

hi,

thank you. i got it.everything i tried with  UART-0 virtual USB port that's why am not getting correct result.

thank you very much.

regards,

sudhakar p

0 Kudos
Reply
1,835 Views
sudhakarp
Contributor V

hi,

i tried  UART1 port with 2stop bit its working fine for none parity. i think for UART-0 i used virtual USB port that's why am not getting correct result. i put MAX232 for UART-1 and tried its ok. but still i have  problem with 7E1.

when i type one by one character its displaying correctly but i transfer some 1kb file through hyperterminal or tereterm its outing junk value why.? and also am using "UART_DRV_InstallRxCallback" interrupt function to receive UART data. is any problem..?

regards,

sudhakar p

0 Kudos
Reply
1,835 Views
sudhakarp
Contributor V

hi,

if i configure 9bit for(7E1 and 8E1) without junk i can able to receive.But i sent large data 1k am getting junk value. 2-stop bit condition was not working at all.

without parity also 2-stop bit not working why?

regards,

sudhakar p

0 Kudos
Reply
1,835 Views
sudhakarp
Contributor V

hi,

     still i have same problem.

actually i configured like this for 7E1-(7bit ,even,one stop bit)

uart_user_config_t uartConfig = {

        .bitCountPerChar = kUart8BitsPerChar,

        .parityMode      = kUartParityEven,

        .stopBitCount    = kUartOneStopBit,

        .baudRate        = BOARD_DEBUG_UART_BAUD

    };

its only displaying some character correctly. some character am getting junk value [example:"C"]. why?

and also you told Stop bit not depends on number of bits per char. i tried 8N2 this one also not working.

can you give some other solution for 7bit data transfer with parity..?

and also i need all combination

1)E71

2)E82

3)O71

4)N82

regards,

sudhakar p

0 Kudos
Reply