|
|
View previous topic :: View next topic |
Author |
Message |
Reignfire
Joined: 21 Jun 2009 Posts: 2
|
RS232 receiving weird data, help! |
Posted: Sun Jun 21, 2009 8:07 am |
|
|
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
|
|
Posted: Sun Jun 21, 2009 8:31 am |
|
|
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
|
|
Posted: Sun Jun 21, 2009 8:50 am |
|
|
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
|
add some stuff |
Posted: Sun Jun 21, 2009 10:21 am |
|
|
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
|
|
Posted: Sun Jun 21, 2009 12:31 pm |
|
|
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 |
|
|
|
|
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
|