Jump to content

Can't get BME280 to work with MSP430g2554

Recommended Posts


I'm using energia 1.6.10E18 with the launchpad MSP430G2 and the MSPG2553 installed. 
So I saw that in another forum the library from cactus.io was used for the BME280. 
That library was for the I2C. Now I want to use the SPI library and they had one.(http://cactus.io/hookups/sensors/barometric/bme280/hookup-arduino-to-bme280-barometric-pressure-sensor-spi).
So I installed the library changed it to hardware SPI with the cs pin on P2_1. And it compiled, but i'm only getting these results:

813.81 mb    100.00 %        0.00 *C    32.00 *F
813.81 mb    100.00 %        0.00 *C    32.00 *F
813.81 mb    100.00 %        0.00 *C    32.00 *F
813.81 mb    100.00 %        0.00 *C    32.00 *F

It looks like the msp430 is not getting any data in/out.
I probed the SPI connections with my oscilloscope en there is literally nothing happening.
While with the basic example sketch I can clearly see what code is sending.

Can anyone help me understand this problem and hopefully fix this.
I want the SPI connection to work because I want the nrf24l01 and BME280 working side by side.
The msp430 can't do SPI and I2C together like an arduino so you need to chose between them.

This is the code I'm using and the library on the website.

#include <SPI.h> 
#include "cactus_io_BME280_SPI.h" 

#define BME_CS P2_1

BME280_SPI bme(P2_1);

void setup() { 

Serial.println("Bosch BME280 Pressure - Humidity - Temp Sensor | cactus.io"); 

if (!bme.begin()) { 
Serial.println("Could not find a valid BME280 sensor, check wiring!"); 
while (1); 


void loop() { 


Serial.print(bme.getPressure_MB()); Serial.print(" mb\t"); // Pressure in millibars 
Serial.print(bme.getHumidity()); Serial.print(" %\t\t"); 
Serial.print(bme.getTemperature_C()); Serial.print(" *C\t"); 
Serial.print(bme.getTemperature_F()); Serial.println(" *F"); 

// Add a 2 second delay. 
delay(1000); //just here to slow down the output. 




Link to post
Share on other sites

Thanks Rei Vilo for the anwser!
I have it working on the hardware pins 14 (SCL) 15 (SDA). But when I try to switch it to pin 9 (SCL) and 10 (SDA) the I2C lines are dead.
I'm using 4.7K pull up resistors and a vcc of 3.3V, I don't know what I am doing wrong.
For the hardware pins I used :       Wire.setModule(1);

And for the software pins I use:   Wire.setModule(0);

I also tried to remove the Wire.setModule and set it to -1 but still no luck.

I have tested this with a I2C scanner.
I hope that you can help me further!

#include <Wire.h>

void setup()

void loop()

uint8_t fromAddress = 0;
uint8_t toAddress = 127;

void findAddress()
  for (uint8_t a = fromAddress; a < toAddress; a++)
    int endStatus = Wire.endTransmission();

    if (endStatus == 0)
      Serial.print("Found device at: 0x");
      Serial.println(a, HEX);


Link to post
Share on other sites

So I tried again the scanner and put my oscilliscope on the I²C lines.
I found out that there is something happening but not the way it supposed to be.
As you can see in the screen caps (yellow is SCL en blue is SDA) mode 0 is working fine.20180518150758.png.82adc59aac593917adce37f2b71476aa.png


But when I switch to mode 1 / default. only some low to high transmission is measured on the SDA pin.
It looks like the clock pin is trying something but it is forced high.


Even when it remove the pull-up resistors and the BME280 nothing happens.
I have tried every possible way: removing the pull-up resistors and leave the BME280, removing the BME280 and leaving the pull-up resistor and I have removed anything from the I²C line and just probe them.

How is it possible that in another form post this all is working but not in my case? 

I hope you can answer this or I need to find another low power MCU.

Link to post
Share on other sites

The I²C port on pins 9 and 10 (module 1) is simulated and may not support advanced features like clock stretching. 

I recommend you to use pins 14 and 15 (module 0) with the hardware I²C.

Have you tried with another board?

I tried with a BME280 I have at hand, but I can't manage to read the data whatever the board. 

Link to post
Share on other sites

I managed to get my BME280 working.

The error was a wrong address.

The library was set to 0x77 by default while my sensor had 0x76 configured. See https://github.com/adafruit/Adafruit_BME280_Library/issues/15


  • Emulated I²C on pins 9 + 10 works with Energia 17.


  • Hardware I²C on pins 14 + 15 does not work with Energia 17.


  • Hardware I²C on pins 14 + 15 works with Energia 12.


As an additional benefit for Energia 12, the code is more compact!

I opened a ticket at https://github.com/energia/msp430-lg-core/issues/62.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...