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); } }
You might have more answers if you :
So, first does HAL_I2C_IsDeviceReady(&hi2c1,ADXL345_I2C_Adress,5,100) returns HAL_OK ?
HAL_I2C_IsDeviceReady(&hi2c1,ADXL345_I2C_Adress,5,100)
HAL_OK
Also it seems that most examples set the clockrate before checking if the device is ready, like this :
to_send = ACCEL_RATE_100KHZ;HAL_I2C_Mem_Write(I2C_device, ACCEL_ADDR, ACCEL_BW_RATE, sizeof(uint8_t), to_send, sizeof(uint8_t), 100);HAL_I2C_IsDeviceReady(I2C_device, ACCEL_ADDR, 1, 100);
Using 0x53 for the Accelerator address.
This might help you :
https://github.com/erebus-labs/sense_platform/blob/master/MAIN_3_20.c
The examples here github.com/.../ADXL345.cpp appear to simply do a 6 byte-read from the DATA_X0 address. No conversion done. That said, the official documentation state that in I²C mode, you might need to offset the register address in some conditions. But I have no idea what these conditions are : www.analog.com/static/imported-files/data_sheets/ADXL345.pdf Try a simple 6 bytes read from DATA_X0 and see if you get something useful. github.com/.../ADXL345.cpp