AnsweredAssumed Answered

K64F UART Status Register TDRE bit

Question asked by yibin wang on May 3, 2016
Latest reply on May 5, 2016 by Jorge Antonio Alcala Vazquez

Dear all,

I have issue on the K64F UART data sending. Now, I use the request mode to code my data sending without interrupt so I also need to check the S1 TDRE bit to understand if the current data is sent out when in the next new data sending.

Please see my UART sending code.

void SendSer0Char(unsigned char Char){
/* Wait for transmitter to empty, load char into TDRE */
//while(!(SSR0 & TDREbit));
//TDR0 = Char;
//SSR0 &= ~TDREbit;
UART1_S1 &= ~(0x80);
while((UART1_S1 & 0x80) != 0x80); // TDRE
UART1_D = Char;

}

 

But, there is the issue on the UART1_S1 TDRE checking. I got the two differences value on TDRE bit when I used same code working on a batch boards.

On the some boards, the TDRE can be reset automatically before the next new data sending. But the another boards, the TDRE always keeps Zero status after the first data sent so the code stay in the loop without any sending for the following datas . I don't what reason was on the UART sending code.

I also attached the UART initialization code in here. Please have a look.

 

void UART1_Init(void) {

  UART1_C2 &= ~UART1_C2_MASK_1;  // #define UART1_C2_MASK_1      0x0CU

 

  UART1_BDH = UART1_BDH_VALUE;  // #define UART1_BDH_VALUE      0x00U

 

  UART1_BDL = UART1_BDL_VALUE;   // #define UART1_BDL_VALUE      0x36U

 

  UART1_C4 = UART1_C4_VALUE;        // #define UART1_C4_VALUE       0x08U

 

  UART1_MA1 = UART1_MA1_VALUE; // #define UART1_MA1_VALUE      0x00U

 

  UART1_MA2 = UART1_MA2_VALUE; // #define UART1_MA2_VALUE      0x00U

 

  UART1_C1 = UART1_C1_VALUE;      // #define UART1_C1_VALUE       0x00U

 

  UART1_S2 = UART1_S2_VALUE;      // #define UART1_S2_VALUE       0xC0U

 

  UART1_MODEM = UART1_MODEM_VALUE;  // #define UART1_MODEM_VALUE    0x00U

 

  UART1_IR = UART1_IR_VALUE;  // #define UART1_IR_VALUE       0x00U

 

  UART1_TWFIFO = UART1_TWFIFO_VALUE; // #define UART1_TWFIFO_VALUE   0x00U

 

  UART1_RWFIFO = UART1_RWFIFO_VALUE; // #define UART1_RWFIFO_VALUE   0x01U

 

  UART1_SFIFO = UART1_SFIFO_VALUE; // #define UART1_SFIFO_VALUE    0xC7U

 

  UART1_CFIFO = UART1_CFIFO_VALUE; // #define UART1_CFIFO_VALUE    0xC0U

 

  UART1_PFIFO &= ~UART1_PFIFO_MASK; // #define UART1_PFIFO_MASK     0x88U

 

  /* Clear flags */

  #ifdef UART1_CLEAR_FLAGS

  (void)UART1_S1;

  (void)UART1_D;

  #endif

 

  UART1_C5 = UART1_C5_VALUE;  // #define UART1_C5_VALUE       0x00U

 

  UART1_C3 = UART1_C3_VALUE; // #define UART1_C3_VALUE       0x0FU

 

  UART1_C2 = UART1_C2_VALUE_2; // #define UART1_C2_VALUE_2     0x2CU

}

Outcomes