Issue while receiving data into "UART2_D "register

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

Issue while receiving data into "UART2_D "register

863 Views
priyankavorugan
Contributor II

Hi,

I am using MKL17z series microcontroller in my project.I am using UART2 for serial receive and transmit.
I am using seperate ISR for transmit and receive.I am able to generate the interrupt for transmit and receive.

But my problem is i can transmit the data and can check that in one of my utility and can see that in uart2_d reg.

But i am unable to receive the data sent by the utility and i cant even see that data in uart2_d reg.

uart2_d register is used fo both transmission and reception??

0 Kudos
Reply
4 Replies

665 Views
mjbcswitzerland
Specialist V

Hi

The data register is WRITE for transmission and READ for reception. This means that you will never be able to see the value that you write to it by reading it back.

Regards

Mark

http://www.utasker.com/kinetis.html for quality Kinetis firmware

0 Kudos
Reply

665 Views
priyankavorugan
Contributor II

Hi,

I have taken a local vaiable and I try to read the UART2_D  register value into that  variable( rx_buffer = UART2_D).
but the i cant see any value in that variable.

So,can I read the data from UAT2_D reg??

What i have noticed is,suppose if i Transmit 10 ,i can read back the same value i.e 10.But i cant read the value that i sent using utility.

I have implemented as shown below.

void UART2_handler(void) 
{

     if ((UART2_S1&UART_S1_TDRE_MASK))     //transmit buffer is empty,write D reg.
    {
          if((UART2_S1&UART_S1_TC_MASK))
         {
            BT_MANAGER_Tx_ISR();
         }
   }

   if((UART2_S1 & UART_S1_RDRF_MASK))       //Receive buffer is full,read D reg.
   {
      BT_MANAGER_Rx_ISR();
   }

}

0 Kudos
Reply

665 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Have you try to disable the UART2_C2[TIE] and UART2_C2[TCIE] and then read the data from UAT2_D reg?

void UART2_handler(void) 
{

   if((UART2_S1 & UART_S1_RDRF_MASK))       //Receive buffer is full,read D reg.
   {
      rx_buffer = UART2_D;
   }

}

And make sure you are not using '38.5.6 Loop operation' mode.

38.5.6 Loop operation.png

I test the uart interrupt demo in SDK_2.2_FRDM-KL27Z with FRDM-KL27Z board. (...SDK_2.2_FRDM-KL27Z\boards\frdmkl27z\driver_examples\uart\interrupt)

SDK_2.2_FRDM-KL27Z_uart.png

I can read the data from UAT2_D reg after I send data using UART Terminal port.

UART_ReadByte.png

You can download and test that demo in SDK_2.2_MKL17Z.

KL17 KSDK.png

Best Regards,

Robin

 

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

0 Kudos
Reply

665 Views
mjbcswitzerland
Specialist V

Hi

When you read the data register you read the last received data value. This "may" be equal to the last transmitted value in case the rx 'sees' the tx line.

To get past this stage I recommend letting the code configure the UART then pausing the debugger. Now display the UART registers in the debugger's IDE and experiment with writing values to the data register. If the UART is operating correctly you will see these being sent to the TXD line. You can then monitor what happens with the value read from the data register and also experiment with ready after there has been a real character reception. This will allow you to understand the behavior and also verify the HW. Once you have understood the operation you can then adapt the code accordingly.

Regards

Mark

0 Kudos
Reply