cancel
Showing results for 
Search instead for 
Did you mean: 

Accelerometer reading is always 0x00

Posted on July 31, 2015 at 02:16

Hey

I'm trying a new board, this is the stm32f411e-disco and I can't read acc. values, they are always 0x00

I've generated the project with STM32CubeMX V4.9.0

The config and the main code are below:

0690X00000605TIQAY.png

&sharpinclude ''stm32f4xx_hal.h''

I2C_HandleTypeDef hi2c1;

HAL_StatusTypeDef acc_ready, acc_read;

uint8_t readXYZ[6];

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_I2C1_Init(void);

int main(void)

{

  HAL_Init();

 

  SystemClock_Config();

 

  MX_GPIO_Init();

  MX_I2C1_Init();

  HAL_I2C_MspInit(&hi2c1);

 

  while (1)

  {

    HAL_Delay(1000);

    HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15);

   

    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);

    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);

   

    //  HAL_OK       = 0x00

    //  HAL_ERROR    = 0x01

    //  HAL_BUSY     = 0x02

    //  HAL_TIMEOUT  = 0x03

    acc_ready = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t) 0x33, (uint32_t) 1, (uint32_t) 1);

    switch(acc_ready) {

    case HAL_OK:

      HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);

      acc_read = HAL_I2C_Mem_Read(&hi2c1, 0x33, 0x28, I2C_MEMADD_SIZE_8BIT, &readXYZ[0], 6, 1);

      break;

    default:

      HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);

      break;

    }

   

  }

}

#stm32f4 #i2c #accelerometer
0 REPLIES 0