View previous topic :: View next topic |
Author |
Message |
pavelustinov
Joined: 09 Mar 2013 Posts: 20
|
Receive rs232 data |
Posted: Fri Apr 19, 2013 7:23 am |
|
|
Hello everybody!
I use simple program to understand, how rs232 works.
Code: | #include <16f877a.h>
#device *=16
#use delay(clock=20000000)
#fuses noWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, DEBUG
#use rs232(baud=4800,xmit=PIN_C6, rcv=PIN_C7,stream=HOSTPC,errors)
void main()
{
int a;
while(TRUE) {
a = 44;
fputc(a);
delay_ms(100);
}
} |
I try to send "a" variable to Hyper Terminal.
My Hyper Terminal in hex mode shows "C0", in binary "11000000".
How can I understand the variable value?
I try
fputc(0xC0);
But Hyper Terminal doesn't display anything.
For example, I use big program and I want in Debug mode to know the value of "a" variable. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Apr 19, 2013 7:56 am |
|
|
idea #1
you specify a stream in the RS232 setup but don't specify it in the fputc send.
suggest remove "stream' and try again. |
|
|
pavelustinov
Joined: 09 Mar 2013 Posts: 20
|
|
Posted: Fri Apr 19, 2013 8:00 am |
|
|
asmboy wrote: | idea #1
you specify a stream in the RS232 setup but don't specify it in the fputc send.
suggest remove "stream' and try again. |
The same. I have "C0" in hex, "11000000" in bin. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Apr 19, 2013 8:00 am |
|
|
Try sending plain text to confirm that terminal and PIC are talking at the same baud rate.
You don't have a #FUSES HS or similar.
Mike |
|
|
pavelustinov
Joined: 09 Mar 2013 Posts: 20
|
|
Posted: Fri Apr 19, 2013 8:11 am |
|
|
Mike Walne wrote: | Try sending plain text to confirm that terminal and PIC are talking at the same baud rate.
You don't have a #FUSES HS or similar.
Mike |
I try this
Code: | #include <16f877a.h>
#device *=16
#use delay(clock=20000000)
#fuses noWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, DEBUG, RC
#use rs232(baud=57600,xmit=PIN_C6, rcv=PIN_C7,errors)
void main()
{
char a;
while(TRUE) {
a = "example string";
fputc(a);
delay_ms(100);
}
} |
But Hyper Terminal shows "FF" in hex, "1111111" in bin |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Apr 19, 2013 8:22 am |
|
|
CCS provides tested code to send text via RS232.
Use theirs, rather that write your own.
Mike |
|
|
pavelustinov
Joined: 09 Mar 2013 Posts: 20
|
|
Posted: Fri Apr 19, 2013 8:42 am |
|
|
Mike Walne wrote: | CCS provides tested code to send text via RS232.
Use theirs, rather that write your own.
Mike |
I try this
Code: | void main() {
while(TRUE) {
putc(getc());
}
} |
I send "testing", but I recieve something strange 76(6С)З and other. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Apr 19, 2013 10:11 am |
|
|
back to basic hardware...
How have you connected the PIC to the PC ???
What are the connections ?
Also try a slower baud rate, like 9600, at least for test purposes.
report back...
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Fri Apr 19, 2013 11:06 am |
|
|
Comments:
'a' is a single character variable. It can't hold a string of characters. Even if it could, you can't transfer a string with '='.
Then on your original problem. Think about the data patterns. You PC is seeing 0xC0. This requires the pattern:
..100000011....
Sending 44, gives the pattern
..1000100010....
Now if you imagine this being stretched till it is double the length, you have
..1000000110000001100....
Notice that the first nine bits are exactly what you are seeing.
Either your PC is set to use 9600bps, so is sampling twice as fast as it should, or your PIC is not running at 20MHz, but about 10MHz, so is actually sending at 2400bps.
Given that 9600 is a common default speed for many PC programs I'd start here....
Best Wishes |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Apr 19, 2013 11:26 am |
|
|
putc() will sent ONE character out from the PIC. If you want to send multiple characters, ie. a 'string' of characters then you should use puts(). Try:
Code: | void main(void)
{
while(TRUE)
{
puts("TEST");
delay_ms(500);
}
} |
This will sent the word TEST out twice a second.
Also, you need to make sure you have a device that will convert the 5V signal levels from the PIC to RS232 levels your computer uses, like a MAX232.
Ronald |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|