资源简介
MAX31865连接PT100 C语言驱动,基于STM32 , 实际测试通过,带调用实例
代码片段和文件信息
/***************************************************
This is a library for the PT100/P1000 RTD Sensor MAX31865
****************************************************/
#include “GlobalsDef.h“
#include “math.h“
#define GetDRDY() GPIO_ReadInputDataBit(MAX_DRDY_PORTMAX_DRDY_PIN)
#define spixfer(a) Spi2_ReadWriteByte(a)
void readRegisterN(uint8_t addr uint8_t buffer[] uint8_t n)
{
addr &= 0x7F; // make sure top bit is not set
Spi2CSn_Enable();
spixfer(addr);
while (n--)
{
buffer[0] = spixfer(0xFF);
buffer++;
}
Spi2CSn_Disable();
}
void writeRegister8(uint8_t addr uint8_t data)
{
Spi2CSn_Enable();
spixfer(addr | 0x80); // make sure top bit is set
spixfer(data);
Spi2CSn_Disable();
}
uint8_t readRegister8(uint8_t addr)
{
uint8_t ret = 0;
readRegisterN(addr &ret 1);
return ret;
}
uint16_t readRegister16(uint8_t addr)
{
uint8_t buffer[2] = {0 0};
readRegisterN(addr buffer 2);
uint16_t ret = buffer[0];
ret <<= 8;
ret |= buffer[1];
return ret;
}
void setWires(max31865_numwires_t wires )
{
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
if (wires == MAX31865_3WIRE)
{
t |= MAX31856_CONFIG_3WIRE;
}
else
{
// 2 or 4 wire
t &= ~MAX31856_CONFIG_3WIRE;
}
writeRegister8(MAX31856_CONFIG_REG t);
}
bool max31865_config(max31865_numwires_t wires)
{
SPIx_Configuration(SPI2);
setWires(wires);
enableBias(FALSE);
autoConvert(FALSE);
clearFault();
// writeRegister8(MAX31856_CONFIG_REG 0xD2);
return TRUE;
}
uint8_t readFault(void)
{
return readRegister8(MAX31856_FAULTSTAT_REG);
}
void clearFault(void)
{
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
t &= ~0x2C;
t |= MAX31856_CONFIG_FAULTSTAT;
writeRegister8(MAX31856_CONFIG_REG t);
}
void enableBias(bool b)
{
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
if (b)
{
t |= MAX31856_CONFIG_BIAS; // enable bias
}
else
{
t &= ~MAX31856_CONFIG_BIAS; // disable bias
}
writeRegister8(MAX31856_CONFIG_REG t);
}
void autoConvert(bool b)
{
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
if (b)
{
t |= MAX31856_CONFIG_MODEAUTO; // enable autoconvert
}
else
{
t &= ~MAX31856_CONFIG_MODEAUTO; // disable autoconvert
}
writeRegister8(MAX31856_CONFIG_REG t);
}
float temperature(float RTDnominal float refResistor)
{
// http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
float Z1 Z2 Z3 Z4 Rt temp;
Rt = readRTD();
Rt /= 32768;
Rt *= refResistor;
// Serial.print(“\nResistance: “); Serial.println(Rt 8);
Z1 = -RTD_A;
Z2 = RTD_A * RTD_A - (4 * RTD_B);
Z3 = (4 * RTD_B) / RTDnominal;
Z4 = 2 *
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4820 2018-07-17 10:26 MAX31865.c
文件 2092 2018-07-13 15:31 MAX31865.h
----------- --------- ---------- ----- ----
6912 2
- 上一篇:c++做的仪表盘非常逼真哦
- 下一篇:matlab实现VQ说话人识别系统
评论
共有 条评论