Sign in to follow this  
Followers 0
TheArduinoGuy

Device resetting (MSP430FR5969) constantly

3 posts in this topic

I am trying to receive I2C data from a temperature sensor and print it to the Serial Monitor. The code works up to a point and then the device resets. I think it may be something to do with the Watchdog but not sure how to rectify it. Please help.

 

My code is...

#include <Wire.h>
#include <Si7006.h>

Si7006 tempNHum;

void setup() {

	// Initialize the Serial1 port:
	Serial1.begin(9600);
	Serial1.flush();
	delay(20);
	Serial1.println("Si7006-A20 example sketch");

	// Initialize the Si7006 library
	// You can pass nothing to light.begin() for the default I2C address (0x40)
	tempNHum.begin();

	if (!tempNHum.begin()) {
		Serial1.println("Couldn't find Si7006");
		while (1)
			delay(1); // Do Nothing
	}

	// Get factory ID from sensor:
	// (Just for fun, you don't need to do this to operate the sensor)

	char ID[8];

	if (tempNHum.getDeviceID(ID)) {
		Serial1.print("Got Sensor Part ID: 0X");
		// Default value of MSB 0x06
		for(int i = 0; i < sizeof(ID); i++) {
			Serial1.print(ID[i],HEX);
		}
		Serial1.println();

	}
	// Most library commands will return true if communications was successful,
	// and false if there was a problem. You can ignore this returned value,
	// or check whether a command worked correctly and retrieve an error code:
	else {
		byte error = tempNHum.getError();
		printError(error);
	}

	// Gets the Firmware Version of the chip
	// Default value is 0xFF for version 1.0 or 0x20 for version 2.0
	byte firmwareVer;

	if(tempNHum.getFirmwareVer(firmwareVer)) {
		Serial1.print("Got Sensor Firmware Version: 0X");
		Serial1.println(firmwareVer,HEX);
	}
	else {
		byte error = tempNHum.getError();
		printError(error);
	}

	// Gets the contents RH/Temp User Register of the sensor
	byte resolution;
	boolean voltage, heaterStatus;
	tempNHum.getTempControl(resolution, voltage, heaterStatus);
	Serial1.print("Resolution is: ");
	Serial1.println(resolution);

	// Setting the resolution and heater disable
	resolution = 0x00;
	heaterStatus = false;
	tempNHum.setTempControl(resolution, heaterStatus);

	// Getting heater current
	byte heaterCurrent;
	tempNHum.getHeaterControl(heaterCurrent);
	Serial1.print("Heater Current is ");
	Serial1.println(heaterCurrent);

	// Setting heater current
	tempNHum.setHeaterControl(heaterCurrent);
}


void loop() {
	float temp;
	float humidity;
	boolean mode = false;

	// Read temperature
	if(tempNHum.getTemperature(temp, mode)) {
		Serial1.print("Temp *C = ");
		Serial1.println(temp);
	}
	else{
		Serial1.println("Failed to read temperature");
		byte error = tempNHum.getError();
		printError(error);
	}

	// Read humidity
	if(tempNHum.getHumidity(humidity, mode)) {
		Serial1.print("Humidity = ");
		Serial1.print(humidity);
		Serial1.println("%");
	}
	else {
		Serial1.println("Failed to read humidity");
		byte error = tempNHum.getError();
		printError(error);
	}

  delay(1000);
}

void printError(byte error) {
  // If there's an I2C error, this function will
  // print out an explanation.

  Serial1.print("I2C error: ");
  Serial1.print(error,DEC);
  Serial1.print(", ");

  switch(error) {
    case 0:
      Serial1.println("success");
      break;
    case 1:
      Serial1.println("data too long for transmit buffer");
      break;
    case 2:
      Serial1.println("received NACK on address (disconnected?)");
      break;
    case 3:
      Serial1.println("received NACK on data");
      break;
    case 4:
      Serial1.println("other error");
      break;
    default:
      Serial1.println("unknown error");
  }
}

The output is...


Got Sensor Part ID: 0X2653FFFFFFB853FFFFFF8244FFFFFF8244
 
Got Sensor Firmware Version: 0X0
 
Resolution is: 0
 
HeaterSi7006-A20 example sketch
 
Got Sensor Part ID: 0X2653FFFFFFB853FFFFFF8244FFFFFF8244
 
Got Sensor Firmware Version: 0X0
 
Resolution is: 0
 
HeaterSi7006-A20 example sketch
 
Got Sensor Part ID: 0X2653FFFFFFB853FFFFFF8244FFFFFF8244
 
Got Sensor Firmware Version: 0X0
 
Resolution is: 0
 
HeaterSi7006-A20 example sketch
 
Got Sensor Part ID: 0X2653FFFFFFB853FFFFFF8244FFFFFF8244

As you can see, it gets as far as printing the word 'Heater' and then resets. Any ideas please?

 

Thanks in advance.

 

Mike.

Share this post


Link to post
Share on other sites

I see mention of a heater, could that be turning on and causing a glitch?

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
Sign in to follow this  
Followers 0