PDA

View Full Version : Whats going on? serial comm



BobEdge
- 26th May 2005, 16:42
Hi,

I am having trouble with communication between 2 pics. All I am trying to do is send one word from one pic to another I have a cs and data line and the following code.

Transmitter:

high cs
pause 50
serout serialpin, T1200, [value]
low cs

Receiver:

datain:
serin serialpin, T1200, [value]
return

start:
IF cs = 1 then gosub datain
IF weld = 0 then start

I just cant get it to work. I have tried [#value], serout2 with [dec value], well have tried everything I can think of, but no luck. Help please. I have read all the posts I can find on serial comms, but I still cant see what im doing wrong.

Regards

Bob...

Dwayne
- 26th May 2005, 19:26
Hello Bob,

Clink on this link:
http://www.picbasic.co.uk/forum/showthread.php?t=579


before you do anything, you must break down your project in very simple steps... Your program shows nothing on using TRISIO switchings, making the chip pins I/O's Let alone turning off comparators and A/D's.

Dwayne

mister_e
- 26th May 2005, 19:29
must be few things...

Wich PIC are you using?
wich PIC pin are you using?
are they multiplexed with analog stufff???
if so did you disable them prior to use them?
Is your datain is before of after the main loop?
If before did you place a Jumpstart Goto to jump over your SERIN?

darkman
- 27th May 2005, 09:21
this my working serial com project : ( I'm test it )

transmitter :

@ device XT_osc
INCLUDE "modedefs.bas"
baslangicdatasi var byte
TRISB=%01000000
PORTB=0
baslangicdatasi=65

gonder:
PAUSE 1000
SEROUT PORTB.7,N2400,["protocol",baslangicdatasi] ' SEND BEFORE "protocol" AFTER SEND baslangicdatasi

son:
END


receiver :

INCLUDE "modedefs.bas"

TRISA=%00000000
TRISB=%00000011
B0 var byte
B1 var byte
B3 var byte
B0=0
PORTA=0
B3=2
LOW PORTB.3
LOW PORTA.2
HIGH PORTA.0
start:
B0=0
' IF PORTB.0=0 THEN bekle
' GOTO start

bekle:
SERIN PORTB.1, N2400, ["protocol"],B0 ' wait "protocol" after write receive baslangicdatasi and insert in B0

IF B0=65 then kontrol
GOTO bekle

kontrol:
IF B3=2 then ac
IF B3=1 then kapat
GOTO kontrol

BobEdge
- 27th May 2005, 11:45
Well thanks for the replies, but still no luck. This should be the easiest bit of the project. Isnt it always the way.

I have included the code. Display is the transmitter, and fback3 is the receiver. The programs control a welder, display is supposed to tell the feedback chip the desired welding current. I can see the serial input to the pic on the scope but still no output mirrored on the test pin. I have also tested the pins as digital in and out, so i know there is no damage to the chips. I have also written code just to test the comms part with but no difference

By the way in the display file is a routine to drive a 4 digit 7 seg led display, with blanking of leading zeros. Quite proud of that little routine.

Thanks again for the help. Hope we can sort it out soon, the boss is back on tuesday :-( lol...

Regards
Bob

Dwayne
- 27th May 2005, 15:24
Hello Bob,

Instead of wading through the code, can you write *just* the code to send the data?

When you do so, make sure the sending pin is a I/O pin.
Make sure you assign it with the TRIS register as a Output
Make sure you You turn off all ADC's and Comparators.

If you cannot scope the output on this pin of any data (like the decimal number 1), you are wasting your time with all the other stuff.

When you get a scoped decimal one, then work on the reciever side.

When the above is finished, insert it in your code where it belongs.

MisterE made some EXTREMELY good points... Do not ignore them!


Dwayne

BobEdge
- 27th May 2005, 15:57
I have scoped the output of the transmitter, no problem with that. To test the circuit I have a PIC16F877A transmitting:

pause 500 'make sure receiver has time to boot
let value = 1
loop:
serout portb.7, 1, [value]
pause 100
goto loop

and a PIC 16F870 receiver:

loop:
serin portb.7, 1, [value] 'get input
high led
serout portb.0, 1, [value] 'send to pin to compare waves
low led
goto loop

The led never flashes so its just sat waiting for input which it never sees, though the scope sees a nice clean signal on the input pin.

I have noted all the points Mr E mentioned. I have tried it on lots of pic types, and various pins, I have included "modedefs.bas", I have a 10k resistor from TX pin to gnd, no comparators to worry about.

I am going to try disabling the A/D before receiving data, but cant see this making a difference, since I'm using port B

regards

Bob...

darkman
- 27th May 2005, 17:10
and a PIC 16F870 receiver:

loop:
serin portb.7, 1, [value] 'get input
high led
serout portb.0, 1, [value] 'send to pin to compare waves
'add here PAUSE
low led
'add here PAUSE
goto loop


and try this software for rs 232 commination capture with pc :

http://www.rs232pro.com

Dwayne
- 27th May 2005, 17:18
Hello Bob,


Bob>>loop:
serin portb.7, 1, [value] 'get input
high led
serout portb.0, 1, [value] 'send to pin to compare waves
low led
goto loop

The led never flashes so its just sat waiting for input which it never sees, though the scope sees a nice clean signal on the input pin.
<<

Ok, One thing I see, is that it will only take a very SMALL amount of time to send the data to the output, Thus your LED may be flashing, but too fast.

Can you scope the POrtb.0? and see the data being transmitted? Do not rely on just 1 LED flashing. (which seems you are doing here). It will flash way too fast, and probably look as if it is not flashing at all.

Since you have scoped the transmitter, and have verified it, then the reciever should be almost the same...Try scoping the PORTB.0, and making sure you have data coming out. If not, it is in your receiver... Then I would suggest slowing down your baud rate to 300.

Dwayne

Bob>>I am going to try disabling the A/D before receiving data, but cant see this making a difference, since I'm using port B <<

Will not make any difference if they are not present on POrtb. PortA ususally has all the AD and comparators...

Make sure your TRISB has the proper pins as I/O... according to your example

your input is PORTB.7 and output is PORTB.0

Thus I would (for safety sake)
Portb=%10000000

This assigns POrtb.7 as a input, and all others as outputs.

Dwayne

BobEdge
- 2nd June 2005, 11:57
First of all thanks to everyone who replied to my posts. I have now cured the problem

serout serpin, 0, ["A",#VALUE,"AA"]
and
serin serpin, 0, ["A"],#VALUE
worked just fine.

Kind regards

Bob Edge...