资源简介
MAX31855开发,热电偶至输出转换器,可用于STM32F4等单片机的库中
代码片段和文件信息
/***************************************************
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 “MAX31855.h“
#include
#include
#include
MAX31855::MAX31855(int8_t SCLK int8_t CS int8_t MISO) {
sclk = SCLK;
cs = CS;
miso = MISO;
//define pin modes
pinMode(cs OUTPUT);
pinMode(sclk OUTPUT);
pinMode(miso INPUT);
digitalWrite(cs HIGH);
}
int16_t MAX31855::readCelsius(void) {
int32_t v;
v = spiread32();
if (v & 0x7) {
// uh oh a serious problem!
return NAN;
}
// get rid of internal temp data and any fault bits
v >>= 18;
// pull the bottom 13 bits off
int16_t temp = v & 0x3FFF;
// check sign bit
if (v & 0x2000)
temp |= 0xC000;
return temp;
}
uint8_t MAX31855::readError() {
return spiread32() & 0x7;
}
uint32_t MAX31855::spiread32(void) {
int i;
uint32_t d = 0;
digitalWrite(sclk LOW);
delayMicroseconds(150);
digitalWrite(cs LOW);
delayMicroseconds(150);
for (i=31; i>=0; i--)
{
digitalWrite(sclk LOW);
delayMicroseconds(150);
d <<= 1;
if (digitalRead(miso)) {
d |= 1;
}
digitalWrite(sclk HIGH);
delayMicroseconds(150);
}
digitalWrite(cs HIGH);
return d;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1832 2013-07-28 13:41 sketchbook\libraries\MAX31855\MAX31855.cpp
文件 955 2013-07-28 13:48 sketchbook\libraries\MAX31855\MAX31855.h
- 上一篇:养鸡场,喂食H5小游戏
- 下一篇:两个单片机之间实现串口通信,包括仿真和程序
评论
共有 条评论