Jump to content
43oh

Recommended Posts

Launchpad noob from Arduino here.  I'm having trouble figuring out how to get a MAX31855 from Adafruit to work with the CC3200.   I've tried this library https://github.com/rocketscream/MAX31855 running the example code with no luck, when I open the serial monitor after initializing the sensor it's blank.  I know that everything is working correctly as far as uploading a sketch because I've ran several different sketches, including wifi, ones on this board with no problems so far.  I've tried the Adafruit library directly in this and that got me nowhere.  The issue with that library is that it makes specific calls to AVR code for Arduino which will not work with Energia as far as I can tell.  I tried hand porting the library and met with a little success, but that success was short lived as I was able to address the chip via SPI but all I ever received from it was 0.  In trying to port the Adafruit library I modified their code and removed the includes for avr and delay.  I replaced all of the _delay_ms calls with delay for this system.  I then plugged in the DO port from the MAX31855 to pin 14, CS to pin 18, and CLK to pin 7.  So far nothing.  I can't even get a readout on the serial monitor.  I tested the MAX and it's working with my Arduino just fine, the thermocouple that I have is crap but it does at least provide something.

Link to post
Share on other sites
  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

I think it's the pinMode() functions in the constructor. The GPIO peripheral modules haven't been activated by the time the C++ constructors execute so those pinMode's put the MCU into the Bus Error

@@Chuckymonkey - Try this little "patch", it's a zip file with 2 files that need to replace some files under Energia's install root (C:\energia-0101E0013 or wherever)   E13_cc3200_ctors_fix.zip  

  • 2 weeks later...

I do realize this, I'm reading the serial data from the USB plugged into energia.  I'm trying something different now, I think I've managed to port the Adafruit C++ library over to the MSP.  I think I was confused between software and hardware SPI.  I'm having some trouble getting energia to see the device right now(Linux) but once I have that I'll post the results.

Link to post
Share on other sites

Ok, so here's some code.  What's going on now is that nothing appears to be happening.  Everything compiles, it uploads the sketch, I pull the header and reset and...... nothing.

 

Here's the modified Adafruit Code:

/*************************************************** 
  This is a library for the Adafruit Thermocouple Sensor w/MAX31855K

  Designed specifically to work with the Adafruit Thermocouple Sensor
  ----> https://www.adafruit.com/products/269

  These displays use SPI to communicate, 3 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include "Adafruit_MAX31855.h"
#include <stdlib.h>
#include <SPI.h>


Adafruit_MAX31855::Adafruit_MAX31855(int8_t SCLK, int8_t CS, int8_t MISO) {
  sclk = SCLK;
  cs = CS;
  miso = MISO;
  hSPI = 0;

  //define pin modes
  pinMode(cs, OUTPUT);
  pinMode(sclk, OUTPUT); 
  pinMode(miso, INPUT);

  digitalWrite(cs, HIGH);
}

Adafruit_MAX31855::Adafruit_MAX31855(int8_t CS) {
  cs = CS;
  hSPI = 1;

  //define pin modes
  pinMode(cs, OUTPUT);
  
  //start and configure hardware SPI
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  
  digitalWrite(cs, HIGH);
}

double Adafruit_MAX31855::readInternal(void) {
  uint32_t v;

  v = spiread32();

  // ignore bottom 4 bits - they're just thermocouple data
  v >>= 4;

  // pull the bottom 11 bits off
  float internal = v & 0x7FF;
  // check sign bit!
  if (v & 0x800) {
    // Convert to negative value by extending sign and casting to signed type.
    int16_t tmp = 0xF800 | (v & 0x7FF);
    internal = tmp;
  }
  internal *= 0.0625; // LSB = 0.0625 degrees
  //Serial.print("\tInternal Temp: "); Serial.println(internal);
  return internal;
}

double Adafruit_MAX31855::readCelsius(void) {

  int32_t v;

  v = spiread32();

  //Serial.print("0x"); Serial.println(v, HEX);

  /*
  float internal = (v >> 4) & 0x7FF;
  internal *= 0.0625;
  if ((v >> 4) & 0x800) 
    internal *= -1;
  Serial.print("\tInternal Temp: "); Serial.println(internal);
  */

  if (v & 0x7) {
    // uh oh, a serious problem!
    return NAN; 
  }

  if (v & 0x80000000) {
    // Negative value, drop the lower 18 bits and explicitly extend sign bits.
    v = 0xFFFFC000 | ((v >> 18) & 0x00003FFFF);
  }
  else {
    // Positive value, just drop the lower 18 bits.
    v >>= 18;
  }
  //Serial.println(v, HEX);
  
  double centigrade = v;

  // LSB = 0.25 degrees C
  centigrade *= 0.25;
  return centigrade;
}

uint8_t Adafruit_MAX31855::readError() {
  return spiread32() & 0x7;
}

double Adafruit_MAX31855::readFarenheit(void) {
  float f = readCelsius();
  f *= 9.0;
  f /= 5.0;
  f += 32;
  return f;
}

uint32_t Adafruit_MAX31855::spiread32(void) { 
  int i;
  uint32_t d = 0;

  if(hSPI) {
    return hspiread32();
  }

  digitalWrite(sclk, LOW);
  delay(1);
  digitalWrite(cs, LOW);
  delay(1);

  for (i=31; i>=0; i--)
  {
    digitalWrite(sclk, LOW);
    delay(1);
    d <<= 1;
    if (digitalRead(miso)) {
      d |= 1;
    }

    digitalWrite(sclk, HIGH);
    delay(1);
  }

  digitalWrite(cs, HIGH);
  //Serial.println(d, HEX);
  return d;
}

uint32_t Adafruit_MAX31855::hspiread32(void) {
  int i;
  // easy conversion of four uint8_ts to uint32_t
  union bytes_to_uint32 {
    uint8_t bytes[4];
    uint32_t integer;
  } buffer;
  
  digitalWrite(cs, LOW);
  delay(1);
  
  for (i=3;i>=0;i--) {
    buffer.bytes[i] = SPI.transfer(0x00);
  }
  
  digitalWrite(cs, HIGH);
  
  return buffer.integer;
  
}

Here's the header:

#ifndef ADAFRUIT_MAX31855_H
#define ADAFRUIT_MAX31855_H

#if (ARDUINO >= 100)
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

class Adafruit_MAX31855 {
 public:
  Adafruit_MAX31855(int8_t SCLK, int8_t CS, int8_t MISO);
  Adafruit_MAX31855(int8_t CS);

  double readInternal(void);
  double readCelsius(void);
  double readFarenheit(void);
  uint8_t readError();

 private:
  int8_t sclk, miso, cs, hSPI;
  uint32_t spiread32(void);
  uint32_t hspiread32(void);
};

#endif

Here's the test sketch:


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

// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define DO   15
#define CS   16
#define CLK  17
Adafruit_MAX31855 thermocouple(CLK, CS, DO);

// Example creating a thermocouple instance with hardware SPI (Uno/Mega only)
// on a given CS pin.
//#define CS   10
//Adafruit_MAX31855 thermocouple(CS);

void setup() {
  Serial.begin(115200);
  
  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
   Serial.print("Internal Temp = ");
   //Serial.println(thermocouple.readInternal());

   //double c = thermocouple.readCelsius();
   //if (isnan(c)) {
   //  Serial.println("Something wrong with thermocouple!");
   //} else {
   //  Serial.print("C = "); 
   //  Serial.println(c);
   //}
   //Serial.print("F = ");
   //Serial.println(thermocouple.readFarenheit());
 
   delay(1000);
}
Link to post
Share on other sites

It's time to,do,some troubleshooting. Here's a checklist that I would follow.

 

Do you have a logic analyzer?

Can you monitor the i2c bus for activity?

What does the i2c bus traffic look like?

Does the cc3200 operate the i2c bus at 3.3V or at 5V?

Is the MAX31855 board configured to operate its i2c bus at the same voltage as the cc3200?

Are there pull-up resistors on the i2c bus?

Is the cc3200 properly configured to drive the correct pins as i2c pins?

 

Let us know what you discover.

Link to post
Share on other sites

@@zeke MAX31855 is SPI fyi. I haven't read this thread yet (those ipboard code blocks look absolutely hideous in tapatalk) but I have plenty of experience with them-

 

MAX31855 has 32 bits of data available for the MCU, starting at the latching (high-to-low) of the CS pin. There is no MOSI connection, just SCLK and MISO, so you transmit up to 4 dummy chars to the chip and read the results; they should be packed into either two 16-bit integers or 1 big 32-bit integer, then the requisite data fields extracted by bit shifts and AND masks, followed by a test to sign-extend the 2's complement signbit (for the thermocouple value and cold-junction temperature, which is optional and part of the "second" pair of bytes).

 

edit: the Adafruit library undoubtedly handles all those "details".

 

Sent from my Galaxy Note II with Tapatalk 4

Link to post
Share on other sites

@@Chuckymonkey Try issuing SPI.begin() after your sketch's Serial.begin(). I haven't inspected the Adafruit code to see if it does this but if it doesn't then it might explain why your chip freezes without serial monitor output. SPI needs to be init'd before use on the CC3200 (and Tiva) or else the MCU will crash (Bus Error IRQ actually which sends it into a function doing an infinite loop) because its SPI peripheral hasn't had its internal clock activated yet otherwise. SPI.begin() does this.

 

Sent from my Galaxy Note II with Tapatalk 4

Link to post
Share on other sites

Ok, the Adafruit library does actually issue SPI.begin() but does so inside the C++ constructor. Not sure if that's causing a problem here or what. I wouldn't think so but who knows. If my suggestion doesn't work then you might have to substantially modify the Adafruit library or scrap it altogether. I could probably write a replacement lib in a day or 2.

 

Sent from my Galaxy Note II with Tapatalk 4

Link to post
Share on other sites

I'm going to monkey around with it some more over the next few days based on all your advice. Unfortunately I'm not made of time(school, full time job, family). The eventual goal of this project is to create a network enabled smoker controlled via MQTT with an Android device. I eventualy want to integrate humidity and smoke density controls.

Link to post
Share on other sites

So, I just spent a couple more hours messing with it and met with exactly zero success.  I've tried using the hardware SPI, I have the DO pin on the MAX plugged into pin 14, CS to pin 18, and CLK to pin 7.  All I ever get back for values are 0 or 255.  I set pin 18 to HIGH, do SPI.transfer(0x00) and then set it to low.

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.

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