Jump to content
Germ

Can't get BME280 to work with MSP430g2554

Recommended Posts

Hello,

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.begin(9600); 
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); 
} 



Serial.println("Pressure\tHumdity\t\tTemp\ttTemp"); 
} 

void loop() { 

bme.readSensor(); 

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. 
}

   

20180517162604.png

20180517162622.png

Share this post


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);
                                                            Wire.begin();

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

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()
{
  Serial.begin(9600);
  Serial.println("Start!");
  
  Wire.setModule(0);
  Wire.begin();
}

void loop()
{
  findAddress();
  delay(1000);
}

uint8_t fromAddress = 0;
uint8_t toAddress = 127;

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

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

 

Share this post


Link to post
Share on other sites

The I²C implementation on pins 9 and 10 is software-based (or bit-banging). Some functions may work differently from the hardware ones. 

Let me try with a very standard I²C device. 

Share this post


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.

20180518153741.png.e485aad8fe0dfd432ffa4408dabef128.png

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.

Share this post


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. 

Share this post


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

Now,

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

5aff467e57f39_Capture2018-05-1823_28_52.thumb.png.5932d040276b7282f3caf8725e475b91.png

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

5aff4696cdbdf_Capture2018-05-1823_28_59.thumb.png.ec097f5b0d62483b476e9998248d1b7b.png

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

5aff468b8e60c_Capture2018-05-1823_28_55.thumb.png.1db640311fa6048fcffd1a51b4be281f.png

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.

Share this post


Link to post
Share on other sites

Rei Vilo you are the best!

Everything works fine in E17. Now I can finally move on with my project.

Thanks for all the help!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×