thermocouple: Add support for MAX6675 chip

The MAX6675 chip has a different read sequence than the MAX31855 chip.

Signed-off-by: Ricardo Amézquita <ramezquitao@cihologramas.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Ricardo Amezquita 2018-06-17 19:59:29 -05:00 committed by Kevin O'Connor
parent eba252d3fd
commit 756514adef
2 changed files with 36 additions and 9 deletions

View File

@ -15,9 +15,10 @@ SAMPLE_COUNT_DEFAULT = 8
REPORT_TIME_DEFAULT = 0.300 REPORT_TIME_DEFAULT = 0.300
VALID_SPI_SENSORS = { VALID_SPI_SENSORS = {
'MAX6675' : 1, 'MAX31855' : 1, 'MAX31855' : 1,
'MAX31856' : 2, 'MAX31856' : 2,
'MAX31865' : 4 'MAX31865' : 4,
'MAX6675' : 8
} }
class error(Exception): class error(Exception):
@ -180,18 +181,26 @@ class Thermocouple(SensorBase):
if chip_type == "MAX31856": if chip_type == "MAX31856":
self.val_a = 0.0078125 self.val_a = 0.0078125
self.scale = 5 self.scale = 5
elif chip_type == "MAX6675":
self.val_a = 0.25
self.scale = 3
else: else:
self.val_a = 0.25 self.val_a = 0.25
self.scale = 18 self.scale = 18
SensorBase.__init__(self, config, is_spi = True, sample_count = 1) SensorBase.__init__(self, config, is_spi = True, sample_count = 1)
def _check_faults_simple(self, val): def _check_faults_simple(self, val):
if not self.chip_type == "MAX31856": if self.chip_type == "MAX6675":
if val & 0x02:
raise self.error("Max6675 : Device ID error")
if val & 0x04:
raise self.error("Max6675 : Thermocouple Open Fault")
elif not self.chip_type == "MAX31856":
if val & 0x1: if val & 0x1:
raise self.error("MAX6675/MAX31855 : Open Circuit") raise self.error("MAX31855 : Open Circuit")
if val & 0x2: if val & 0x2:
raise self.error("MAX6675/MAX31855 : Short to GND") raise self.error("MAX31855 : Short to GND")
if val & 0x4: if val & 0x4:
raise self.error("MAX6675/MAX31855 : Short to Vcc") raise self.error("MAX31855 : Short to Vcc")
def check_faults(self, fault): def check_faults(self, fault):
if self.chip_type == "MAX31856": if self.chip_type == "MAX31856":
if fault & MAX31856_FAULT_CJRANGE: if fault & MAX31856_FAULT_CJRANGE:

View File

@ -16,7 +16,8 @@
enum { enum {
TS_CHIP_MAX31855 = 1 << 0, TS_CHIP_MAX31855 = 1 << 0,
TS_CHIP_MAX31856 = 1 << 1, TS_CHIP_MAX31856 = 1 << 1,
TS_CHIP_MAX31865 = 1 << 2 TS_CHIP_MAX31865 = 1 << 2,
TS_CHIP_MAX6675 = 1 << 3
}; };
struct thermocouple_spi { struct thermocouple_spi {
@ -48,7 +49,7 @@ void
command_config_thermocouple(uint32_t *args) command_config_thermocouple(uint32_t *args)
{ {
uint8_t chip_type = args[2]; uint8_t chip_type = args[2];
if (chip_type > TS_CHIP_MAX31865 || !chip_type) if (chip_type > TS_CHIP_MAX6675 || !chip_type)
shutdown("Invalid thermocouple chip type"); shutdown("Invalid thermocouple chip type");
struct thermocouple_spi *spi = oid_alloc( struct thermocouple_spi *spi = oid_alloc(
args[0], command_config_thermocouple, sizeof(*spi)); args[0], command_config_thermocouple, sizeof(*spi));
@ -90,7 +91,6 @@ thermocouple_respond(struct thermocouple_spi *spi, uint32_t next_begin_time
oid, next_begin_time, value, fault); oid, next_begin_time, value, fault);
} }
/* Logic of thermocouple K readers MAX6675 and MAX31855 are same */
static void static void
thermocouple_handle_max31855(struct thermocouple_spi *spi thermocouple_handle_max31855(struct thermocouple_spi *spi
, uint32_t next_begin_time, uint8_t oid) , uint32_t next_begin_time, uint8_t oid)
@ -147,6 +147,21 @@ thermocouple_handle_max31865(struct thermocouple_spi *spi
try_shutdown("Thermocouple reader fault"); try_shutdown("Thermocouple reader fault");
} }
static void
thermocouple_handle_max6675(struct thermocouple_spi *spi
, uint32_t next_begin_time, uint8_t oid)
{
uint8_t msg[2] = { 0x00, 0x00};
spidev_transfer(spi->spi, 1, sizeof(msg), msg);
uint16_t value;
memcpy(&value, msg, sizeof(msg));
value = be16_to_cpu(value);
thermocouple_respond(spi, next_begin_time, value, 0, oid);
// Kill after data send, host decode an error
if (value & 0x04)
try_shutdown("Thermocouple reader fault");
}
// task to read thermocouple and send response // task to read thermocouple and send response
void void
thermocouple_task(void) thermocouple_task(void)
@ -172,6 +187,9 @@ thermocouple_task(void)
case TS_CHIP_MAX31865: case TS_CHIP_MAX31865:
thermocouple_handle_max31865(spi, next_begin_time, oid); thermocouple_handle_max31865(spi, next_begin_time, oid);
break; break;
case TS_CHIP_MAX6675:
thermocouple_handle_max6675(spi, next_begin_time, oid);
break;
} }
} }
} }