|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Software UART not working |
Posted: Fri Jan 01, 2010 1:46 pm |
|
|
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
|
|
Posted: Fri Jan 01, 2010 3:41 pm |
|
|
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 |
|
|
|
|
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
|