Read the UART0_D

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

Read the UART0_D

1,173 Views
piergiusepperan
Contributor II

Hi, I'm trying to use the UART0 of the kl25z board. I use the KDS software, I set the interrupt, I send a integer from my computer, and the OnRxChar events start, so a correct character is received and I can see each bit by using the oscilloscope. My problem is that I want to read the recived data, so inside the OnRxChar events i wrote : if (UART0_D = '1'){do something}, but it never goes inside this "if", for any kind of values.I use the EmbSys Registers to control the register and for example I can see the content of the other register like  UART0_C2 UART0_S2 etc, but UARTO_D remain always equal to zero. What can be the problem in your opinion?

Labels (2)
0 Kudos
8 Replies

844 Views
piergiusepperan
Contributor II

I don't know, I think that the first read operation is in the following part of the code;

PE_ISR(ASerialLdd1_Interrupt)

{

  /* {Default RTOS Adapter} ISR parameter is passed through the global variable */

  ASerialLdd1_TDeviceDataPtr DeviceDataPrv = INT_UART0__DEFAULT_RTOS_ISRPARAM;

  register uint32_t StatReg = UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR); /* Read status register */

  register uint16_t OnErrorFlags = 0U; /* Temporary variable for flags */

  register uint8_t  OnBreakFlag = 0U;  /* Temporary variable flag for OnBreak event */

  register uint16_t Data;              /* Temporary variable for data */

  if (StatReg & (UART0_S1_NF_MASK | UART0_S1_OR_MASK | UART0_S1_FE_MASK | UART0_S1_PF_MASK)) { /* Is any error flag set? */

    UART0_PDD_ClearInterruptFlags(UART0_BASE_PTR, (UART0_S1_NF_MASK | UART0_S1_OR_MASK | UART0_S1_FE_MASK | UART0_S1_PF_MASK));

    Data = (uint16_t)UART0_PDD_GetChar8(UART0_BASE_PTR); /* Read an 8-bit character from receiver */

    if ((StatReg & UART0_S1_FE_MASK) != 0U) { /* Is the framing error detected? */

      if (((StatReg & UART0_S1_RDRF_MASK) != 0U) && (Data == 0U)) { /* Is the zero character in the receiver? */

        OnBreakFlag++;

        DeviceDataPrv->SerFlag |= BREAK_DETECTED; /* If yes then set the flag */

      } else {

        OnErrorFlags |= LDD_SERIAL_FRAMING_ERROR; /* If yes then set the flag */

      }

    }

    if ((StatReg & UART0_S1_OR_MASK) != 0U) { /* Is the overrun error flag set? */

      OnErrorFlags |= LDD_SERIAL_RX_OVERRUN; /* If yes then set the flag */

    }

    if ((StatReg & UART0_S1_PF_MASK) != 0U) { /* Is the parity error flag set? */

      OnErrorFlags |= LDD_SERIAL_PARITY_ERROR; /* If yes then set the flag */

    }

    if ((StatReg & UART0_S1_NF_MASK) != 0U) { /* Is the noise error flag set? */

      OnErrorFlags |= LDD_SERIAL_NOISE_ERROR; /* If yes then set the flag */

    }

    DeviceDataPrv->ErrFlag |= OnErrorFlags; /* Copy flags status to ErrFlag status variable */

    StatReg &= (uint32_t)(~(uint32_t)UART0_S1_RDRF_MASK); /* Clear the receive data flag to discard the errorneous data */

    if (OnBreakFlag != 0U) {

      ASerialLdd1_OnBreak(DeviceDataPrv->UserDataPtr); /* If yes then invoke user event */

    } else {

      ASerialLdd1_OnError(DeviceDataPrv->UserDataPtr); /* Invoke user event */

    }

  }

  if (StatReg & UART0_S1_RDRF_MASK) {  /* Is the receiver's interrupt flag set? */

    InterruptRx(DeviceDataPrv);        /* If yes, then invoke the internal service routine. This routine is inlined. */

  }

  if (DeviceDataPrv->SerFlag & ENABLED_TX_INT) { /* Is the transmitter interrupt enabled? */

    if (StatReg & UART0_S1_TDRE_MASK) { /* Is the transmitter empty? */

      InterruptTx(DeviceDataPrv);      /* If yes, then invoke the internal service routine. This routine is inlined. */

    }

  }

}

Do you think that it is correct? how can I read the uart0_d register?

0 Kudos

844 Views
mjbcswitzerland
Specialist V

Hi

It looks like

Data = (uint16_t)UART0_PDD_GetChar8(UART0_BASE_PTR); /* Read an 8-bit character from receiver */

reads the data so there is no use in reading the data register again since the reception bytes has already been removed.

Your function needs to use Data, where the value is still present.

Regards

Mark

0 Kudos

844 Views
piergiusepperan
Contributor II

Ok, i put this code just below the Data=(uint16_t).... etc :

extern int16_t uart0_value;

  uart0_value=Data;

Now it works but the problem is that sometimes this part of code disappear and I have to write the code again.At the beginning of the code (automatically generated) there is this write: It is used by Processor Expert only; Do you know how to avoid the removal of the code: extern int16_t  etc?

0 Kudos

844 Views
dave408
Senior Contributor II

Hi piergiusepperanieri​, you just have to disable code generation for that particular component.  See below:

pastedImage_0.png

0 Kudos

844 Views
mjbcswitzerland
Specialist V

HI

Sorry, I can't help with PE.

If you need to use it to generate basic code you will need to learn how to control it and live with any side-effects.

Regards

Mark

0 Kudos

844 Views
piergiusepperan
Contributor II

This is the code in events.c that i use:

void AS1_OnRxChar(void)

{

  extern int c;

  if(UART0_D==49){

  c=c+1;

  }

I think that the i read only one time, o not?

0 Kudos

844 Views
mjbcswitzerland
Specialist V

Hi

It is only read once here but has it already been read in the routine calling AS1_OnRxChar() ?

Regards

Mark

0 Kudos

844 Views
mjbcswitzerland
Specialist V

Hi

How many times do you read UART0_D in the handing routine?

Remember that this is a buffer/FIFO and each read empties one byte. If you read it more than once it may have no more data in it and always read 0.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html

KL25: http://www.utasker.com/kinetis/FRDM-KL25Z.html / http://www.utasker.com/kinetis/TWR-KL25Z48M.html

For the complete "out-of-the-box" Kinetis experience and faster time to market

:smileyinfo: Out-of-the-box support for 46 Kinetis boards and 10 IDEs (460 combinations from a single code source with no porting required)

0 Kudos