|
|
View previous topic :: View next topic |
Author |
Message |
ice
Joined: 30 May 2005 Posts: 10 Location: India
|
Serial Comm. problem between 2 PICs |
Posted: Tue Jun 28, 2005 4:23 am |
|
|
Hello,
Im trying to communicate between 2 pics ,with no success
The ADC value[10bit] from pic1 is transmitted to pic2.
i get a few values from pic 2 and then it stops receiving..
im working at 9600 baud ,20Mhx crystals and two PIC16f873A 's
My setup is in this format
PIC1(Hardware UART)
|||||||
(Software UART)PIC2(Hardware UART)
|||||||
PC COM Port
b is an array of char >>b[20]
Transmit routine:
Code: |
while(TRUE)
{
test=read_adc();
delay_ms(10);
sprintf(b,"%lu",test);
puts(b);
} |
Receive routine:
Code: |
while(TRUE)
{
fgets(b,picpic);
x=atol(b);
fprintf(picpc,"%4lu\n",x);
}
|
Thank you _________________ **ice**
Machinegrid.com :: Robots at Work!! |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Tue Jun 28, 2005 5:25 am |
|
|
Hi,
MCU: 16F877
Compiler: PCM 3.169
Have you specified the stream parameter in #use RS232 statement.
Eg.:
Code: |
#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n,brgh1ok,stream=PC)
#use rs232(baud=9600,xmit=pin_b1, rcv=pin_b2,parity=n,brgh1ok,stream=LASERCONTROLLER)
|
Here LASERCONTROLLER is the software USART, and PC the hatrdware one.
thanks
arunb |
|
|
Guest
|
|
Posted: Tue Jun 28, 2005 6:06 am |
|
|
Thanks for your reply ..yes i did specify the streams
Code: |
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=PicPc )
#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5,stream=PicPic )
| [/code] |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Jun 28, 2005 6:08 am |
|
|
fgets() reads until it receives a RETURN. You are not sending any that I can see. Also make sure that you have specified ERRORS in you #use RS232 statement. Personally I wouldn't use the fgets() function. Sure is an easy way to overrun a buffer. |
|
|
Ttelmah Guest
|
|
Posted: Tue Jun 28, 2005 6:55 am |
|
|
Yes.
It is far 'better', to include 'input.c', and use the 'get_string' function. This allows you to specify a maximum length for the string, which will 'block' if more characters arrive than expected, or re-code this to default to return when the string is full. :-)
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
|