cancel
Showing results for 
Search instead for 
Did you mean: 

MPL115A2 withSTM32 NUCLEO-H723ZG

knowit-jos
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3

@knowit-jos wrote:

I didn't find Driver of MPL115A2 for STM32


It's an NXP part!

https://www.nxp.com/products/sensors/pressure-sensors/barometric-pressure-15-to-150-kpa/absolute-digital-pressure-sensor-50-to-115-kpa:MPL115A 

https://community.nxp.com/t5/Sensors/bd-p/sensors 

But the part neither knows nor cares what microcontroller you use - all it sees are transaction on the I2C bus

https://www.nxp.com/docs/en/application-note/AN3785.pdf

 

Thank you for your reply, is there any example function how to get proper data from the sensor?

Best regards

 

NXP would be the ones to ask for that ...