Files
@ b42e15fadfde
Branch filter:
Location: therm/max31865.c - annotation
b42e15fadfde
3.3 KiB
text/plain
Add new pid files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 b77b97fa501d a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d b77b97fa501d a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 235f584ead39 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 235f584ead39 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 235f584ead39 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 235f584ead39 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 a76c60e8cc43 | #include "stm32f0xx_hal.h"
#include "config.h"
#include "stringhelpers.h"
#include "states.h"
#include "gpio.h"
// Registers
#define MAX31855_REG_CONFIG 0x00
#define MAX31855_REG_RTD_MSB 0x01
#define MAX31855_REG_RTD_LSB 0x02
#define MAX31855_REG_HFAULT_THRESH_MSB 0x03
#define MAX31855_REG_HFAULT_THRESH_LSB 0x04
#define MAX31855_REG_LFAULT_THRESH_MSB 0x05
#define MAX31855_REG_LFAULT_THRESH_LSB 0x06
#define MAX31855_REG_FAULTSTATUS 0x07
#define MAX31855_REGWRITEMODIFIER 0x80
// Fields
#define MAX31865_CONF_VBIAS (1<<7)
#define MAX31865_CONF_CONVMODE (1<<6)
#define MAX31865_CONF_1SHOT (1<<5)
#define MAX31865_CONF_3WIRE (1<<4)
#define MAX31865_CONF_FAULT_NOACTION 0b0000
#define MAX31865_CONF_FAULT_AUTODELAY 0b0100
#define MAX31865_CONF_FAULT_MANUALELAY1 0b1000
#define MAX31865_CONF_FAULT_MANUALELAY2 0b1100
#define MAX31865_CONF_FAULT_CLEAR (1<<1)
#define MAX31865_CONF_50_60HZ_FILTER (1<<0)
// Grab temperature reading from MAX31865
void max31865_readtemp(SPI_HandleTypeDef* hspi1, therm_settings_t* set, therm_status_t* status)
{
///////////////////////////////////
// This is duplicated from MAX31855, update for MAX31865 registers/etc
///////////////////////////////////
// TODO: Set configuration register based on params in config.h (2-wire, 4-wire, etc RTD). This is register 0x00.
// 2-wire RTC or 2-wire (duh) NTC thermistor will be the only options
// Need option for resistance of RTD
// These options should be stored in the set structure and should be menu-selectable
// TODO: Read RTD msbs (0x01)
// TODO: Read RTD LSBs (0x02)
// Assert CS
HAL_GPIO_WritePin(MAX_CS, 0);
uint8_t rxdatah[1] = {0x00};
uint8_t rxdatal[1] = {0x00};
HAL_SPI_Receive(hspi1, rxdatah, 1, 100);
HAL_SPI_Receive(hspi1, rxdatal, 1, 100);
// Release CS
HAL_GPIO_WritePin(MAX_CS, 1);
// Assemble data array into one var
uint16_t temp_pre = rxdatal[0] | (rxdatah[0]<<8);
if(temp_pre & 0b001 && !set->val.ignore_tc_error) {
status->tc_errno = 1;
HAL_Delay(400); // FIXME: remove?
status->state_resume = status->state;
status->state = STATE_TC_ERROR;
status->temp = 0;
status->temp_frac = 0;
}
else
{
uint8_t sign = status->temp >> 15;// top bit is sign
temp_pre = temp_pre >> 2; // Drop 2 lowest bits
status->temp_frac = temp_pre & 0b11; // get fractional part
status->temp_frac *= 25; // each bit is .25 a degree, up to fixed point
temp_pre = temp_pre >> 2; // Drop 2 fractional bits
int8_t signint;
if(sign) {
signint = -1;
}
else {
signint = 1;
}
// Convert to Fahrenheit
if(set->val.temp_units == TEMP_UNITS_FAHRENHEIT)
{
status->temp = signint * ((temp_pre*100) + status->temp_frac);
status->temp = status->temp * 1.8;
status->temp += 3200;
status->temp_frac = status->temp % 100;
status->temp /= 100;
status->temp += set->val.temp_offset;
}
// Use Celsius values
else
{
status->temp = temp_pre * signint;
status->temp += set->val.temp_offset;
}
}
}
// vim:softtabstop=4 shiftwidth=4 expandtab
|