CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Software UART not working

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Software UART not working
PostPosted: Fri Jan 01, 2010 1:46 pm     Reply with quote

I am trying to make a serial link between two MCs, but I failed.

TX side
Code:

#include<16f877a.h>
#use delay(clock=20m)
#fuses nowdt,hs
 
#use rs232(baud=4800, bits=8, parity=E, stop=1, xmit=PIN_A0, rcv=PIN_A1, stream=COM_a, ERRORS)
 
void main()
{    
int data;

while(true)
  {
   fputc(0x02,com_A);
  }
}


Rx Side
Code:

#include <18F2550.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#include<lcd420.c>
 
#use rs232(baud=4800, bits=8, parity=E, stop=1, xmit=PIN_A0, rcv=PIN_A1, stream=com_a, ERRORS)  // For communicating with other PIC
#use rs232(baud=4800, bits=8, parity=E, stop=1, xmit=PIN_A2, rcv=PIN_A3, stream=com_b, ERRORS)  //To computer, currently not using
 
   
void main()
{
int d1;
delay_ms(100);
lcd_init();
delay_ms(100);
printf(lcd_putc,"\fWelcome");
delay_ms(2000);

while(1)
  {
   d1= fgetc(com_A);
   printf(lcd_putc,"\fd1=%x",d1);
   delay_ms(100);
  }
}

I am getting some garbage values....like 20,84,2

Please help me....
Ttelmah
Guest







PostPosted: Fri Jan 01, 2010 3:41 pm     Reply with quote

You will....
The software UART, has to be _sitting waiting_ for an incoming character.
In your case, the receiving PIC, paues for 2.2+ seconds, before even starting to try to receive. It will see the first _falling_ edge on the serial line after this point, as the start of the character, so will receive garbage, since it will be in the middle of a continuous stream of characters. Even if by sheer chance, it happens to start at the right point for one character, your code then pauses for 0.1seconds (plus the time to write to the LCD), so another 2.9 characters will have already been missed, and the code will start looking inside another character, and again receive garbage.
Do a search here. There are some possible solutions (using a hardware interrupt to actually trigger character reception, or in the past I have posted a 'core' to a timer based software UART), but what you are trying to do, just won't work with the software UART as it stands.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group