Uart stop bits in NXP K22 series

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

Uart stop bits in NXP K22 series

1,200 Views
prasannanaik
Contributor III

Hi,

      While going through user manual of K22F series, we found that only 1 stop bit(Fixed) is available in UART.

      I need user configurable stop bits (1 or 2) in my application(Modbus over RS485).

      How to get this Uart working with systems with 2 stop bits?

 

      Controller used: MK22FX512AVLQ12 (No LPUART in this microcontroller)

 

Thanks and best regards,

Prasanna

Labels (1)
Tags (1)
0 Kudos
7 Replies

927 Views
mjbcswitzerland
Specialist V

Hi

Your processor's UART doesn't support 2 stop bits as a UART setting but you can still use 2 stop bit if you work in interrupt driven mode and use the transmission complete interrupt instead of the buffer empty interrupt to control each byte sent (reception is not critical because it will accept either 1 or 2 stop bits).

If you require a complete and immediate solution for your device see the uTasker project since it contains a turn key Modbus solution with Modbus master and slave in ASCII or RTU modes on all K22 UARTs (and RS485 mode), as well on USB-CDC connections (up to 6), or Modbus TCP master/slaves on USB-RNDS (host or device). 

http://www.utasker.com/docs/MODBUS/uTasker_MODBUS.PDF
[proven on Kinetis since 2011 in many industrial products]

Regards

Mark

Complete Kinetis solutions for professional needs, training and support: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html

uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market

Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html

Open Source version at https://github.com/uTasker/uTasker-Kinetis

0 Kudos

927 Views
prasannanaik
Contributor III

Hmjbcswitzerland ,

  Thanks for your valuable input.

   I was trying to implement the same but faced certain issues while doing so.

   I am using non blocking transfer method to send data through uart.

 

API's used in code: 

1) status_t UART_TransferReceiveNonBlocking(UART_Type *base,uart_handle_t *handle,uart_transfer_t *xfer,size_t *receivedBytes)

2) void UART_TransferCreateHandle(UART_Type *base,uart_handle_t *handle,uart_transfer_callback_t callback,void *userData)

3) status_t UART_TransferSendNonBlocking(UART_Type *base, uart_handle_t *handle, uart_transfer_t *xfer)

 

I modified following snippets in firmware in "fsl_uart.c" file:

1) status_t UART_Init(UART_Type *base, const uart_config_t *config, uint32_t srcClock_Hz)   :

         Replaced ==> base->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);

         With ==> base->C2 &= ~(UART_C2_TCIE_MASK | UART_C2_RE_MASK);

 

         Replaced ==> if (config->enableTx)
                                 {
                                       temp |= UART_C2_TE_MASK;

                                  }

         With ==> if (config->enableTx)
                         {
                                 temp |= UART_C2_TCIE_MASK;
                          }

 

2) status_t UART_TransferSendNonBlocking(UART_Type *base, uart_handle_t *handle,uart_transfer_t *xfer)

 

Replaced ==> UART_EnableInterrupts(base, kUART_TxDataRegEmptyInterruptEnable);

              With ==> UART_EnableInterrupts(base, kUART_TransmissionCompleteInterruptEnable);

When i started debugging the firmware the controller stopped all of a sudden and now it is giving constant reset even if i try to debug any demo code.

Can you please help in resolving this issue.

Also, there is a guard time setting in K22 uart, will this setting help in acheiving the desired second stop bit delay?

Thanks and best regards,

Prasanna

 

 

0 Kudos

927 Views
mjbcswitzerland
Specialist V

Hi

The K22 guard time support is used only in ISO 7816 mode for its smart card interface.

Use the uTasker open source project as reference (it has a UART driver that support 2 stop bits on your chip and also allows its operation to be simulated in Visual Studio to make it easier to analyse the operation). Then you can make changes to your library routines to suit - also don't forget to correctly clear the interrupt if that is the reason for your code hanging.

If you are developing professionally and prefer a complete out-of-the-box solution for your K22 Modbus project show the uTasker links to your employer or your client since it would allow you to complete the work in a few hours and possibly them to save project development costs in comparison to redeveloping from scratch.

Regards

Mark

0 Kudos

926 Views
prasannanaik
Contributor III

Hi Mark,

   I couldn't find the source code of Modbus from "http://www.utasker.com/kinetis/FRDM-K22F.html". Can you please send me the link of source code or the downloaded source code.

Thanks and best regards,

Prasanna

0 Kudos

926 Views
mjbcswitzerland
Specialist V

Hi

Modbus source code is not included in the open source version of the project but the UART drivers are - you can copy the UART solution for use with your Modbus stack if need.

Modbus is reserved for commercial users, who have helped finance its development.
See http://www.utasker.com/Licensing/request.html if you would like to evaluate the commercial version.
If your company can't afford software there is also a service to help with a single-project complementary license (see the options)

regards

Mark

0 Kudos

927 Views
prasannanaik
Contributor III

Hi mjbcswitzerland ,

   I have modifed the interrupt suggested by you and it is working fine but i am not able to understand the logic behind this.

How does this interrupt help in achieving two stop bits?

Because we are not changing the frame format so where does that additional delay of second stop bit comes?

Thanks & best regards,

Prasanna 

0 Kudos

927 Views
mjbcswitzerland
Specialist V

Hi

The UART's tx time base is controlled by its baud rate. If you 'queue' a following Tx data byte it means that it will be sent after the stop bit (one stop bit). However, if there is no second Tx data in the output buffer at this point the UART Tx sends idle line. If a further Tx data byte is added to the output buffer during the first clock period of the idle line it results in it being sent out 'at the next possible occasion', which is one baud clock later - resulting in 1 stop bit, 1 idle line bit and then the start bit of the following byte. The inserted idle line period is the same as a second stop bit.

This works in interrupt-driven tx mode but not in DMA mode since DMA loads the next byte too early.

Regards

Mark

[uTasker project developer for Kinetis and i.MX RT]

0 Kudos