我的程序可以发送数据,但是不能接收数据。请问是为什么,我把代码贴出来吧。我发现里边rdrf一旦进入中断后就自动变为0,而且不管我怎么赋值,也不能改变sci0sr1_rdrf的值,请问谁知道是为什么呢?
C/C++ code?#include <hidef.h> /* common defines and macros */ #include "headers/uart.h" void main(void) { UART_s8Init(Duart0, 9600); EnableInterrupts; UART_s8SendByte( Duart0, 2 ); for(;;) { _FEED_COP(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */} #include "headers\uart.h" #include <mc9s12dg128.h> #pragma LINK_INFO DERIVATIVE "mc9s12dg128" #if (Duart_UART0_used) volatile static U8 u8Uart0_RxBuffer[Duart_BUFFER_SIZE_RX]; volatile static U8 u8Uart0_RxB_indexin=0; volatile static U8 u8Uart0_RxB_indexout=0; volatile static U8 u8Rx_0_Error=0; #endif S8 UART_s8Init( U8 UART_Id, U32 baudrate) { U16 ubrr_value=0; #if F_UART==8000000 switch( baudrate ) { case 2400 : ubrr_value = 207; break; case 4800 : ubrr_value = 103; break; case 9600 : ubrr_value = 52; break; case 14400 : ubrr_value = 34; break; case 19200 : ubrr_value = 25; break; case 28800 : ubrr_value = 16; break; case 38400 : ubrr_value = 12; break; case 57600 : ubrr_value = 8; break; case 76800 : ubrr_value = 6; break; case 115200 : ubrr_value = 3; break; case 230400 : ubrr_value = 1; break; case 250000 : ubrr_value = 1; break; case 500000 : ubrr_value = 0; break; default : return( -1 ); } #else #error "F_UART non reconnu ou non defini !" #endif #if (Duart_UART0_used) if(UART_Id==Duart0) { SCI0BDH=(ubrr_value>>8) & 0xFF; SCI0BDL=ubrr_value& 0xFF; SCI0CR1=0x00; // SCICR1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 SCI0CR2=0x2C; // enable tx et rx interrupts } #endif return(0); } S8 UART_s8GetByte( U8 UART_Id ) { #if (Duart_UART0_used) if(UART_Id==Duart0) { if(u8Rx_0_Error==1) { u8Rx_0_Error=0; return(-1); // Err Rx }else { while(SCI1SR1_RDRF==0) ; //=while(!SCI1SR1_RDRF); waite until le data arrive , rdrf!=1 SCI1SR1_RDRF=1; return SCI1DRL; } } #endif } 是通过中断判断是不是有数据进来,所以这个时候不用判断rdrf。这样就可以看到来的数据了。
|