stm32l432kc with bme280 code

02 Aug 2019

I am very new to microprocessors and trying to connect stm32l4 with bme280. I really don't even know where to start. andy articles, books and/or advise you can give me to start?

Thanks in advance robert

  1. include "mbed.h"

I2C i2c( D0, D1 ); Serial pc( USBTX, USBRX ); int bme280_sensor_addr = 0x77 << 1;

int main() { i2c.frequency (100000); char data[10]; char id_register_value[1] = {0xD0}; i2c.write( bme280_sensor_addr, id_register_value, 1, true ); data[1] = 0;

i2c.read( bme280_sensor_addr, data, 1, false ); pc.printf( "ID = %2x\r\n", data[0] );

char temp_register[1] = {0xFA << 8 | 0xFB}; i2c.write( bme280_sensor_addr, temp_register, 2, true );

char temp_data[2] = {0, 0}; i2c.read( bme280_sensor_addr, temp_data, 2, false );

int temp_value = ((int)temp_data[1] ) | temp_data[0]; pc.printf( "Temp = %d\r\n\n", temp_value );

}

You need to log in to post a reply