|
|
|
@ -90,8 +90,8 @@ void max31865_init(
|
|
|
|
|
device->lowFaultThreshold = lowerFaulThreshold << 1;
|
|
|
|
|
device->highFaultThreshold = higherFaultThreshold << 1;
|
|
|
|
|
// settup configurations + set a fault status
|
|
|
|
|
device->configReg = (uint8_t)(((wire_3) ? (1 << 4):(0) |
|
|
|
|
|
(filter_50Hz) ? (0x01) : (0));
|
|
|
|
|
device->configReg = (uint8_t)((logic_wire_3) ? (1 << 4):(0) |
|
|
|
|
|
(logic_filter_50Hz) ? (0x01) : (0));
|
|
|
|
|
|
|
|
|
|
// low and high fault threshold setup
|
|
|
|
|
temp_1 = device->highFaultThreshold;
|
|
|
|
@ -102,8 +102,8 @@ void max31865_init(
|
|
|
|
|
buff[3] = (uint8_t)(temp_1);
|
|
|
|
|
|
|
|
|
|
temp = device->configReg;
|
|
|
|
|
spi_writeReg(device->spiCH,REG_WRITE_CONFIGURATION, &temp);
|
|
|
|
|
spi_writeBlock(device->spiCH, REG_WRITE_HIGH_FAULT_TH_MSB, buff,4);
|
|
|
|
|
spiWriteReg(device->spiCH,REG_WRITE_CONFIGURATION, temp);
|
|
|
|
|
spiWriteBlock(device->spiCH, REG_WRITE_HIGH_FAULT_TH_MSB, buff,4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t max31865_readADC(const max31865_t* device)
|
|
|
|
@ -112,20 +112,20 @@ uint16_t max31865_readADC(const max31865_t* device)
|
|
|
|
|
uint8_t temp = 0;
|
|
|
|
|
// turn on vbias
|
|
|
|
|
temp = device->configReg | D7;
|
|
|
|
|
spi_writeReg(device->spiCH, REG_WRITE_CONFIGURATION,&temp);
|
|
|
|
|
spiWriteReg(device->spiCH, REG_WRITE_CONFIGURATION,temp);
|
|
|
|
|
|
|
|
|
|
device->charged_time_delay();
|
|
|
|
|
|
|
|
|
|
// initiate 1-shot conversion + vbias
|
|
|
|
|
temp = device->configReg | 0xA0;
|
|
|
|
|
spi_writeReg(device->spiCH, REG_WRITE_CONFIGURATION,&temp);
|
|
|
|
|
spiWriteReg(device->spiCH, REG_WRITE_CONFIGURATION,temp);
|
|
|
|
|
|
|
|
|
|
device->conversion_timer_deay();
|
|
|
|
|
|
|
|
|
|
spi_AutoReadBlock(device->spiCH, REG_READ_RTD_MSB, &buff, 2);
|
|
|
|
|
spiAutoReadBlock(device->spiCH, REG_READ_RTD_MSB, buff, 2);
|
|
|
|
|
|
|
|
|
|
// turn off vbias
|
|
|
|
|
spi_writeReg(device->spiCH, REG_WRITE_CONFIGURATION, &(device->configReg));
|
|
|
|
|
spiWriteReg(device->spiCH, REG_WRITE_CONFIGURATION, device->configReg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(buff[1] & 0x01) {
|
|
|
|
@ -162,8 +162,7 @@ void max31865_setHighFaultThreshold(max31865_t* device,
|
|
|
|
|
threshold = threshold << 1;
|
|
|
|
|
buff[0] = (uint8_t)(threshold >> 8);
|
|
|
|
|
buff[1] = (uint8_t)(threshold);
|
|
|
|
|
|
|
|
|
|
_write_n_reg(device, REG_WRITE_HIGH_FAULT_TH_MSB, buff, 2);
|
|
|
|
|
spiWriteBlock(device->spiCH, REG_WRITE_HIGH_FAULT_TH_MSB,buff,2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max31865_setLowFaultThreshold(max31865_t* device,
|
|
|
|
@ -175,13 +174,13 @@ void max31865_setLowFaultThreshold(max31865_t* device,
|
|
|
|
|
threshold = threshold << 1;
|
|
|
|
|
buff[0] = (uint8_t)(threshold >> 8);
|
|
|
|
|
buff[1] = (uint8_t)(threshold);
|
|
|
|
|
_write_n_reg(device, REG_WRITE_LOW_FAULT_TH_MSB, buff, 2);
|
|
|
|
|
spiWriteBlock(device->spiCH, REG_WRITE_LOW_FAULT_TH_MSB,buff,2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int8_t max31865_checkThresholdFault(const max31865_t* device)
|
|
|
|
|
{
|
|
|
|
|
uint8_t buff;
|
|
|
|
|
_read_n_reg(device,REG_READ_FAULT_STATUS, &buff, 1);
|
|
|
|
|
buff = spiReadReg(device->spiCH, REG_READ_FAULT_STATUS);
|
|
|
|
|
|
|
|
|
|
if(buff & max31865_err_RTD_HIGH_THRESHOLD) return 1;
|
|
|
|
|
if(buff & max31865_err_RTD_LOW_THRESHOLD) return -1;
|
|
|
|
@ -192,55 +191,13 @@ int8_t max31865_checkThresholdFault(const max31865_t* device)
|
|
|
|
|
|
|
|
|
|
uint8_t max31865_readFault(const max31865_t* device)
|
|
|
|
|
{
|
|
|
|
|
uint8_t buff;
|
|
|
|
|
_read_n_reg(device, REG_READ_FAULT_STATUS, &buff, 1);
|
|
|
|
|
return buff;
|
|
|
|
|
return spiReadReg(device->spiCH, REG_READ_FAULT_STATUS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void max31865_clearFault(const max31865_t* device)
|
|
|
|
|
{
|
|
|
|
|
uint8_t temp = (device->configReg | D1);
|
|
|
|
|
_write_n_reg(device,REG_WRITE_CONFIGURATION, &temp, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void _write_n_reg(const max31865_t* device,
|
|
|
|
|
uint8_t start_reg_address,
|
|
|
|
|
const uint8_t* data,
|
|
|
|
|
uint8_t len)
|
|
|
|
|
{
|
|
|
|
|
uint8_t index = 0;
|
|
|
|
|
|
|
|
|
|
if(len == 0) return;
|
|
|
|
|
|
|
|
|
|
device->chipselect(true);
|
|
|
|
|
|
|
|
|
|
device->spi_trx(start_reg_address);
|
|
|
|
|
|
|
|
|
|
do{
|
|
|
|
|
device->spi_trx(data[index++]);
|
|
|
|
|
} while(index < len);
|
|
|
|
|
|
|
|
|
|
device->chipselect(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void _read_n_reg(const max31865_t* device,
|
|
|
|
|
uint8_t start_reg_address,
|
|
|
|
|
uint8_t* data,
|
|
|
|
|
uint8_t len)
|
|
|
|
|
{
|
|
|
|
|
uint8_t index = 0;
|
|
|
|
|
|
|
|
|
|
if(len == 0) return;
|
|
|
|
|
|
|
|
|
|
device->chipselect(true);
|
|
|
|
|
device->spi_trx(start_reg_address);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
data[index++] = device->spi_trx(0xFF);
|
|
|
|
|
} while(index < len);
|
|
|
|
|
|
|
|
|
|
device->chipselect(false);
|
|
|
|
|
spiWriteReg(device->spiCH, REG_WRITE_CONFIGURATION, temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _handle_threshold_fault(const max31865_t* device)
|
|
|
|
|