Changeset - 573011597aec
[Not reviewed]
default
0 8 0
Ethan Zonca - 8 years ago 2017-07-25 07:14:34
ez@ethanzonca.com
Attempt to get temp working
8 files changed with 34 insertions and 19 deletions:
0 comments (0 inline, 0 general)
.settings/language.settings.xml
Show inline comments
 
@@ -5,7 +5,7 @@
 
			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 
			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-796171634606229038" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1073395970633912068" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
				<language-scope id="org.eclipse.cdt.core.gcc"/>
 
				<language-scope id="org.eclipse.cdt.core.g++"/>
 
			</provider>
 
@@ -16,7 +16,7 @@
 
			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 
			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-786907217906447192" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1105339482864355034" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
				<language-scope id="org.eclipse.cdt.core.gcc"/>
 
				<language-scope id="org.eclipse.cdt.core.g++"/>
 
			</provider>
inc/tempsense.h
Show inline comments
 
@@ -7,6 +7,7 @@
 

	
 

	
 
void tempsense_init(void);
 
float tempsense_readtemp(void);
 
void tempsense_readtemp(void);
 
float tempsense_gettemp(void);
 

	
 
#endif
lib/max31856/max31856.c
Show inline comments
 
@@ -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);
 

	
 
}
 

	
lib/max31856/max31856.h
Show inline comments
 
@@ -4,7 +4,7 @@
 
#include "stm32f3xx_hal.h"
 

	
 
void max31856_init(SPI_HandleTypeDef* spi_port, GPIO_TypeDef* cs_port, uint32_t cs_pin, uint32_t sensor_type);
 
void max31856_process(void);
 
float max31856_process(void);
 
float max31856_latest_temp(void);
 
float max31856_avg_temp(void);
 

	
lib/ssd1306/ssd1306.c
Show inline comments
 
@@ -63,11 +63,11 @@ void ssd1306_init(void)
 
	hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
 
	hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
 
	hspi1.Init.NSS = SPI_NSS_SOFT;
 
	hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
 
	hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; //16;
 
	hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
 
	hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
 
	hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
 
	hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLED;
 
	hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLED;
 
	HAL_SPI_Init(&hspi1);
 
 
src/main.c
Show inline comments
 
@@ -65,7 +65,7 @@ int main(void)
 
		if(HAL_GetTick() - last_5hz > 200)
 
		{
 
			tempsense_readtemp();
 
//			runtime_status = tempsense_gettemp();
 
			runtime_status()->temp = tempsense_gettemp();
 
			last_5hz = HAL_GetTick();
 
		}
 
src/system/flash.c
Show inline comments
 
@@ -73,6 +73,7 @@ void flash_restoresettings(void)
 
		settings.val.k_i = 0;
 
		settings.val.k_d = 0;
 
		settings.val.windup_guard = 300;
 
		settings.val.sensor_type = 1;
 
		//torestore.values.can_id = 22;
 
	}
 
}
src/tempsense.c
Show inline comments
 
@@ -22,7 +22,7 @@ void tempsense_init(void)
 
}
 

	
 
// Returns the latest reading from the configured temperature sensor
 
float tempsense_readtemp(void)
 
void tempsense_readtemp(void)
 
{
 

	
 
	switch(flash_getsettings()->val.sensor_type)
 
@@ -35,6 +35,7 @@ float tempsense_readtemp(void)
 
		case SENSOR_TC_T:
 
		{
 
			// Read MAX31856
 
			max31856_process();
 
		} break;
 

	
 
		case SENSOR_NTC:
 
@@ -49,5 +50,8 @@ float tempsense_readtemp(void)
 
	// Need to gracefully handle the timeout...
 
}
 

	
 
float tempsense_gettemp(void)
 
{
 
	return max31856_latest_temp();
 
}
 

	
 

	
0 comments (0 inline, 0 general)