Question regarding picaxe interfacing FAQ

Hey guys,
I've got a quick question regarding one of the answers to the picaxe interfacing FAQ, namely the answer regarding additional outputs (title "I need more outputs - what can I do?")
It recommends using the following code (based on two 20M2s):
Code:
        let dirsb = $FF
main:   serin C.0, N2400, b1
        let pinsb = b1
        goto main
This allows you to control the B pins on the connected microcontroller. My question is, is there a way to also control the C side with this system? My guess is that I would have to take into account the pins being used for the serial transfer, and set these to inputs within the first line of code.
Code:
start0:
        let dirsb = $FF
        let dirsc = $BE                       'Pins C.0 and C.6 set to inputs
main0:   serin C.0, N2400, b1
        let pinsb = b1
        goto main

start1:
       pause 100                             'Allow time for dirs command to come into effect - a little overkill, but better safe than sorry
main1:
       serin C.6, M2400, b2
       let pinsc = b2
       goto main
In this example I've kept the serial input for the B side on C.0, and connected the input for the C side into C.6. The two sides operate on seperate parallel programs, to simplify the operation.

Would this work? I plan on using an 18M2 connected to a 14M2, obviously the program would be slightly altered. Any feedback would be most welcome.

cheers
 

hippy

Technical Support
Staff member
Yes; that's the basic idea. You will likely have to pass over more than one byte to control the two slave ports and it would be best to use serial qualifiers when sending multiple bytes. And don't use 'start0' and 'start1' as labels as they puts the chip into multi-tasking mode and all manner of odd behaviour will occur.

For example, sending from an 18M2 to 14M2, this (untested) should toggle all the 14M2 output pins on and off ...

Code:
#Picaxe 18M2
Do
  ;     76543210
  b0 = %00111111 ; B
  b1 = %00010111 ; C
  SerOut B.7, N2400, ( "DATA", b0, b1 )
  Pause 1000

  ;     76543210
  b0 = %00000000 ; B
  b1 = %00000000 ; C
  SerOut B.7, N2400, ( "DATA", b0, b1 )
  Pause 1000
Loop
Code:
#Picaxe 14M2
;        76543210
dirsB = %00111111
dirsC = %00010111 
Do
  SerIn C.3, N2400, ( "DATA" ), b0, b1
  pinsB = b0
  pinsC = b1
Loop
C.3 is used as serial in on the 14M2 as that's an input only pin so that doesn't lose an output pin.
 
OK, perfect - I didn't realise that could be done, sending data into multiple variables... You learn something new every day! Perfect, I'll wire this up, and get back to you with the results!
 
Top