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

RS232 receiving weird data, help!

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



Joined: 21 Jun 2009
Posts: 2

View user's profile Send private message

RS232 receiving weird data, help!
PostPosted: Sun Jun 21, 2009 8:07 am     Reply with quote

hello,

i wrote a program to receive data from a working distance sensor if i connect the sensor to a rs232 and read it in a terminal it gives the right values but i have to connect it to a 16f877 ic and then read it with a rs232 into a C# program the code for my 16f877 is the following:

header:

Code:
#include <16F877.h>
#device adc=8
#use delay(clock=20000000,RESTART_WDT)
#fuses HS, PUT, NOPROTECT, BROWNOUT, LVP,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt,STREAM=HOSTPC)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
#use rs232(baud=9600,parity=N,rcv=PIN_B0,bits=8,restart_wdt,STREAM=ULTRASOON)


and in my main class i use
Code:

char distance;
   while(true)
   {

   distance = fgetc(ULTRASOON);
   fputc(distance, HOSTPC);
   }


my (working) C# program reads the following: ??????????????????????... the question marks won't stop coming! i don't really know what i'm doing wrong i'm just a student and don't have much experience...

i hope somebody can help me.
Ttelmah
Guest







PostPosted: Sun Jun 21, 2009 8:31 am     Reply with quote

If the sensor will connect directly to a PC, you need a MAX232 chip between the sensor, and the PIC (and another between the PIC, and the PC).
First, get your PC interface working. Do a 'hello world' type program, and prove that you can print data to the PC. Then connect your sensor, using a MAX232 or equivalent inverter, and try again.

Best Wishes
Reignfire



Joined: 21 Jun 2009
Posts: 2

View user's profile Send private message

PostPosted: Sun Jun 21, 2009 8:50 am     Reply with quote

That isn't the problem... i have no trouble sending text to my pc.
i have my sensor and his ic's and already an rs232 port (it's like a sort of testboard) and i put a wire in my transmit-pin of the rs232 port so it's connected to the rb0 port (of the 16f877 ic) and there i have to use that input and send it to another rs232 ( it's a robot (i'm able to steer it but there's also a sensor on it)) so if i read the value of the connection i get weird signs and a lot of ???
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

add some stuff
PostPosted: Sun Jun 21, 2009 10:21 am     Reply with quote

1- add the ERRORS option to your hardware RS-232 setup
2- consider strongly using the interrupt based version of the second (software ) serial port handler - since you are already wired to port B0
it will be E Z to go to int based character reception
3- when sending to the 2nd port - check that you are not receiving from it synchronously.

see where that gets you
Ttelmah
Guest







PostPosted: Sun Jun 21, 2009 12:31 pm     Reply with quote

I think you are missing the 'point' of what I said.
The PIC, _does not have an RS232 port_. It is a common misconception (including with CCS!), that it does. The PIC only talks TTL async serial. To talk to anything using 'RS232', there _has_ to be an RS232 buffer. Now, it sounds as if you have the one between the PIC and the PC, but you need _another_ between the PIC, and the sensor, if the sensor will talk directly to the PC....
Without this, the PIC will 'see' inverted data, and since when idle, the unit will hold the line 'low', rather than the high that the PIC needs when idle, the PIC will receive garbage characters continuously. These are your continuous '?????'.

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