started implementing max31865

redesign_interrupts
polymurph 3 years ago
parent 376ed8cfe8
commit 57e6671e88

@ -1 +1,2 @@
add_subdirectory(max7219)
add_subdirectory(max31865)

@ -0,0 +1,5 @@
#add_library(MAX31865 max31865.c)
#target_compile_options(MAX31865 PRIVATE ${C_FLAGS})
#target_compile_definitions(MAX31865 PRIVATE ${C_DEFS})
#target_include_directories(MAX31865 PUBLIC . ${PERIFERALS_DIR} ${CSL_INCLUDES})
#add_library(sub::max31865 ALIAS MAX31865)

@ -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)) );
}

@ -27,6 +27,8 @@ SOFTWARE.
#include <stdint.h>
#include <stdbool.h>
#include "pin.h"
#include "spi.h"
typedef void (*fptr_t)(void);
typedef void (*fptr_b_t)(bool);
@ -42,9 +44,8 @@ typedef enum{
}max31865_err_t;
typedef struct{
fptr_b_t chipselect;
u8_fptr_u8_t spi_trx;
fptr_t charged_time_delay;
spi_ch_t *spiCH;
fptr_t charged_time_delay;
fptr_t conversion_timer_deay;
fptr_t highFaultThreshold_cb;
fptr_t lowFaultThreshold_cb;
@ -55,36 +56,44 @@ typedef struct{
uint8_t configReg;
}max31865_t;
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);
uint16_t max31865_readADC(const max31865_t* device);
float max31865_readRTD_ohm(const max31865_t* device);
float max31865_readCelsius(const max31865_t* device);
void max31865_setHighFaultThreshold(max31865_t* device,
uint16_t threshold);
void max31865_setLowFaultThreshold(max31865_t* device,
uint16_t threshold);
int8_t max31865_checkThresholdFault(const max31865_t* device);
uint8_t max31865_readFault(const max31865_t* device);
void max31865_clearFault(const max31865_t* device);
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);
uint16_t max31865_readADC(
const max31865_t *device);
float max31865_readRTD_ohm(
const max31865_t *device);
float max31865_readCelsius(
const max31865_t *device);
void max31865_setHighFaultThreshold(
max31865_t *device,
uint16_t hreshold);
void max31865_setLowFaultThreshold(
max31865_t *device,
uint16_t threshold);
int8_t max31865_checkThresholdFault(
const max31865_t *device);
uint8_t max31865_readFault(
const max31865_t *device);
void max31865_clearFault(
const max31865_t *device);
#endif /* MAX31865_H_ */

Loading…
Cancel
Save