08 to 20x2 serial data link

sid

Senior Member
Hi all,
I've spent the last two evenings trying to get an 08 to talk to a 20x2 via a serial out/in link but without success.
I've managed to get the 08 to talk to another 08 but when the transmitting 08 is connected to the reciving 20 nothing happens, so I assume that error is in the coding of the 20 as the pre serin code works fine.
code for the 08 is as follows..
Code:
;1ST 08 TRANSMITTING
start:
b0=1
serout 0,n1200_8, ("uuuuuuuuuu") 	;sends a waky waky call @ slow rate
pause 10					;waits for the receiver to wake up
serout 0,n1200_8, ("ABC",b0)         ;sends password ABC then b0
pause 1000		                        ;wait 1 second

b0=2
serout 0,n1200_8, ("uuuuuuuuuu") 	;sends a waky waky call @ slow rate
pause 10					;waits for the receiver to wake up
serout 0,n1200_8, ("ABC",b0)         ;sends password ABC then b0
pause 1000					;wait 1 second
goto start					;return to s
and the code for the receiving 20 is....
Code:
prestart:

b1 = %11111111 :gosub doit
b1 = %11111111 :gosub doit
b1 = %11111111 :gosub doit
pulsout c.4,10

pause 2000

b1 = %00000000 :gosub doit
b1 = %00000000 :gosub doit
b1 = %00000000 :gosub doit
pulsout c.4,10


start:
serin c.2, n1200_8,("ABC"),b0
if b0=1 then goto sig1
if b2=2 then goto sig2
goto start

sig1:
b1 = %00100100 :gosub doit
b1 = %10010010 :gosub doit
b1 = %01001001 :gosub doit
pulsout c.4,10


goto start

sig2:
b1 = %00100100 :gosub doit
b1 = %10010010 :gosub doit
b1 = %01100100 :gosub doit
pulsout c.4,10


goto start

doit:
for b0= 1 to 8
if b1 > 127 then high c.7 else low c.7
endif
pulsout c.5,10
b1 = b1 *2
next b0
return
The 20 is setting up three 8bit shift registers hence the three lines of 1's and 0's
The picaxe x2 product briefing states that the pin should be refered to as
the port number, in this case port c.2
I've tried changing the baudrate thinking that perhaps the 08 runs at 4mhz and the 20 runs at 8mhz so I've played around with those settings as well.
I'm obviously missing something so simple, please put me out of my misery
 

hippy

Ex-Staff (retired)
It's likely the problem is you are using "n1200_8" on the 08M but haven't specified "SETFREQ M8" so the serial sent won't be at 1200 baud.
 

sid

Senior Member
Hi Hippy,
Thanks for the quick respnse
please tell me more, ie: how do I code "SETFREQ MQ" as this is a new one for me
 

hippy

Ex-Staff (retired)
Just add "SETFREQ M8" before your start line, or preferable at this stage, just remove the _8 from all the baud rate specifiers. If you do add "SETFREQ M8" you will be running the 08M twice as fast so your pauses will all be half as long so you'll have to alter them as well.

Details on SETFREQ is in PICAXE Manual 2.
 

sid

Senior Member
had a quick read of the manual, added SETFREQ M8 at the start and doubled the length of the pauses, watch the led on the serout pin flash at double speed, but the 20 still won't take any notice
 

hippy

Ex-Staff (retired)
Try some simpler code ...

#Picaxe 08M
Do
SerOut 0, n1200, ( b0 )
b0 = b0 + 1
Pause 1000
Loop

#Picaxe 20X2
#Terminal 9600
Do
SerIn c.2, n1200, b0
SerTxd( #b0, " " )
Loop

With the download cable connected to the 20X2 the Terminal should show an incrementing number. If not check your hardware, make sure the correct pins are connected and 0V between 08M and 20X2.

If you are using an RF module, take that out, use a wired link to start with.
 

sid

Senior Member
Thanks Hippy,
I will try this later this evening, but I notice in your reply you say to check the 0V between the 08 and 20, however both chips are on seperate boards fed from different power supplys, is this the problem ?, does a serial link have to be between axes fed from the same power source?
 

hippy

Ex-Staff (retired)
No, each PICAXE can be on its own power supply but the 0V of each circuit must be joined for a wired serial connection.

It is also extremely advisable to put a 1K resistor in series with the communications lines linking each board when using separate power supplies to avoid potential damage to the components when the voltage is not the same each side.

When trying to get something working the best advice is to keep it simple, remove as much that can go wrong out of the picture. That applies to hardware as well as software, so ideally operate from the same supply to start with, then move to separate supplies.

Otherwise, dive-in, and if it doesn't work, there are so many factors which could be a problem it becomes extremely difficult to determine what the problem may actually be. It's also best to describe exactly what one has ( why full and complete circuit diagrams are so important ) so a factor which may be the problem isn't simply over-looked. Hours of many people's time can be wasted on trying to find a problem which is actually somwhere else and only ascertained by guesswork or logical deduction, if it ever is.
 

sid

Senior Member
Added an earth strap between circuits and both chips are talking to each other
Many thanks
 

SAborn

Senior Member
It is highly likely the 20x2 chip will need its internal clock calibrated to send/receive serial data, it has been a fault in every 20x2 chip i have used, that the serial wont work without recalibration.

Try sending some known serial data from the 20x2 to the screen and i bet you will get gargage displayed.

I have only ever had this problem with the 20x2. (other wise its a great chip)

You will need to use calibfreq to adjust the internal clock, somewhere around a value of -15 is needed on average but this will vary for chip to chip.
 

sid

Senior Member
Both the opto isolator and the re-calibration of the internal resonator are interesting ideas which I will bear in mind for the future, but for now the 20x2 is receiving fine.
FYI.
The idea is that I have a bank of 25 switchs on a control panel and I want each switch to be able to control several different picaxe circuits which will al be working on different power supplys, so I will be using a resistor array into an adc port on a 08m which will then send out a serial instruction to the other circuits which will be a mix of 18,20,28 picaxes.
But now I've got the 20x2 to take instruction from the 08 I'm on my way
Thanks all
 
Top