SOLVED: Converting DS1302 driver from P1 to P2 question
dgately
Posts: 1,630
Excuse my simplistic code conversion...
I'm sure there's a much simpler solution in Spin2, but I'm trying to start with a literal translation from P1 Spin. I'm trying to send out the command byte to the DS1302, one bit at a time, in the following excerpt:
dgately
I'm sure there's a much simpler solution in Spin2, but I'm trying to start with a literal translation from P1 Spin. I'm trying to send out the command byte to the DS1302, one bit at a time, in the following excerpt:
pub main() setup() wait_for_terminal(true) write_a_byte(%10000101) '' $85 DS1302 read hours command PRI write_a_byte( cmd ) | i '' P1 dira & outa version {{ dira[io]~~ ' set to output repeat i from 0 to 7 outa[io] := cmd ' send the LSB bit to the IO pin ??? outa[clk]~~ cmd >>= 1 outa[clk]~ }} '' P2 Spin2 methods repeat i from 0 to 7 if (cmd & %00000001 == 1) ' REPLACE: outa[io] := cmd for P2 ??? pinhigh(io) ' the masked bit is 1 else pinlow(io) ' the masked bit was 0 pinhigh(clk) cmd >>= 1 pinlow(clk)The Spin2 version does not yet work (timing issue or just bad coding?)
dgately
Comments
Changed my code, still not getting good results, but at least I think I understand how that piece of code works. Now, on to the rest of the code.
Here's a code snippet with commented-out working P1 code (compiles with flexprop):
OK... that's the correct P2 replacement, but it still just returns with datar as 0. Is there any other difference from the P1 code?
One more try and it works:
Thx