2 byte result
Farmer Scott
Posts: 30
I think I know the answer to this one, but was hoping someone could help me and verify...
I want to send a two byte I2C result as a return code from a public function, using the Basic I2C Driver from the object exchange...
Is this valid to assign both bytes to result:
Result[noparse][[/noparse]0] := I2C.Read(SCL, NAK)
Result[noparse][[/noparse]1] := I2C.Read(SCL, ACK)
Thanks in advance...
Scott
I want to send a two byte I2C result as a return code from a public function, using the Basic I2C Driver from the object exchange...
Is this valid to assign both bytes to result:
Result[noparse][[/noparse]0] := I2C.Read(SCL, NAK)
Result[noparse][[/noparse]1] := I2C.Read(SCL, ACK)
Thanks in advance...
Scott
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
result := I2C.Read(SCL, NAK) + I2C.Read(SCL, ACK)<<8
'result' is always a long, so you can pack up to 4 bytes in it. Here the first byte is in bits7..0 and the scond in bits 15..8.
To separate theme again:
first := result & 255
second := result >> 8
Andy
Thanks to both of you.· Andy's method looks a little cleaner, so I'm gonna give it a shot and see how things go, but appreciate both responses...
Thanks,
Scott