Author Topic: using Spi arduino library to drive max6675  (Read 947 times)

0 Members and 1 Guest are viewing this topic.

Offline amateur_25

  • Regular Contributor
  • *
  • Posts: 104
using Spi arduino library to drive max6675
« on: December 26, 2016, 12:28:22 pm »
hI GUYS

I need some help to ensure my understanding of how this is supposed to work.

I have found a sketch online to drive my max6675 using the spi library i.e. hardware spi bus on the uno.

I want to know given the attached serial timing diagram which spi mode should I use?

Based on my newly found knowledge I believe it should be mode 1

Is this correct?

Code: [Select]
void setup(){
pinMode(9,OUTPUT); // configure MAX6675 CS pin
digitalWrite(9,HIGH); // tell MAX6675 to read sensor
SPI.begin();
Serial.begin(9600);
}

int readTemp(){
SPI.beginTransaction((SPISettings(1000000, MSBFIRST, SPI_MODE1))); // configure the SPI for this device
digitalWrite(9,LOW); // I am now talking to the MAX6675
uint16_t reading=SPI.transfer16(0); // read 16bits
Serial.println("current reading:");
Serial.print(reading);
digitalWrite(9,HIGH); // I am done Talking to the MAX6675
SPI.endTransaction();  // release the SPI bus for others to use (i.e. SD, ethernet)

if (reading & 0x0004){// sensor disconnected
   reading = -1;
}
else {
   reading = reading >>3;  // the reading is in bits 14..03, get rid of bit 2,1,0
}
return reading;
}

void loop()
{
  readTemp();

}



 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf