Writing to slave i2c device always gets stuck. Compiles with no errors...
I'm setting some registers on a slave device using the code bellow. The code compiles with no errors but gets stuck each time it tries to write to that register. What I want to do is loop through the for loop and set each register to it's corresponding value .
It always gets stuck at this part of the write command:
while (__HAL_I2C_GET_FLAG(hi2c, Flag) == Status)
which I think means it is communicating, but if I use the same code but hard-code the register locations and data values it works fine, so I'm thinking it must be something to do with the way I'm handling those arrays.
My code segment:
void set_Regs(){
//read register 0x07, check bit 7 or 0?
int i=0;
for(i=0; i<3; i++){
uint8_t reg_addr[] = {0x08, 0x09, 0x0A};
uint8_t reg_data[] = {0x08, 0x03, 0x01};
uint8_t reg_point = reg_addr[i];
uint8_t data_point = reg_data[i];
if(HAL_I2C_Mem_Write(&hi2c1, (0x30<<1),reg_point,sizeof(reg_addr), (uint8_t*)(&data_point) , sizeof(reg_data), HAL_MAX_DELAY) != HAL_OK){
Error_Handler();
printf("Error Setting Registers \n\r");
}
}
}