PDA

View Full Version : Serin,Serout Problem



orwell101
- 27th October 2012, 10:41
Hello!

I am a Newbie on programming Micros.
I have a PIC 16F84 an wrote a littele Program.
This is my Programm:
INCLUDE "modedefs.bas"
B0 var byte
a var byte
SI var PORTB.7
start:
SERIN si,T2400,B0
if b0 <> "0" then
for a= 0 to 255
serout si,T2400,[a]
next a
endif
goto start
end

When i send an X in the serial communicator window,the PIC sould send
the complette ASCII codes.
But the PIC send this:
X!A9#T̑!3H!CR"ʒ*Sq҉f2cRbrj(PPb=RiQQfy}-RR**-Mm*
Xq-1=AMQ]amq}*``
!"#,-./0123<=>?@ABCLMNOPQRS\]^_`abclmnopqrs|}~ *

The Settings of then Serial Communicator is:
COM1
2400 Baud
NoParity
ByteSice 8
1 Stop Bit

What do i wrong?
I think its a little Problem for the most afl here.
Sorry for mx English(german)

Thanks a lot for your help!

mackrackit
- 27th October 2012, 12:36
Welcome to the forum.

Try Inverted mode.

From the manual

While single-chip RS-232 level converters are common and inexpensive, the excellent I/O specifications of the PICmicro allow most applications to run without level converters. Rather, inverted input (N300..N9600) can be used is conjunction with a current limiting resistor.

Charlie
- 27th October 2012, 12:36
Lots of possible error sources, including, most likely, clock configuration. Please post your complete code.
Are you using something like a MAX232 device? If not, you need to invert your data.

harralk
- 27th October 2012, 17:41
Are you using something like a MAX232 device? If not, you need to invert your data.

I'm having a similar problem with my project and I was told to ensure the data sent was true (not inverted). I am using a 16f88, not an 84 maybe that's the difference?

Charlie
- 28th October 2012, 01:37
I'm having a similar problem with my project and I was told to ensure the data sent was true (not inverted). I am using a 16f88, not an 84 maybe that's the difference?

Why don't you simply try it? It's a grand total of 1 character difference in 2 places in the posted code... Certainly no need to take our word for it :p

MikeWinston
- 28th October 2012, 02:18
Serial out and serial in on same PIC pin? Normally separate pins.

Archangel
- 28th October 2012, 07:12
Hello!

I am a Newbie on programming Micros.
I have a PIC 16F84 an wrote a littele Program.
This is my Programm:
INCLUDE "modedefs.bas"
B0 var byte
a var byte
SI var PORTB.7
start:
SERIN si,T2400,B0
if b0 <> "0" then
for a= 0 to 255
serout si,T2400,[a]
next a
endif
goto start
end

When i send an X in the serial communicator window,the PIC sould send
the complette ASCII codes.
But the PIC send this:
X!–ˆA9Œ#‘T‘!†Ž3’H!CR‰"’*Sq‰fœ2cRbr‚’j(PPb=RiQQfy}-RR**™-Mm*
–Xq-1=AMQ]amq}‘*˜``
!"#,-./0123<=>?@ABCLMNOPQRS\]^_`abclmnopqrs|}~€‚ƒŒŽ‘’“œžŸ *

The Settings of then Serial Communicator is:
COM1
2400 Baud
NoParity
ByteSice 8
1 Stop Bit

What do i wrong?
I think its a little Problem for the most afl here.
Sorry for mx English(german)

Thanks a lot for your help!
That you get output is good, that it is garbage can have several causes. 1 oscillator is not defined in code, 2. baud rate mismatch between sender & receiver. 3. sending and receiving mismatch (one true the other inverted). 4. long or loss-ey cables causing data corruption, or receiving noise.5.mismatched data profile I E parity # of bits . . .
I would DEFINE OSC x where x represents your crystal or resonator, or if you are using INTRC then make (x) 4. The define does not make the oscillator work at that speed it simply forces PBP to adjust all of it's timing to accommodate the defines speed.

orwell101
- 28th October 2012, 12:26
Hello!
I have used DEFINE OSC 4
and N9600.
I think the Problem is my COM Settings.
What shoul i use there?

norohs
- 28th October 2012, 16:17
I know how frustrating it can be to get this problem. It cost me several hours (and a dead USB to RS232 dongle) to isolate my problem. It turns out the internal oscillator (4Mhz) on my 12F629 was too far off. I probably killed the internal calibration value by mistake at some other time.


"for a= 0 to 255"

You are getting some data in acceding order. Using printable characters can help by counting the number of correct ascending order before it breaks consistent order. The control characters can be muddying up things. Maybe:

for a=32 to 126 'send only printable characters

Also, characters pacing might help

DEFINE CHAR_PACING 1000 'character pacing of 1ms

My Hyper Terminal setting is on ASCII (chosen from a list in the setup)

mackrackit
- 29th October 2012, 01:38
In your code, change back to 2400
N2400

And leave the PC program at 2400.

Let us know what happens so we can help more if needed.

orwell101
- 30th October 2012, 11:57
Hello!
I have tried this.
INCLUDE "modedefs.bas"
B0 var byte
define OSC 4
DEFINE CHAR_PACING 1000
A var byte
SI var PORTB.7
start:
SERIN si,N2400,B0
if b0 <> "0" then
for a= 32 to 126
serout si,N2400,[a]
next a
endif
goto start
end

And the PIC sends nothing more

norohs
- 30th October 2012, 14:56
It stops sending anything? Or the same garbage? Which?

And I'm with Mike:

"Serial out and serial in on same PIC pin? Normally separate pins. "

orwell101
- 30th October 2012, 23:36
Hello!
I think i must send the CHR$ code of a.
How can i do this?

mackrackit
- 31st October 2012, 01:31
About half way down is the Standard ASCII Character Set
http://melabs.com/resources/ascii.htm

norohs
- 31st October 2012, 04:19
Hello!
I think i must send the CHR$ code of a.
How can i do this?

I don't think so. By limiting the decimal value of 'a' to printable characters, the byte being sent will print that ASCII character. So, the way its being sent now is '32' will print a space, '33' will print "!",,,, '65' will print "A", etc..

Are you willing to try separate and different ports for the SERIN and SEROUT? Sending and receiving on the same port pin is something I've never seen done using SERIN and SEROUT... and I have never considered doing it myself. It sure would eliminate one obvious anomaly.

<snip...>
SI var PORTB.7
start:
SERIN si,N2400,B0 <===== SERIN (on) PORTB.7
if b0 <> "0" then
for a= 32 to 126
serout si,N2400,[a] <====== serout (on) PORTB.7

Try not using the same port for SERIN and SEROUT.

It may not be an issue for PBP to use the same port pin, but I can't imagine what the hookup to the RS232 would look like.

EDIT: To be simple about it, just remark out:

start:
' SERIN si,N2400,B0
' if b0 <> "0" then
for a= 32 to 126
serout si,N2400,[a]
next a
' endif
goto start

AvionicsMaster1
- 31st October 2012, 14:08
If that doesn't work try

start:
' SERIN si,N2400,B0
' if b0 <> "0" then
for a= 32 to 126
serout si,T2400,[a]
next a
' endif
goto start

I believe if the issue is only with inverted data that should get it to display.