Problem With Local Bytes
JonnyMac
Posts: 9,107
in Propeller 2
While working on my I2C routines, I did this test
If I change to this:
@cgracey Is the a problem with PNut? I'm using v34n.
pub main() | device, addr, slaveid, last, byte s, m, h setup() ' write 23:59:45 to rtc s := $45 m := $59 h := $23 i2c.start() i2c.write($D0) i2c.write($00) i2c.wr_block(@s, 3) i2c.stop() last := -1 repeat i2c.start() i2c.write($D0) i2c.write($00) i2c.start() i2c.write($D1) s := i2c.read(i2c.ACK) m := i2c.read(i2c.ACK) h := i2c.read(i2c.NAK) i2c.stop() if (s <> last) term.tx(term.HOME) term.fstr3(string("%2.2x:%2.2x:%2.2x"), h, m, s) last := s waitms(50)Only the seconds and minutes are written to the clock -- hours gets 0.
If I change to this:
pub main() | device, addr, slaveid, last, time, byte s, m, h setup() ' write 23:59:45 to rtc time := $23_59_45 i2c.start() i2c.write($D0) i2c.write($00) i2c.wr_block(@time, 3) i2c.stop() last := -1 repeat i2c.start() i2c.write($D0) i2c.write($00) i2c.start() i2c.write($D1) s := i2c.read(i2c.ACK) m := i2c.read(i2c.ACK) h := i2c.read(i2c.NAK) i2c.stop() if (s <> last) term.tx(term.HOME) term.fstr3(string("%2.2x:%2.2x:%2.2x"), h, m, s) last := s waitms(50)...the complete time is correctly written to the RTC. The only difference is using a local long vs local bytes.
@cgracey Is the a problem with PNut? I'm using v34n.
Comments
Edit: I just did a little test to confirm that the size override must be done per variable. In my original version m and h were longs.
In Spin2 the default size for locals can be overridden.
That is interesting...