Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 9 months ago.
ADXL345 I2C problem(I'm new to ARM)
Codes are not working ,I m not going next HAL_I2C_IsDeviceReady(&hi2c1,ADXL345_I2C_Adress1,5,100) == HAL_OK is not working this is why HAL_I2C_Mem_Read(&hi2c1,ADXL345_I2C_Adress1,INT_SOURCE,I2C_MEMADD_SIZE_8BIT,a,1,1000); is not working as well. please help, I m stuck with it and I m going to my project.I can do with PIC but now time to ARM
GPIOs setted as very-high
void Setup_Acc(); uint8_t a[1]=0; uint8_t out[2]; char abc[15]; uint8_t degisken[1]; uint8_t degisken1[1]; int16_t sonuc=0; float sonuc1=5,sonuc2=10; 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_I2C_Adress1,INT_SOURCE,I2C_MEMADD_SIZE_8BIT,a,1,1000);
while((a & 0x80) == 0) { HAL_I2C_Mem_Read(&hi2c1,ADXL345_I2C_Adress1,INT_SOURCE,I2C_MEMADD_SIZE_8BIT,a,1,1000); }
HAL_GPIO_WritePin(GPIOD, LED2_Pin, GPIO_PIN_SET);
HAL_I2C_Mem_Read(&hi2c1,ADXL345_I2C_Adress1,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_Adress1,5,100) == HAL_OK) { degisken[0]=0x0D; HAL_I2C_Mem_Write(&hi2c1,ADXL345_I2C_Adress1,BW_RATE,1,degisken,1,50); degisken1[0]=0x08; HAL_I2C_Mem_Write(&hi2c1,ADXL345_I2C_Adress1,POWER_CTL,1,degisken1,1,50); } else { while(1) { HAL_GPIO_TogglePin(GPIOD, LED3_Pin); HAL_Delay(250); } } }