MPL115A2 with STM32 NUCLEO-H723ZG

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MPL115A2 with STM32 NUCLEO-H723ZG

448件の閲覧回数
josalk
Contributor I

Hello! I didn't find Driver of MPL115A2 for STM32, I tried to create a simple one

I'm not able to get dynamic data from the sensor.

I connected it as below:

VDD > STM32 3.3V
GND > STM32 GND
SCL > PB8
SDA > PB9
HSR > not connected
SDWN > not connected

This is the code i'm trying

 

 

 

// MPL115A2 registers with bit shifts for I2C communication
#define MPL115A2_REG_PRESSURE_MSB   0x00 // Padc_MSB
#define MPL115A2_REG_PRESSURE_LSB   0x01 // Padc_LSB
#define MPL115A2_REG_TEMP_MSB       0x02 // Tadc_MSB
#define MPL115A2_REG_TEMP_LSB       0x03 // Tadc_LSB
#define MPL115A2_REG_A0_MSB         0x04 // a0_MSB
#define MPL115A2_REG_A0_LSB         0x05 // a0_LSB
#define MPL115A2_REG_B1_MSB         0x06 // b1_MSB
#define MPL115A2_REG_B1_LSB         0x07 // b1_LSB
#define MPL115A2_REG_B2_MSB         0x08 // b2_MSB
#define MPL115A2_REG_B2_LSB         0x09 // b2_LSB
#define MPL115A2_REG_C12_MSB        0x0A // c12_MSB
#define MPL115A2_REG_C12_LSB        0x0B // c12_LSB
#define MPL115A2_REG_CONVERT        0x12 // CONVERT

    // Perform a memory read to read the value from the specified register
    status = HAL_I2C_Mem_Read(
    		&hi2c1, 
    		(0x60<<1), // The i2c address of the device.
			reg, // the target registery address according the datasheet.
			I2C_MEMADD_SIZE_8BIT, // the memory size to get
			&value, //This is where to store the value from the device..
			1, // Store 1 byte.
			HAL_MAX_DELAY); // Maxmum delay.
    if (status != HAL_OK) {
        printf("I2C Memory Read Error: %d\r\n", status);
        return 0;
    }
    return value;
}



// Function to read temperature from MPL115A2
void readTemperature(void)
{

        printf(readRegister(MPL115A2_REG_PRESSURE_MSB));
	printf(readRegister(MPL115A2_REG_PRESSURE_LSB));
	printf(readRegister(MPL115A2_REG_TEMP_MSB));
	printf(readRegister(MPL115A2_REG_TEMP_LSB));
	printf(readRegister(MPL115A2_REG_A0_MSB));
	printf(readRegister(MPL115A2_REG_A0_LSB));
	printf(readRegister(MPL115A2_REG_B1_MSB));
	printf(readRegister(MPL115A2_REG_B1_LSB));
	printf(readRegister(MPL115A2_REG_B2_MSB));
	printf(readRegister(MPL115A2_REG_B2_LSB));  //    0x09
	printf(readRegister(MPL115A2_REG_C12_MSB)); //    0x0A
	printf(readRegister(MPL115A2_REG_C12_LSB)); //    0x0B
	printf(readRegister(MPL115A2_REG_CONVERT)); //    0x12
	printf(readRegister(0x0c));
	printf(readRegister(0x0d));
	printf(readRegister(0x0e));
	userConsole(readRegister(0x0f));

}

 while (1)
  {
       HAL_Delay(1000);
       readTemperature();
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

 

 

I'm getting data to console like this: (Static data, no temperature data):

71
71
68
68
170
170
126
126
181
181
89
89
58
58
208
208
13
0
0
0
14
0
0
0
96
15
0
0

 

 

any help is appricated.

Best regards

 

0 件の賞賛
返信
0 返答(返信)