File diff 573011597aec → 6cc8fa5ae0f6
lib/max31856/max31856.c
Show inline comments
 
@@ -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);
 

	
 
}