Chuckymonkey 0 Posted October 7, 2014 Share Posted October 7, 2014 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. Quote Link to post Share on other sites
abecedarian 330 Posted October 7, 2014 Share Posted October 7, 2014 What pins are you using? You do realize that pins used to communicate with the sensor cannot be pins used for the serial / terminal monitor, right? Quote Link to post Share on other sites
Chuckymonkey 0 Posted October 18, 2014 Author Share Posted October 18, 2014 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. Quote Link to post Share on other sites
Chuckymonkey 0 Posted October 18, 2014 Author Share Posted October 18, 2014 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); } Quote Link to post Share on other sites
Chuckymonkey 0 Posted October 18, 2014 Author Share Posted October 18, 2014 I should mention that I have the MAX pins connected just like it shows in the sketch. I also have the 5v and GND connected to 5v and GND on device. I've tested it again with a new thermocouple on Arduino so I know the MAX and thermocouple work. Quote Link to post Share on other sites
Chuckymonkey 0 Posted October 18, 2014 Author Share Posted October 18, 2014 I should mention that I have the MAX pins connected just like it shows in the sketch. I also have the 5v and GND connected to 5v and GND on device. I've tested it again with a new thermocouple on Arduino so I know the MAX and thermocouple work. Quote Link to post Share on other sites
abecedarian 330 Posted October 18, 2014 Share Posted October 18, 2014 According to the datasheet here, the MAX31855 is a 3.3v (3.0-3.6) chip. Is this the module you're working with? If so, it has a 3v hook-up too, so you might try that- it could be the LDO on the module is bad for some reason. Quote Link to post Share on other sites
Chuckymonkey 0 Posted October 18, 2014 Author Share Posted October 18, 2014 No, it's 3.3 and 5v. You can input either into the VIN pin. Quote Link to post Share on other sites
zeke 693 Posted October 19, 2014 Share Posted October 19, 2014 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. Quote Link to post Share on other sites
spirilis 1,265 Posted October 19, 2014 Share Posted October 19, 2014 @@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 Quote Link to post Share on other sites
spirilis 1,265 Posted October 19, 2014 Share Posted October 19, 2014 @@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 Quote Link to post Share on other sites
spirilis 1,265 Posted October 19, 2014 Share Posted October 19, 2014 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 Quote Link to post Share on other sites
Chuckymonkey 0 Posted October 19, 2014 Author Share Posted October 19, 2014 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. Quote Link to post Share on other sites
Chuckymonkey 0 Posted October 19, 2014 Author Share Posted October 19, 2014 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. Quote Link to post Share on other sites
zeke 693 Posted October 19, 2014 Share Posted October 19, 2014 @@spirilis, doh! Thanks for the correction. @@Chuckymonkey, sorry about that. As an aside, I just discovered that there is a one wire variant of this device - the MAX31850K: https://learn.adafruit.com/adafruit-1-wire-thermocouple-amplifier-max31850k/overview I'm going to have to try that one out. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.