Last active
January 12, 2020 21:23
-
-
Save ti-nspire/164187c79ec8b0ece8ca1f177150a585 to your computer and use it in GitHub Desktop.
MAX31855_library_for_ATmega328P
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include "MAX31855.h" | |
#include "mySPI.h" | |
void MAX31855::getData(){ | |
selectSlave(_port, _pin); | |
tradeByte(0); hi16bits = SPDR << 8; | |
tradeByte(0); hi16bits |= SPDR ; | |
tradeByte(0); lo16bits = SPDR << 8; | |
tradeByte(0); lo16bits |= SPDR ; | |
deselectSlave(_port, _pin); | |
} | |
float MAX31855::getHotTemp() {return (float)(hi16bits & 0xfffc) / 16.0;} | |
float MAX31855::getColdTemp(){return (float)(lo16bits & 0xfff0) / 256.0;} | |
uint8_t MAX31855::isFailed() {return ( hi16bits & 1);} | |
uint8_t MAX31855::isShorted2Vcc(){return ((lo16bits >> 2) & 1);} | |
uint8_t MAX31855::isShorted2Gnd(){return ((lo16bits >> 1) & 1);} | |
uint8_t MAX31855::isOpened() {return ( lo16bits & 1);} | |
uint8_t MAX31855::getPort(){return _port;} | |
uint8_t MAX31855::getPin (){return _pin;} | |
// コンストラクター | |
MAX31855::MAX31855(uint8_t port, uint8_t pin){ | |
PORTB |= (1 << PB2); // マスターモードのときはとにかくまずPB2をプルアップしておく。 | |
_port = port; | |
_pin = pin; | |
setSPIpins(_port, _pin); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#include <avr/io.h> | |
#include "mySPI.h" | |
#ifndef MAX31855_H | |
#define MAX31855_H | |
class MAX31855{ | |
private: | |
uint8_t _port, _pin; | |
int16_t hi16bits, lo16bits; // 32ビットデータを格納するための変数。 | |
uint8_t FaultBit, ShortVccBit, ShortGndBit, OpenBit; // 障害ビット | |
public: | |
void getData(); // 32ビットを全部取得する。 | |
float getHotTemp(); // 熱接点温度を返す。 | |
float getColdTemp(); // 冷接点温度を返す | |
uint8_t isFailed(); // 下のいずれかが発生しているか? | |
uint8_t isShorted2Vcc(); // 電源に短絡しているか? | |
uint8_t isShorted2Gnd(); // GNDに短絡しているか? | |
uint8_t isOpened(); // 切れているか(外れているか)? | |
uint8_t getPort(); // !SSピンのポート文字を返す。 | |
uint8_t getPin(); // !SSピンのピン番号を返す。 | |
// コンストラクター。PB3、PB4、PB5は指定しないこと。 | |
MAX31855(uint8_t port, uint8_t pin); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment