K64 UART Receiver Active Flag "RAF"

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

K64 UART Receiver Active Flag "RAF"

1,420 Views
Designer11
Contributor IV

Hi,

I'm new to the Kinetis K64 series of microcontrollers. I would like to detect whether the UART receiver line is idle or active. I'm currently using Processor Expert  AS1_ReceiveBlock(), UART1 to receive incoming serial data and it works great. I know that UART1_S2 is the status register i need to work with.  But how do i access the RAF field ?

Thanks,

Labels (1)
0 Kudos
Reply
7 Replies

1,057 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Designer11,

    From the register description:

pastedImage_1.png

You can get that the RAF bit is read only.

If you want to access this bit, just read UART1_S2[RAF] bit in the code is OK.

You can use code:

UART1_S2 & UART_S2_RAF_MASK

 If this result is 0x0, it means the RAF bit is 0:UART receiver idle/inactive waiting for a start bit..

 If the result is 0x01, it means the RAF bit is 1:UART receiver active, RxD input not idle.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

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

0 Kudos
Reply

1,057 Views
Designer11
Contributor IV

Hi Kerry,

Thanks for your help. However, whenever the interrupt happened it called PE_DEBUGHALT(); function 

Below is the example code. What is going on ?

if (UART1_S2 & UART_S2_RAF_MASK){
   i = 1;
}

Thanks,

0 Kudos
Reply

1,057 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Degisner11,

    When the interrupt happened, it called PE_DEBUGHALT().

   Did you add the interrupt ISR function?

   If you didn't add the interrupt service function, when the interrupt happens, the mcu can't find the according function, it will cause the problem.

  I don't know how you configure it.

  If you are convenient, could you give me your test project, then I can help you to check it.


Have a great day,

Kerry

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

0 Kudos
Reply

1,057 Views
Designer11
Contributor IV

Hi Kerry,

Since I don't have much experience with the Kinetis 32 bit. Could you give me an example on how to configure the interrupt ISR function for the RAF? I have dealt with the RAF flag in the 8bit HCS08 family of microcontrollers in the past. 

Thanks,

0 Kudos
Reply

1,057 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Designer11,

   Do you just want to get the receive idle interrupt?

   If yes, you don't need to use RAF to get the interrupt, because RAF is just the state flag, it doesn't have the interrupt.

  You should enable the idle line request in UARTx_C2[ILIE].

   About the example, I help you use the KDS PE generate a K64 project, and test it on my side, it works ok on my FRDM-K64 board, you can refer to it.

  The code function is, when the receive idle interrupt happens, it will clear the idle flag, and receive the UART data, then send the received data back.

  The configuration is like this:

pastedImage_1.png

pastedImage_2.png

The main code like this:

unsigned char data, flag=0;
PE_ISR(UART_ISR)
{
  if(UART0_S1 & UART_S1_IDLE_MASK)
  {
      data= UART0_D;
        flag=1;
  }
}

void send_data(char ch)
{
    while(!(UART0_S1 & UART_S1_TDRE_MASK));
    UART0_D= ch;

}

int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  send_data(0x55);
  for(;;) {

      if(flag==1)
      {
          flag=0;
          send_data(data);

     }
  }
 } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

More details, please check my attached project.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

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

0 Kudos
Reply

1,057 Views
Designer11
Contributor IV

Hi Kerry,

Thanks for your help. I don't think i want  interrupt for the moment. All i want is something like the below pseudo code

if (UART0 RAF Flag ==  IDLE) {    //check the RAF flag

     Do something

}else {

   Do another task

}

thanks.

0 Kudos
Reply

1,057 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Designer 11,

  If you don't want to use the interrupt, it is very simple, you just can use the code which you are mentioned.

      if(UART0_S1 & UART_S1_IDLE_MASK)
  But go to your initial question:I would like to detect whether the UART receiver line is idle or active. 

 If you just want to detect the receiver line, you can use UARTx_S1[IDLE], then when you want to send one byte, the code write like this:

      while(!(UART0_S1 & UART_S1_IDLE_MASK));
      data= UART0_D;

  You can refer to my attached code

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos
Reply