# HG changeset patch # User Ethan Zonca # Date 2017-07-25 13:17:30 # Node ID 6cc8fa5ae0f646b31c104e81bef5dfce6184b6fb # Parent 573011597aec180cf170dd7f8b21fadf7162dee2 Temp reading finally working! diff --git a/lib/max31856/max31856.c b/lib/max31856/max31856.c --- a/lib/max31856/max31856.c +++ b/lib/max31856/max31856.c @@ -64,7 +64,7 @@ float max31856_process(void) __read_reg(MAX31856_LTCBH_REG, tempbuf, 3); - int32_t temp24 = tempbuf[0] << 16 | tempbuf[1] << 8 | tempbuf[0]; + volatile int32_t temp24 = tempbuf[0] << 16 | tempbuf[1] << 8 | tempbuf[2]; if (temp24 & 0x800000) { temp24 |= 0xFF000000; // fix sign } @@ -107,16 +107,15 @@ static void __write_reg(uint8_t reg, uin reg |= MAX31856_WRITE_BIT; uint8_t outarr[2] = {reg, data}; + uint8_t dummyrx[2]; // Assert the bus __cs_assert(); - HAL_Delay(1); // Write data - volatile HAL_StatusTypeDef res = HAL_SPI_Transmit(spiport, outarr, 2, 100); + volatile HAL_StatusTypeDef res = HAL_SPI_TransmitReceive(spiport, outarr, dummyrx, 2, 100); - HAL_Delay(1); // Release the bus __cs_deassert(); @@ -125,24 +124,23 @@ static void __write_reg(uint8_t reg, uin static void __read_reg(uint8_t reg, uint8_t* rxbuf, uint8_t len) { // Transmit buffer only uses first item for reg addr - uint8_t regarr[1] = {reg}; + uint8_t regarr[1]; + regarr[0] = reg; - HAL_Delay(1); + uint8_t dummyrx[12] = {0}; + uint8_t dummytx[12] = {0}; + // Assert the bus __cs_assert(); - HAL_Delay(1); // Send address - volatile HAL_StatusTypeDef res = HAL_SPI_Transmit(spiport, regarr, 1, 100); - HAL_Delay(1); + HAL_SPI_TransmitReceive(spiport, regarr, dummyrx, 1, 100); // Receive data - volatile HAL_StatusTypeDef res2 = HAL_SPI_Receive(spiport, rxbuf, len, 100); - HAL_Delay(1); + HAL_SPI_TransmitReceive(spiport, dummytx, rxbuf, len, 100); // Release bus __cs_deassert(); - HAL_Delay(1); } diff --git a/lib/ssd1306/ssd1306.c b/lib/ssd1306/ssd1306.c --- a/lib/ssd1306/ssd1306.c +++ b/lib/ssd1306/ssd1306.c @@ -60,10 +60,10 @@ void ssd1306_init(void) hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; + hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; hspi1.Init.NSS = SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; //16; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLED; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; diff --git a/src/display.c b/src/display.c --- a/src/display.c +++ b/src/display.c @@ -84,8 +84,8 @@ void display_process(void) if(temp_changed || state_changed) { char tempstr[16]; - snprintf(tempstr, 16, "Temp: %g", status->temp); - ssd1306_drawstring(" ", 3, 40); + snprintf(tempstr, 16, "Temp: %6.1f", status->temp); +// ssd1306_drawstring(" ", 3, 40); ssd1306_drawstring(tempstr, 3, 40); }