I compiled my code without any errors but got this Warning ..I know it just a warning but could it have been written a better way so it doesn't generate an error ??
This is the code.Also,
This is the Arduino code for the operationsCan it be written in a more concise, better way than the horrible translation I have done for the pico version above ??
Thanks,
Code:
battery.c:161:40: warning: passing argument 3 of 'i2c_write_blocking' from incompatible pointer type [-Wincompatible-pointer-types] 161 | i2c_write_blocking(I2C_PORT, addr, &new_CONFIG, 3, false); // write new value to CONFIG register. | ^~~~~~~~~~~ | | | uint8_t (*)[3] {aka unsigned char (*)[3]}
This is the code.
Code:
static void setThreshold(uint8_t limit){ uint8_t CONFIG = 0x0C; uint8_t configReg[2] = {0}; uint8_t new_CONFIG[3] = {0x0C, 0x00, 0x00}; uint8_t buffer[2] = {0}; limit = (uint8_t) constrain((float)limit, 0.0, 32.0); limit = 32 - limit; // Read config reg, so we don't modify any other values: i2c_write_blocking(I2C_PORT, addr, &CONFIG, 1, true); i2c_read_blocking(I2C_PORT, addr, buffer, 2, false); // get default threshold value. new_CONFIG[1] = buffer[0]; new_CONFIG[2] = buffer[1]; new_CONFIG[1] &= 0xFF; new_CONFIG[2] &= 0xE0; // Mask out the threshold bit of the bits new_CONFIG[2] |= percent; i2c_write_blocking(I2C_PORT, addr, &new_CONFIG, 3, false); // write new value to CONFIG register. }
This is the Arduino code for the operations
Code:
uint16_t configReg = read16(MAX17043_CONFIG);configReg &= 0xFFE0; // Mask out threshold bitsconfigReg |= percent; // Add new threshold
Thanks,
Statistics: Posted by Gitduino — Mon Jan 22, 2024 2:31 am — Replies 3 — Views 100