diff --git a/lib/max31856/max31856.c b/lib/max31856/max31856.c --- a/lib/max31856/max31856.c +++ b/lib/max31856/max31856.c @@ -10,7 +10,7 @@ static float temp_latest = 0.0; static float temp_avg = 0.0; -static SPI_HandleTypeDef* spiport; +SPI_HandleTypeDef* spiport; static GPIO_TypeDef* csport; static uint32_t cspin; @@ -48,7 +48,7 @@ void max31856_init(SPI_HandleTypeDef* sp // TODO: Enable open/short detection // Enables auto conv - __write_reg(MAX31856_CR0_REG, MAX31856_CR0_OCFAULT0 | MAX31856_CR0_AUTOCONVERT); + __write_reg(MAX31856_CR0_REG, MAX31856_CR0_AUTOCONVERT); // MAX31856_CR0_OCFAULT0 // Averaging set to 1 sample, TC type set to K __write_reg(MAX31856_CR1_REG, MAX31856_TCTYPE_K); @@ -58,9 +58,9 @@ void max31856_init(SPI_HandleTypeDef* sp // Pull reading from the MAX31856 IC -void max31856_process(void) +float max31856_process(void) { - uint8_t tempbuf[4]; + uint8_t tempbuf[3]; __read_reg(MAX31856_LTCBH_REG, tempbuf, 3); @@ -74,14 +74,15 @@ void max31856_process(void) float tempfloat = temp24; tempfloat *= 0.0078125; + temp_latest = tempfloat; return tempfloat; // Read temperature from the MAX31856 (approx 10hz optimally) - uint8_t data[] = {0,0,0,0}; - HAL_SPI_Transmit(spiport, data, 1, 100); +// uint8_t data[] = {0,0,0,0}; +// HAL_SPI_Transmit(spiport, data, 1, 100); } @@ -110,8 +111,12 @@ static void __write_reg(uint8_t reg, uin // Assert the bus __cs_assert(); + HAL_Delay(1); + // Write data - HAL_SPI_Transmit(spiport, outarr, 2, 100); + volatile HAL_StatusTypeDef res = HAL_SPI_Transmit(spiport, outarr, 2, 100); + + HAL_Delay(1); // Release the bus __cs_deassert(); @@ -122,18 +127,22 @@ static void __read_reg(uint8_t reg, uint // Transmit buffer only uses first item for reg addr uint8_t regarr[1] = {reg}; - + HAL_Delay(1); // Assert the bus __cs_assert(); + HAL_Delay(1); // Send address - HAL_SPI_Transmit(spiport, regarr, 1, 100); + volatile HAL_StatusTypeDef res = HAL_SPI_Transmit(spiport, regarr, 1, 100); + HAL_Delay(1); // Receive data - HAL_SPI_Receive(spiport, rxbuf, len, 100); + volatile HAL_StatusTypeDef res2 = HAL_SPI_Receive(spiport, rxbuf, len, 100); + HAL_Delay(1); // Release bus __cs_deassert(); + HAL_Delay(1); }