AnsweredAssumed Answered

SCI0SR1_RFRD set 0 before I read SCI0DRL'value

Question asked by 崇锐 卢 on Feb 24, 2016

UINT8

xReadCH376Data( void )  /* CH376读数据 */

{

 

INT8U ch;

    while(SCI0SR1_RDRF == 0) { /* Is the transmitter empty? */

    }

    ch=SCI0DRL;

   return ch;

}

 

void Init_SCI0(INT16U sci_ytpe)

{

 

    #ifdef Enable_SCI_Interrupt

       //SCI0BD = BUS_CLOCK/16/BAUD; //设置SCI0波特率为9600

       SCI0CR1 = 0x00; //设置SCI0为正常模式,八位数据位,无奇偶校验

       SCI0CR2 = 0x2c; //允许接收和发送数据,允许接收中断功能

    #else

       SCI0CR1 = 0x00;

       SCI0SR2 = 0x80; /* Switch to the alternative register set */         //SCI使用发射器禁用接收器

       SCI0ASR1 = 0x83; /* Clear alternative status flags */

       SCI0ACR1 = 0x00;

       SCI0ACR2 = 0x00;

       SCI0SR2 = 0x00; /* Switch to the normal register set */

       (void) SCI0SR1; /* Reset interrupt request flags */

       //SCI0CR2 = 0x0C; /* Disable error interrupts */

//定义波特率115200

       SCI0CR2 |= (SCI0CR2_TE_MASK | SCI0CR2_RE_MASK);

     

    #endif

   

    

 

    switch(sci_ytpe)

     {

      case InitBaud:

        SCI0BD = BUS_CLOCK/16/UART_INIT_BAUDRATE;

        break;

      case WorkBaud:

        SCI0BD = BUS_CLOCK/16/UART_WORK_BAUDRATE;

        break;

      default:

        break;

     }

 

this is my code,

when I debug my program I found when a data is coming, RDRF register will be set 1,and SCI0DRL's value is correct.

But,when I clicked single step,

the RDRF reset,become 0

It makes me cant read what is coming in xReadData and code will be run in a dead loop.

 

 

Outcomes