Notifications
Clear all

[Solved] Help needed with I2C and wire.h

18 Posts
3 Users
1 Likes
8,230 Views
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

Thanks for the functions. Unfortunately, they don't solve the problem.

An example:

If I want to save 30 seconds in reg1, 20 minutes in reg2 and 4 hours in reg3.

Then I have to write 0x30, 0x20 and 0x04 to the first three registers.

The registers store the actual real-world values as hexadecimal. Which would certainly make doing maths with them difficult.


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

The solution seems to be as follows.

Assume I want to change decimal 23 to 0x23.

x = 2

y = 3

z = x << 4

z |= y

 The binary result being 0010 0011

or 2 for the high byte

 & 3 for the low byte.

Which is how the register stores its values.


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

My apologies Scott.

One of the functions did work, it was just that my brain turned to mush yesterday, due to the temperature being in the high nineties and no aircon, now we are back down to mid-seventies, my brain has started functioning as it should.

Another case of not seeing the wood for the trees!


   
ReplyQuote
Page 2 / 2