Hi Guys.. I2C communication has bedevilled for far too long and i'm now trying to face my fears!
Alright, so when i see an i2c code example in c, that someone has written, I will understand it.
I will understand what's going on and it makes sense.
However, i'm unable to write my own I2C code !!![😭]()
Ok ok, look here.. I have this 15 page long datasheet.. https://www.mouser.ca/datasheet/2/609/M ... 127679.pdf
At the end of page 11, bottom right. It says that device/slave address is 0110110 = 0x36 but then it also says: The 7-bit slave address is fixed to
6Ch (write)/6Dh (read):
I dunno, perhaps i'm terrible at understanding this but i'm assuming that 0x6C write and 0x6D read need not be explicitly written and
the read and write pico function for the i2c actually takes care of this
example :
Ok, so as you can seehas the addr for the device address which I want the pico to communicate with
and VERSION is the register where I want to read from.
Then i do Again.. since I've already performed a write
to let the device know that I will be reading from the VERSION register, i go ahead and do the read but
the result comes off as 00.0000 as if nothing is being read which i believe is the case.
I've seen the MPU6050 motion sensor example for the pico. very easy to comprehend but
this MAX17043 is just weird. i feel like my tiny example code is missing something..
or there's something I don't understand or have overlooked in the datasheet.
PLEASE HELP!
Alright, so when i see an i2c code example in c, that someone has written, I will understand it.
I will understand what's going on and it makes sense.
However, i'm unable to write my own I2C code !!
Ok ok, look here.. I have this 15 page long datasheet.. https://www.mouser.ca/datasheet/2/609/M ... 127679.pdf
At the end of page 11, bottom right. It says that device/slave address is 0110110 = 0x36 but then it also says: The 7-bit slave address is fixed to
6Ch (write)/6Dh (read):
I dunno, perhaps i'm terrible at understanding this but i'm assuming that 0x6C write and 0x6D read need not be explicitly written and
the read and write pico function for the i2c actually takes care of this
example :
Code:
#define VERSION 0x08 // returns IC versionint static addr = 0x36; // device address#define I2C_PORT i2c0// get the max1704x version.static void get_VERSION(){ uint16_t version = 0; uint16_t buffer[2]; i2c_write_blocking(I2C_PORT, addr, VERSION, 1, true); i2c_read_blocking(I2C_PORT, addr, buffer, 2, false); version = buffer[0] << 8 | buffer[1]; printf("Device version: %f\n", version); }int main() { stdio_init_all(); printf("Hello, MAX17043/MAX17044 battery charging something something testing... \n"); // This example will use I2C0 on the GPIO4 (SDA) & GPIO5 (SCL) i2c_init(I2C_PORT, 400 * 1000); // set i2c clock speed to 400khz gpio_set_function(4, GPIO_FUNC_I2C); gpio_set_function(5, GPIO_FUNC_I2C); gpio_pull_up(4); gpio_pull_up(5); while(1){ get_VERSION(); sleep_ms(1000); } }
Ok, so as you can see
Code:
i2c_write_blocking(I2C_PORT, addr, VERSION, 1, true);
and VERSION is the register where I want to read from.
Then i do
Code:
i2c_read_blocking(I2C_PORT, addr, buffer, 2, false);
to let the device know that I will be reading from the VERSION register, i go ahead and do the read but
the result comes off as 00.0000 as if nothing is being read which i believe is the case.
I've seen the MPU6050 motion sensor example for the pico. very easy to comprehend but
this MAX17043 is just weird. i feel like my tiny example code is missing something..
or there's something I don't understand or have overlooked in the datasheet.
PLEASE HELP!
Statistics: Posted by Gitduino — Sat Jan 13, 2024 4:55 am