-
PICtoPIC by 1-wire
Hi all
I have some problems to connect 2 PIC16F648A using portB.0 with OWIN/OWOUT command.
The PIC-1 (master) call PIC-2, like an iButton, with this code that I cann't change:
----------------------
IB VAR BYTE[8]
OWOUT PortB.0, 1, [$33]
PAUSE 5
OWIN PortB.0, 0, [STR IB\8]
----------------------
The PIC-2 must to reply at PIC-1 reset with "presence" pulse, read "$33" and send it 8 byte.
Is it possible do it with PBP without ASM code?
Can anyone help me with ASM code if indispensable?
Thank in advance
cip
-
Cip,
PIC to PIC connection using 1-Wire is not that simple.
when using OWIN / OWOUT both the PICs claim to be a master.
I have already spent hours to write a 1-Wire slave routine for the PIC, no success so far.
What you could do is: use SerIn / SerOut
When Idle your Slave is in a SerIn loop
As soon as it has been "called" it replies on the same Port using SerOut.
The Master "calls" the Slave using SerOut and after sending its Bits it listens on the same port for the slaves reply using SerIn.
Even this will require some lines of code to get the timing right and make it fail safe, assuming the slave has more to do than looping waiting for it's masters call.
If you can afford to use some more port Bits (up to 3)
"handshaking" will be easier.
@all members
Does anyone have a better solution ?
rgds.
-
Thank you for reply.
I'm huppy: my question is not so stupid! :)
I *must* use only PortB.0 pin and reply to PIC-1 like an iButton.
I write this routine for PIC-2 (work fine without ONE error with OSC_INT at 4 MHz):
------------------------
LOOP:
input PortB.0
'wait reset pulse
WAIT_L:
if PortB.0 = 1 then WAIT_L
WAIT_H:
if PortB.0 = 0 then WAIT_H
'tPDH
pauseus 15
'start PRESENCE pulse
low PortB.0
pauseus 60
high PortB.0
'tRSTH
pauseus 450
' read Function Command ($33)
owin PortB.0, 0, [FC]
goto LOOP
---------------------------
But I don't know to continue... :-(
I can send to PIC-1 only a correct byte with OWOUT command, no more.
I think the problem is the timing...
Thanks
cip
-
I guess it's a bit more than just the timing . . .
You will have to shift the bits in and out "manually"
and your Slave Routine will have to interrupt driven.
This is probably a good questions to our Experts (Melanie?)
As Mentioned earlier: I haven't had any luck yet to run a PIC as 1-Wire Slave.
But if you manage to get this working I would be interested in your solution.
rgds:
-
You need something such as a shift left.
For example a reciever:
counter var byte
result var byte
Loop:
result =0
for counter=0 to 7
'Here you check for your sending bit
Loop2:
if Portb0.0=then Loop2
'Here you do NOT go ahead, unless the bit goes to zero
Loop3:
if portb0.0=1 goto Loop3
Pauseus 50 'Wait until transmitter has time toggle bit
'Here you put your bit into register and shift left to add.
'If you do it 8 times, you have a complete byte
result=Portb0.0
result=result << 1
Pause 1 'Give time for transmitter to toggle bit to 0
next counter
Transmitter:
Dcounter var byte
counter var byte
number var byte
T var Porta.bitoftransmitter
DigNumber var byte
number=2468
for counter=7 to 0 step -1
DigNumber=Dig Number 7
for Dcounter=0 to 7
High T
pauseus 10 'remember, you can't go past 50us,because of reciever
Low T
T=DigNumber0.7
pauseus 20 'enough time for receiver to read!!
T=0 'TURN IT OFF!!!!!
DigNumber.7=DigNumber.7 <<1
Pause 1 'give time for receiver to do its job
Next Dcounter
Pause 100 '(give time for display to print it out)
Next counter
Dwayne
-
one wire slave
Hi Everibody
Anyone as implemented 1-wire slave with Pic?
I want to start it, any help will be great!
Regards
Chip