Question
Problem setting registers on I2C slave device
I've read through a couple other posts but haven't fount anything that helps me. I am trying to set some registers on a MMC5883 digital magnetometer and can't seem to write to the correct registers. I initialized I2C1 using the graphical Device Configuration Tool, the slave 7-bit address is 0x30. I have PB7 as SDA and PB6 as SCL.
When I go through the debugger the error seems to be at the "status = HAL …." line, as it never returns HAL_OK.
void set_MAG_Regs(){
printf("setting mag slave registers... \n\r");
HAL_StatusTypeDef status = HAL_OK;
int i = 0;
int data [3] = {0x08, 0x03, 0x01};//array of data to set registers
int addr [3] = {0x08, 0x09, 0x0A};// array data location
int *register_value;//points to data[]
int *register_pointer;//points to addr []
register_value = &data[i];
register_pointer = &addr[i];
for (i=0; i<4; i++){
status = HAL_I2C_Mem_Write(&hi2c1, 0x30, (uint16_t)register_pointer, I2C_MEMADD_SIZE_16BIT,(uint8_t*)(®ister_value), 2, HAL_MAX_DELAY);
if (status != HAL_OK){
//error handling
Error_Handler();
printf("Device failed to set registers \n\r");
}
i++;
}
}