PDA

View Full Version : strange rs232 data displayed



MOUNTAIN747
- 12th January 2010, 19:22
I am sending RS232 from PIC to PIC. Transmitter sends 16 characters, “ABCD….OP”. Transmitter output is verified with Tera Term on PC. Both Tx and Rx operates at 96k baud. Receiver stores characters in VAR RxData. RxData is displayed on LCD on my X1 board. On the first pass LCD displays ABABCDEFG….. On the second pass and all passes after the LCD displays OPABCDE….. for 16 characters. I have used different delays on the receiver before and after, hserin 2000,TimeOut , [str Rxdata\16]. I can’t figure out why this is happening. I’m not real sure about the use of STR modifier, can this be a problem? Comments please!

Tx char string ABCDEFGHIJKLMNOP
First pass Rx display ABABCDEFGHIJKLMN
Second pass display OPABCDEFGHIJKLMN
All fallowing pass OPABCDEFGHIJKLMN
--------------------------------------------

RxData var byte [20]

Main:
RxData=0 ;clear RxData
hserin 2000,TimeOut , [str Rxdata\16]

LCDOUT $FE,1,"Rcvd string: " ;display 16 bytes RxData
LCDOUT $FE,$c0
LCDOUT str rxdata\16
pause 3000
goto Main ;Loop forever

TimeOut:
LCDOUT $FE,1,"Fumble,try again"
pause 1000
GOTO main

Archangel
- 12th January 2010, 19:42
What happens if you clear rxdata after you lcdout the value?
I am thinking . . . . 20 byte array vs 16 byte data . . . maybe shifting . . . no time right now to play with this .

MOUNTAIN747
- 12th January 2010, 23:27
Joe,
I cleared RxData after LCDout as you suggested with no change in results. Then I tried this addition:

LCDOUT $FE,1
LCDOUT RxData[1],RxData[2],RxData[3],RxData[4],RxData[5], RxData[6]
PAUSE 3000
Results: first pass: BABCDE. second pass: PABCDE
This is even more puzzling.
String display after first pass OPABCDE…Byte display PABCDE
String display screws up two bytes while byte display screws up one byte????

With this change:
hserin 2000,TimeOut , [wait ("A"),str Rxdata\15
LCDOUT $FE,1
LCDOUT RxData[1],RxData[2],RxData[3],RxData[4],RxData[5], RxData[6]
pause 3000


Results:
first pass: ABCDEF “A” should not have been displayed
second pass: CDEFGH
third pass: ABCDEF same as first pass
forth pass: CDEFGH same as second pass
and continues to rotate output data through each pass

If I Rx string then LCDout and END with only one cycle the results are the same ABABCDEF…..
It sounds like RxData IS clearing based on changing first display byte. So it has something to do with hserin RxData “I think”. I added a delay after Tx output with no change in Rx. Still scratching my head...........

By the way, I like your quote from the 1950's. I've passed it on to others.

Dennis
- 12th January 2010, 23:46
Hey Moutnain747

What are your HSER defines set to ?

What clock speeds etc , internal or external oscillator ?
PIC's?

Is there anything between the two PIC's ?

Are they wired or wireless ?
Did it all work before ?

Did you try a lower baud rate ?

Think this info may help other help you more :-)

Thought this may help assuming you're running at 20 MHz


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 0 ' 9600 KBaud @ 20MHz, -86.98%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

Kind regards
Dennis

mackrackit
- 13th January 2010, 00:46
Post your whole code, RX and TX.
Remember that arrays start at zero [0]

MOUNTAIN747
- 13th January 2010, 18:23
After testing at different Bauds, trying different Hser defines, I found that if I always use a short define string before my needed data all reception is exceptable. Sending a string of “SINKABCDEFG…… and receive with

hserin 2000,TimeOut , [wait("SINK"),str Rxdata\16]

is successful each loop without error. I’ve seen other examples like this and I’m sure it’s a good practice. I’m sending with 16F819 at 8Mhz internal driving a LT108CN RS232 shifter. Resulting in NO errors on Tera Term.

Receive on X1 board, 16F877A at 20Mhz also with LT108CN. Wired connection from bread board w/ F819. My only question now is why this works on receive end:

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_BAUD 9600 ' Baud rate
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

And this doesn’t work on receive end with my X1 board:

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 0 ' 9600 KBaud @ 20MHz, -86.98%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

Thank you guys for all your comments!

Dennis
- 13th January 2010, 20:09
Hi Mountain :-)

Glad you're winning !

You left a few things out :-)

Try this
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 12 ' 9600 Baud @ 8MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

Hope that helps :-)

Dennis