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 CCS Technical Support

Receive rs232 data

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



Joined: 09 Mar 2013
Posts: 20

View user's profile Send private message

Receive rs232 data
PostPosted: Fri Apr 19, 2013 7:23 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Fri Apr 19, 2013 7:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 8:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 8:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 8:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 8:22 am     Reply with quote

CCS provides tested code to send text via RS232.
Use theirs, rather that write your own.

Mike
pavelustinov



Joined: 09 Mar 2013
Posts: 20

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 8:42 am     Reply with quote

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: 9220
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 10:11 am     Reply with quote

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: 19492

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 11:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 11:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 12:58 pm     Reply with quote

CCS FAQ article: Why is rs232 not working right ?
http://www.ccsinfo.com/faq.php?page=rs232_errors
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