| The Free Site | vBuddy - make friends, share photos, blogs, have fun | Cheap Web Hosting - starting at $5 |
Picaxe Bidrectional Bus
This bus system allows any picaxe to send data to the bus, receive data from the bus and run background processes including reading and writing data to other pins. It contains several workarounds for the well documented problem of Serin hanging the picaxe until data arrives:

Echo code for testing:
main:high 0' flash led
pause 100
low 0
pause 100
gosub checkbus
goto main
checkbus:
if pin4=1 then' if bus is high
do
if pin4=0 then exit' wait till goes low
loop
serin 4,N2400,("Data"),b0,b1' get the data
gosub senddata
endif
return
senddata:
high 4
pause 200' initialise pulse to bus
low 4
pause 10' short delay to let serin settle
serout 4,N2400,("Data",b0,b1)
let dirs = %00000000' set back as input
return
Notes:
1) Data is initialised with a 200ms high pulse. If the bus is not high, then the code skips the serin and avoids locking up the picaxe. The led keeps flashing and/or any other code keeps executing. The only restriction is the main loop must check the input at least 5 times a second.
2) Data going out onto the bus is via the diode. Data coming back from the bus is via the 10k resistor. The bus is pulled low in one place with a 1k resistor.
3) The senddata code sets the pins back as inputs with the let dirs command. Note that some other commands may not necessarily set the pin back as an input, eg readadc does not (check with a multimeter for high Z vs L). The let dirs output will reset other outputs to L and if this is not intended, then the values can be stored in a register and an 'or' with this data used. Alternatively, brief low pulses to some devices may not matter if they are immediately set high afterwards - eg leds and relays.
4) For testing purposes the bus can be set up with two picaxes, one with this code and one with only senddata code. This code echos data back to the bus with no delay, but delays can be introduced if needed.
5) Working circuits may not need the led. There are thus 4 free pins for inputs and outputs on an 08/08M.
6) Pin 2 is pulled low on this schematic. This is for a system where the picaxe is programmed elsewhere. For systems where the picaxe is programmed in-situ, this will use the standard 22k/10k network on pin2 and will tie up pin0 for comms back to the PC.
7) Components not shown are the 5V regulator and 33uF/0.1uF across the power supply rail, plus one 0.1uF for every few chips.