PDA

View Full Version : Serial Comm startup



ruijc
- 9th January 2008, 09:13
Hi all,

i've been fine tunning this code that just reads the value of the temp. sensor and send's out to pc through RS232.

The code has been mentioned several times in previous threads so i wont repeat it here.

Also the question is very simple.

I use the PBP debug command to send the data out like this:

DEBUG DEC VA,13,10

The problem i'm having is that the first time that it sends data out the PC receives garbage like :

[#%$df|....etc

the second and following lines are all ok.

Why this is happening always for the first line and how can i avoid this ?

.

sinoteq
- 9th January 2008, 09:30
I guess it is only the first character that is wrong the first time you send. You can fix this by making sure the pin you use for serial com is in the correct state (High/Low) before you make the first Debug output. Also if you can start your program with a PAUSE so all other things around you MAX and similar gets some time to wake up.


-------------------------------------------
TRISwhatever..... 'make the pin an output

TXpin=1 '<------- here is the fix if you use TRUE modes, if you have inverted modes do TXpin=0
DEBUG..... 'send data on TXPIN

BrianT
- 9th January 2008, 10:25
Sinoteq is right. You must condition the Tx data line first. Here is what I do.

high tx232 'preset Txdata line high
pause 50 'allow receiver time to stabilise
debug $0D, $0A 'send carriage return line feed
for a = 2 to 42 ' display 42 characters from EEROM
read a,b
debug b
next a
debug $0D, $0A 'finish with carriage return line feed

HTH
BrianT

ruijc
- 9th January 2008, 10:45
BrianT, sinoteq,

thanks alot for the help.

Actually it's not just the first character but 90% and most of the time 100% of the entire first line .

As a note, i'm using a direct connection from the pic to the serial port.
Also tryed using an 1K resistor between I/O and serial port but the result is the same.

With your experience...what is best ? To use the serial resistor or not ?

Will try your instructions tonight ;)

.

sinoteq
- 9th January 2008, 13:08
That is the best way if you have space for it. This also will save your PC if your Pic board makes a misstake, the MAX chip dies and PC lives...... MAX is cheap PC is not :) I never connect my things without level-converter. It is so easy to make, really cheap so I don't see why not use it.

Regarding your resistor question I hope someone can explain it to you.

mackrackit
- 9th January 2008, 13:41
The code has been mentioned several times in previous threads so i wont repeat it here.


And now we search your past post to find the code. Yeah-right.

If you are going a shout distance the MAX is not needed. Make sure the signal is inverted if sending to a PC.

The resistor is for current limiting.

ruijc
- 9th January 2008, 14:50
"And now we search your past post to find the code. Yeah-right."

Not quite mackrackit,

that was not my intention !

I just simply wanted to say that the code was previously showned in diferent issues and that my question here on this thread did not required ( IMO ) all the code for the exception of the debug line it self.


"If you are going a shout distance the MAX is not needed."

By this you mean short distance ?

.

mackrackit
- 9th January 2008, 15:11
"And now we search your past post to find the code. Yeah-right."

Not quite mackrackit,

that was not my intention !

I just simply wanted to say that the code was previously showned in diferent issues and that my question here on this thread did not required ( IMO ) all the code for the exception of the debug line it self.

I was just being a smart ....:)



"If you are going a shout distance the MAX is not needed."

By this you mean short distance ?

.

I have gone 30 feet with no problems. The MAX chips are good if you need to invert the signal and you can not do it at the source and to raise the signal levels to +-12v as is standard for RS232. Making longer distances possible. Have reached around 80 feet this way. If the location is not noisy and the cable is good (CAT5 does not get it) the distance could be more.

ruijc
- 9th January 2008, 15:20
Thanks mackrackit,

got it ;)

This one will be for short distance only... 1 meter max.


.