|
|
|
@ -23,8 +23,6 @@ SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "max31865.h"
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
enum REG{
|
|
|
|
|
REG_READ_CONFIGURATION = 0x00,
|
|
|
|
@ -60,39 +58,30 @@ static const float a3 = 0.000000731467;
|
|
|
|
|
static const float a4 = 0.000000000691;
|
|
|
|
|
static const float a5 = 7.31888555389e-13;
|
|
|
|
|
|
|
|
|
|
static void _write_n_reg(const max31865_t* device,
|
|
|
|
|
uint8_t start_reg_address,
|
|
|
|
|
const uint8_t* data,
|
|
|
|
|
uint8_t len);
|
|
|
|
|
static void _read_n_reg(const max31865_t* device,
|
|
|
|
|
uint8_t start_reg_address,
|
|
|
|
|
uint8_t* data,
|
|
|
|
|
uint8_t len);
|
|
|
|
|
void _handle_threshold_fault(const max31865_t* device);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void max31865_init(max31865_t* device,
|
|
|
|
|
fptr_b_t chipselect_cb,
|
|
|
|
|
u8_fptr_u8_t spi_trx_cb,
|
|
|
|
|
fptr_t charged_time_delay_cb,
|
|
|
|
|
fptr_t conversion_timer_deay_cb,
|
|
|
|
|
fptr_t highFaultThreshold_callback,
|
|
|
|
|
fptr_t lowFaultThreshold_callback,
|
|
|
|
|
uint16_t rtd_ohm,
|
|
|
|
|
uint16_t rref_ohm,
|
|
|
|
|
uint16_t lowerFaulThreshold,
|
|
|
|
|
uint16_t higherFaultThreshold,
|
|
|
|
|
bool wire_3,
|
|
|
|
|
bool filter_50Hz)
|
|
|
|
|
void max31865_init(
|
|
|
|
|
max31865_t* device,
|
|
|
|
|
spi_ch_t *spi_ch,
|
|
|
|
|
fptr_t charged_time_delay_cb,
|
|
|
|
|
fptr_t conversion_timer_deay_cb,
|
|
|
|
|
fptr_t highFaultThreshold_callback,
|
|
|
|
|
fptr_t lowFaultThreshold_callback,
|
|
|
|
|
uint16_t rtd_ohm,
|
|
|
|
|
uint16_t rref_ohm,
|
|
|
|
|
uint16_t lowerFaulThreshold,
|
|
|
|
|
uint16_t higherFaultThreshold,
|
|
|
|
|
uint8_t logic_wire_3,
|
|
|
|
|
uint8_t logic_filter_50Hz)
|
|
|
|
|
{
|
|
|
|
|
uint8_t buff[4];
|
|
|
|
|
uint8_t temp = 0;
|
|
|
|
|
uint16_t temp_1 = 0;
|
|
|
|
|
|
|
|
|
|
// object setup
|
|
|
|
|
device->chipselect = chipselect_cb;
|
|
|
|
|
device->spi_trx = spi_trx_cb;
|
|
|
|
|
device->charged_time_delay = charged_time_delay_cb;
|
|
|
|
|
device->spiCH = spi_ch;
|
|
|
|
|
device->charged_time_delay = charged_time_delay_cb;
|
|
|
|
|
device->conversion_timer_deay = conversion_timer_deay_cb;
|
|
|
|
|
device->highFaultThreshold_cb = highFaultThreshold_callback;
|
|
|
|
|
device->lowFaultThreshold_cb = lowFaultThreshold_callback;
|
|
|
|
@ -101,7 +90,8 @@ void max31865_init(max31865_t* device,
|
|
|
|
|
device->lowFaultThreshold = lowerFaulThreshold << 1;
|
|
|
|
|
device->highFaultThreshold = higherFaultThreshold << 1;
|
|
|
|
|
// settup configurations + set a fault status
|
|
|
|
|
device->configReg = (uint8_t)((wire_3 << 4) | (filter_50Hz));
|
|
|
|
|
device->configReg = (uint8_t)(((wire_3) ? (1 << 4):(0) |
|
|
|
|
|
(filter_50Hz) ? (0x01) : (0));
|
|
|
|
|
|
|
|
|
|
// low and high fault threshold setup
|
|
|
|
|
temp_1 = device->highFaultThreshold;
|
|
|
|
@ -112,8 +102,8 @@ void max31865_init(max31865_t* device,
|
|
|
|
|
buff[3] = (uint8_t)(temp_1);
|
|
|
|
|
|
|
|
|
|
temp = device->configReg;
|
|
|
|
|
_write_n_reg(device, REG_WRITE_CONFIGURATION, &temp, 1);
|
|
|
|
|
_write_n_reg(device, REG_WRITE_HIGH_FAULT_TH_MSB, buff, 4);
|
|
|
|
|
spi_writeReg(device->spiCH,REG_WRITE_CONFIGURATION, &temp);
|
|
|
|
|
spi_writeBlock(device->spiCH, REG_WRITE_HIGH_FAULT_TH_MSB, buff,4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t max31865_readADC(const max31865_t* device)
|
|
|
|
@ -122,26 +112,26 @@ uint16_t max31865_readADC(const max31865_t* device)
|
|
|
|
|
uint8_t temp = 0;
|
|
|
|
|
// turn on vbias
|
|
|
|
|
temp = device->configReg | D7;
|
|
|
|
|
_write_n_reg(device, REG_WRITE_CONFIGURATION, &temp, 1);
|
|
|
|
|
spi_writeReg(device->spiCH, REG_WRITE_CONFIGURATION,&temp);
|
|
|
|
|
|
|
|
|
|
device->charged_time_delay();
|
|
|
|
|
|
|
|
|
|
// initiate 1-shot conversion + vbias
|
|
|
|
|
temp = device->configReg | 0xA0;
|
|
|
|
|
_write_n_reg(device, REG_WRITE_CONFIGURATION, &temp, 1);
|
|
|
|
|
spi_writeReg(device->spiCH, REG_WRITE_CONFIGURATION,&temp);
|
|
|
|
|
|
|
|
|
|
device->conversion_timer_deay();
|
|
|
|
|
|
|
|
|
|
_read_n_reg(device, REG_READ_RTD_MSB, &buff, 2);
|
|
|
|
|
spi_AutoReadBlock(device->spiCH, REG_READ_RTD_MSB, &buff, 2);
|
|
|
|
|
|
|
|
|
|
// turn off vbias
|
|
|
|
|
_write_n_reg(device, REG_WRITE_CONFIGURATION, &(device->configReg), 1);
|
|
|
|
|
spi_writeReg(device->spiCH, REG_WRITE_CONFIGURATION, &(device->configReg));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(buff[1] & 0x01) {
|
|
|
|
|
_handle_threshold_fault(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ((uint16_t)((buff[0]<<8) | (buff[1] >> 1)) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|