2022-01-20 11:22 AM
Hello I was hoping to get some guidance on what the best way to read an 8bit register, clear and set a few bits, then write back to the same register using the HAL_Transmit function.
I am using a TI LP55231 9 Channel LED driver. Datasheet is located here: https://www.ti.com/lit/ds/symlink/lp55231.pdf
My issue is when I read the registers and step through the code I am not getting the values I am expecting and I believe it has something to do with how the variable types do not match as one is a uint8_t and the other is a pointer.
I got this code originally from github as a place to start located here:
https://github.com/jonathanrjpereira/LP55231-Programmable-9-LED-Driver
The provided code seems to give just very basic user functions but I wanted to expand on the library and see if I could add a few more features to it. I started by testing the existing code and realized some of it is not functional. Such as the channel mapping function and this is how I got to where I am.
The code below are some of the functions where I am getting the warnings "warning: passing argument 5 of 'HAL_I2C_Mem_Read' makes pointer from integer without a cast [-Wint-conversion]"
however if I changed it to a pointer I get errors about preforming logic operations on pointers.
If you would like me to post my entire code I will but Its not to far off from what was posted at the github link. I just adapted it to work on the STM32G0 and cut a few things out as I am using 9 white LEDs instead of 3 RGB.
Thanks.
What is the best way to reslove this issue?
Thanks
/*
* @brief Selects dimming mode i.e. Log/Linear scale
* @param channel: LED channel number (0-8)
* @param control: 0: Linear, 1: Log
* @retval Status
*/
enum lp_err_code Log_Dimmer_CNTRL(uint8_t channel, bool control){
if(channel >= Total_Channels){
return LP_ERR_INVALID_CHANNEL;
}
uint8_t reg;
HAL_I2C_Mem_Read(&hi2c1, (uint16_t)(LP55231_ADDR<<1) |0x01, (D1_CNTRL) + channel, 1, reg, 1, 50);
uint8_t config = control ? LOG_EN : 0x00;
reg &= ~(0x20);
reg |= config;
HAL_I2C_Mem_Write(&hi2c1, (uint16_t)(LP55231_ADDR<<1), (D1_CNTRL) + channel, 1, ®, 1, 50);
return LP_OK;
}
/*
* @brief Assigns a channel to a specific Master Fader
* @param channel: LED channel number (0-8)
* @param fader_mode: 0: No Mapping, 1: Master Fader 1, , 2: Master Fader 2, 3: Master Fader 3
* @retval Status
*/
enum lp_err_code Master_Fader_Map(uint8_t channel, uint8_t fader_mode){
if(channel >= Total_Channels){
return LP_ERR_INVALID_CHANNEL;
}
uint8_t reg = 0, config;
HAL_I2C_Mem_Read(&hi2c1, (uint16_t)(LP55231_ADDR<<1) |0x01, (D1_CNTRL) + channel, 1, reg, 1, 50);
config = fader_mode;
config <<= 6;
reg &= ~(0xC0);
reg |= config;
HAL_I2C_Mem_Write(&hi2c1, (uint16_t)(LP55231_ADDR<<1), (D1_CNTRL) + channel, 1, ®, 1, 50);
return LP_OK;
}
Solved! Go to Solution.
2022-01-20 04:41 PM
Your memory read functions use “reg�? where they should be using “®�?.
2022-01-20 04:41 PM
Your memory read functions use “reg�? where they should be using “®�?.