View Full Version : Data corrupterd when using serout command
johnson
- 27th June 2004, 10:17
dear all,
I have some problems dealing with interfacing between pic16f628a and pc's hyper-terminal. My code is as follow:
INCLUDE "modedefs.bas"
testvalue var byte
pause 3000
'
'other code
'
'
SEROUT PORTB.2,T2400,["hello"] 'sending the string "hello"
SEROUT PORTB.2,T2400,["123"]
SEROUT PORTB.2,T2400,["abc"]
main:
serin PORTB.1,T2400,testvalue 'waiting for 1 byte of data and store it
'in testvalue
SEROUT PORTB.2,T2400,[testvalue]
goto main
Whenever I power up my PIC, the 1st byte of data sent will be corrupted(which shown in hyper terminal), however the rest of the data are correct. I wonder why??? Anyone got solution???
ps: i'm using pic16f628's, tx and rx is connected to hin232
thanks,
cheer:>
Melanie
- 27th June 2004, 11:03
There's a whole heap of reasons...
Try this...
Loop:
SEROUT PORTB.2,T2400,[REP $00\8,"hello "] 'sending the string "hello"
SEROUT PORTB.2,T2400,["123 "]
SEROUT PORTB.2,T2400,["abc",13,10]
Pause 1000
Goto Loop
Have you now got clean transmission?
Those NULS $00 sent at the start are there to push any line garbage lurking in your comms link away. Also, if you're not using a Resonator or Crystal oscillator, then 2400 baud can produce significant errors - especially at start up, and it can take a few bits for the PC's USART to sync-up if it's right at the edge of timing tollerance.
Melanie
johnson
- 27th June 2004, 11:24
thanks man, I am trying the way as u stated :>
johnson
- 27th June 2004, 11:49
hi i got some doubt:
what is the syntax "$00\8" means? I got compilation error "error line 6: expected "]", where line 6 is:
SEROUT PORTB.2,T2400,[$00\8,"hello "] 'sending the string "hello"
help please,
thanks,
Melanie
- 27th June 2004, 13:15
Sorry, my omission of the word REP... I've corrected it.
TONIGALEA
- 27th June 2004, 16:26
What does REP do?
Is this in the manual?
Toni
Melanie
- 27th June 2004, 17:00
REP c\n
Repeat character c, n times...
In the manual in at least four places... DEBUG, LCDOUT, SEROUT, SEROUT2... and in list of Reserved Words.
TONIGALEA
- 27th June 2004, 23:03
Thanks for pointing that out.
L_Gaminde
- 13th August 2004, 15:16
This is something that used to come up a lot
just before your pause 3000 put in
high portb.2
you could even change the pause 3000 to
pause 500
this should take care of all your problems
Is there a spell checker for this forum ??
NavMicroSystems
- 14th August 2004, 02:14
Melanie,
As there are more and more questions regarding serial comunication we should put some "How To's" together and post it in the FAQ category.
There appears to be a lot of confusion about the different modes (TRUE/INVERTED), Baud rate vs. clock speed etc.
regards
Ralph
Melanie
- 15th August 2004, 16:32
Yup, I agree. It's a question of finding time to do it all... nothing stopping other folks contributing to the FAQ... however Serial Comms is a major subject, and not something that gets covered in a couple of paragraphs and ten lines of code. Just for starters, you can do comms between two PICs a dozen different ways, and them some... it's one of those subjects that has so many variables, that what works brilliantly for one application, ends up totally inappropriate for another.
NavMicroSystems
- 15th August 2004, 16:45
Melanie,
If there is some FTP-space on the server we could start writing a "HowTo" and share that Document using FTP.
Once we think it covers everything it will go to the FAQ section as PDF.
regards
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.