In my attempt to control a device by I2C (programmable power supply), as a first time I2C user, I found the wire lib to be somewhat hard to implement.
It requires the correct sequence of commands that is not always easy to understand, especially the setting of sub addresses.
All one needs is to read and write to the device internal registers (sub address) and let the library do all internal settings and checks.
Had I been an expert, I would have modified the library by adding just 2 user functions, as follows:
- //Reading a sequence of bytes from a sub address into a byte or char array
I2CgetData(uint8_t device_address, uint8_t sub_address, uint8_t data_length)
2.//Writing up to 4 bytes (the default buffer size) to a sub address
I2CsetData(uint8_t device_address, uint8_t sub_address, uint32_t data) //can be 8,16,or even 64.
This is all the user needs. All other functions (like setTransmit, Read(), Write(), etc. etc) can and should be handled by the Wire library.
Does this make sense?
Is there an expert out there who can take up the challenge and make the I2C simple to implement?
I will willingly help by testing a beta!.