energia / msp430-lg-core

15 stars 12 forks source link

MSP430FR4133 — Issue with I²C #55

Closed rei-vilo closed 6 years ago

rei-vilo commented 6 years ago

The MSP430FR4133 uses software I²C on pins 9 and 10 for compatibility. However, only SCL signal seems to be generated.

The same sketch with the same INA226 BoosterPack works fine on the MSP430FR6989 LaunchPad. According to the schematics, SCL and SDA have 10 kΩ pull-up resistors.

I'm using MSP430 boards package release 1.0.3.

capture 2018-01-31 a 09 42 16

#include "Wire.h"

#define INA226_I2C_ADDRESS 0x40
#define INA226_REGISTER_MANUFACTURER_ID 0xfe
#define INA226_REGISTER_DIE_ID          0xff

int16_t read16(uint8_t address)
{
  int16_t value = 0;

  Wire.beginTransmission(INA226_I2C_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();

  Wire.requestFrom(INA226_I2C_ADDRESS, 2);
  while (Wire.available() < 2)
  {
    Serial.print(".");
  }

  value = Wire.read();
  value <<= 8;
  value += Wire.read();

  return value;
}

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  Serial.print("5449 ? ");
  Serial.println(read16(INA226_REGISTER_MANUFACTURER_ID), HEX); // 5449
  Serial.print("2260 ? ");
  Serial.println(read16(INA226_REGISTER_DIE_ID), HEX); // 2260
  delay(100);

}
StefanSch commented 6 years ago

Can you please check if both (SDA and SCL) have pull up resistor on the BoosterPack.

rei-vilo commented 6 years ago

Yes, the schematics shows both SCL and SDA have 10 kΩ pull-up resistors.

11- wcs033a boosterpack _sch

rei-vilo commented 6 years ago

Same happens with the Sensors BoosterPack and the WeatherSensors_Demo example.

TMP007_internalTemperature 0.00°C TMP007_externalTemperature 0.00°C OPT3001_light 0.00lux BME280_pressure 0.00hPa BME280_temperature 0.00°C BME280_humidity 0.00%

boostxl-sensors_schematic

StefanSch commented 6 years ago

The sensor BoosterPack has the I2C on pins 14 and 15 while the default for Energia is 9 and 10.

So you have to add Wire.setModule(0);

StefanSch commented 6 years ago

Hope this helps - if not let me know and i will debug into it.

rei-vilo commented 6 years ago

Here are the results of my tests

Wire.setModule Pins Result
Wire.setModule(0); 14 + 15 5449 =? 5449
Wire.setModule(1); 14 + 15 5449 =? 0
Wire.setModule(0); 9 + 10 5449 =? ................ERROR
Wire.setModule(1); 9 + 10 5449 =? 0
Wire.setModule Pins Result
Wire.setModule(1); 9 + 10 5449 =? 5449
No Wire.setModule = default = 1 9 + 10 5449 =? 5449
#include "Wire.h"

#define INA226_I2C_ADDRESS 0x40
#define INA226_REGISTER_MANUFACTURER_ID 0xfe

void setup()
{
    Serial.begin(9600);
    Wire.setModule(0);
    Wire.begin();
    delay(100);

    Serial.println("Test MSP430FR2433 I2C with INA226");
    Serial.println("Wire.setModule(0);");
    Serial.println("----");
    Serial.print("5449 =? ");

    Wire.beginTransmission(INA226_I2C_ADDRESS);
    Wire.write(INA226_REGISTER_MANUFACTURER_ID);
    Wire.endTransmission();

    uint16_t count = 16;
    uint16_t value = 0;
    Wire.requestFrom(INA226_I2C_ADDRESS, 2);
    while ((Wire.available() < 2) and (count > 0))
    {
        delay(100);
        Serial.print(".");
        count--;
    }

    if (count > 0) {
        value = Wire.read();
        value <<= 8;
        value += Wire.read();
        Serial.println(value, HEX);
    } else {
        Serial.println("ERROR");
    }
    Serial.println("====");

}

void loop()
{

}
StefanSch commented 6 years ago

A little bit confused now - which launchpad shows the error: MSP430FR4311 (title say 4133 but that does not exist) MSP430FR2433 (as in the last comment)?

rei-vilo commented 6 years ago

Sorry, the LaunchPad with issues is the MSP430FR4133. The reference LaunchPad that works is the MSP430FR6989.

StefanSch commented 6 years ago

fixed in branch issue_55