Trouble getting values with I2C using HAL_Library

Former Member
Former Member

I cant get values with I2C using HAL_Library .I use HAL_I2C_Mem_Read and I cant manage ,maybe my adress wrong I didnt understand please help

int main(void)
{

HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();
LCD_Init(_LCD_4BIT, _LCD_FONT_5x8, _LCD_2LINE );
Setup_Acc();

while (1)
{
//sprintf(abc,"%3.2f",sonuc1);
// LCD_Out(1,1,abc);
HAL_GPIO_WritePin(GPIOD, LED1_Pin, GPIO_PIN_SET);
HAL_I2C_Mem_Read(&hi2c1,ADXL345_deviceAdress_w,INT_SOURCE,I2C_MEMADD_SIZE_8BIT,a,1,1000);
HAL_Delay(200);
while((a[0] & 0x80) == 0)
{
HAL_Delay(200);
HAL_I2C_Mem_Read(&hi2c1,ADXL345_deviceAdress_w,INT_SOURCE,I2C_MEMADD_SIZE_8BIT,a,1,1000);
}
HAL_GPIO_WritePin(GPIOD, LED2_Pin, GPIO_PIN_SET);

HAL_I2C_Mem_Read(&hi2c1,ADXL345_deviceAdress_w,DATAXL_INC,I2C_MEMADD_SIZE_8BIT,out,2,1000);
HAL_GPIO_WritePin(GPIOD, LED3_Pin, GPIO_PIN_SET);

sonuc = (int16_t)(((uint16_t)out[0]<<8) | out[1]);
sonuc1 = sonuc*0.004F;

}
}

void Setup_Acc()
{
if(HAL_I2C_IsDeviceReady(&hi2c1,ADXL345_I2C_Adress,5,100)==HAL_OK)
{
degisken[0]=0x0D;
HAL_I2C_Mem_Write(&hi2c1,ADXL345_deviceAdress_w,BW_RATE,1,degisken,1,50);
degisken1[0]=0x08;
HAL_I2C_Mem_Write(&hi2c1,ADXL345_deviceAdress_w,POWER_CTL,1,degisken1,1,50);
}
}

Parents Reply Children