Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Uart1_Data_Ready() always returns true

Status
Not open for further replies.

K33rg4t3

Full Member level 3
Joined
Aug 2, 2015
Messages
165
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,298
Activity points
2,607
Hey!
I am creating RS232 communication on PIC16F628A.
I am able to send a string to the computer and receive it in hyper terminal.
But I am haveing troubles with doing "Echo" application. It looks like Uart1_Data_Ready() is always returning true, and my PIC is spamming empty "Letter received" messages to PC.
Here is my code:

Code:
void main() {
   int count;
   char buff[64];
 CMCON = 7;    // Disable Comparators
 UART1_Init(9600);   // Baud Rate 9600
 Delay_ms(100);
 TRISA = 0;     
 TRISB = 0;   
 count = 0;
 while(1) {
  // every some time send the string
  if(count >= 255) {
     UART1_Write_Text(" UART Test Successful! ");  // Character Message to be Sent
     UART1_Write(10); // Line Feed
     UART1_Write(13); // Carriage Return
      count = 0;
      PORTA ^= 0x7;
  }
// if something is received
  if(UART1_Data_Ready())
  {
   // read and reply
   int r = UART1_Read();
   buff[0] = r;
   buff[1] = 0;
     UART1_Write_Text("Letter: ");
     UART1_Write_Text(buff);
     UART1_Write(10); // Line Feed
     UART1_Write(13); // Carriage Return
      count = 0;
  }
  count++;
  delay_ms(1);  
 }
}

The problem is that I am getting "Letter: " messages all the time in the PC. Please help.
 

Problem with TRISB ?

Rx pin on PORTB should be configured as input pin using TRISB.
 
I'm intrigued to know how the portB pin would be related to the original question.
 

I'm intrigued to know how the portB pin would be related to the original question.

RB1 has RX function and RB2 is TX. And I was setting TRISB after initializing the UART, thus overwriting the correct settings...
 

Sure, I forgot to complete the argument, that a priori would be not necessary to thange PortB settings. It is a good practice to place initialization functions for peripherals right after I/O pins configuration.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top