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
 
@@ -2,24 +2,24 @@
 
<project>
 
	<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1538442532" name="Debug">
 
		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
 
			<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>
 
		</extension>
 
	</configuration>
 
	<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.release.1229152259" name="Release">
 
		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
 
			<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>
 
		</extension>
 
	</configuration>
 
</project>
inc/tempsense.h
Show inline comments
 
@@ -4,9 +4,10 @@
 

	
 
#define TEMPSENSE_MAX_CS_PIN GPIO_PIN_15
 
#define TEMPSENSE_MAX_CS_PORT GPIOA
 

	
 

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

	
 
#endif
lib/max31856/max31856.c
Show inline comments
 
@@ -7,13 +7,13 @@
 
#include "error.h"
 

	
 
// Private variables
 
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;
 

	
 

	
 
// Private prototypes
 
static void __cs_assert(void);
 
@@ -45,25 +45,25 @@ void max31856_init(SPI_HandleTypeDef* sp
 
	// - probably no filtering, we'll do that on this side of things
 
	// - set up to read the typical open/short faults but not the high/low alarms
 

	
 

	
 
	// 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);
 

	
 
	// sensor type - could we just mask bits off? maybe optimize the enum for this
 
}
 

	
 

	
 
// 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);
 

	
 

	
 
	int32_t temp24 = tempbuf[0] << 16 | tempbuf[1] << 8 | tempbuf[0];
 
	if (temp24 & 0x800000) {
 
		temp24 |= 0xFF000000;  // fix sign
 
@@ -71,20 +71,21 @@ void max31856_process(void)
 

	
 
	temp24 >>= 5;  // bottom 5 bits are unused
 

	
 
	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);
 

	
 
}
 

	
 

	
 
// Return latest temperature reading (unaveraged, deg C)
 
float max31856_latest_temp(void)
 
@@ -107,36 +108,44 @@ static void __write_reg(uint8_t reg, uin
 

	
 
	uint8_t outarr[2] = {reg, data};
 

	
 
	// 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();
 
}
 

	
 
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};
 

	
 

	
 
	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);
 

	
 
}
 

	
 
static void __cs_assert(void)
 
{
 
	HAL_GPIO_WritePin(csport, cspin, 0);
lib/max31856/max31856.h
Show inline comments
 
#ifndef MAX31856_H
 
#define MAX31856_H
 

	
 
#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);
 

	
 
// Thanks to Adafruit:
 
#define MAX31856_CR0_REG           0x00
 
#define MAX31856_CR0_AUTOCONVERT   0x80
lib/ssd1306/ssd1306.c
Show inline comments
 
@@ -60,17 +60,17 @@ 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.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);
 
 
 
	// Generate a reset
 
	SSD_Reset_Low();
 
	uint32_t i;
src/main.c
Show inline comments
 
@@ -62,13 +62,13 @@ int main(void)
 
			last_1hz = HAL_GetTick();
 
		}
 
 
		if(HAL_GetTick() - last_5hz > 200)
 
		{
 
			tempsense_readtemp();
 
//			runtime_status = tempsense_gettemp();
 
			runtime_status()->temp = tempsense_gettemp();
 
			last_5hz = HAL_GetTick();
 
		}
 
 
        if(flash_getsettings()->val.control_mode == MODE_PID && (HAL_GetTick() - last_pid > PID_PERIOD))
 
        {
 
//        	runtime_status()->temp = tempsense_readtemp();
src/system/flash.c
Show inline comments
 
@@ -70,12 +70,13 @@ void flash_restoresettings(void)
 
	else
 
	{
 
		settings.val.k_p = 10;
 
		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;
 
	}
 
}
 
 
 
// Accessor to retrieve settings structure
src/tempsense.c
Show inline comments
 
@@ -19,25 +19,26 @@ void tempsense_init(void)
 
	// we need to re-init...
 

	
 

	
 
}
 

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

	
 
	switch(flash_getsettings()->val.sensor_type)
 
	{
 
		case SENSOR_TC_K:
 
		case SENSOR_TC_E:
 
		case SENSOR_TC_N:
 
		case SENSOR_TC_R:
 
		case SENSOR_TC_S:
 
		case SENSOR_TC_T:
 
		{
 
			// Read MAX31856
 
			max31856_process();
 
		} break;
 

	
 
		case SENSOR_NTC:
 
		{
 
			// Read analog value from internal ADC, linearize the reading, etc
 
		} break;
 
@@ -46,8 +47,11 @@ float tempsense_readtemp(void)
 

	
 
	// either return latest reading from DMA loop (NTC, etc)
 
	// or initiate a blocking read and return it.
 
	// Need to gracefully handle the timeout...
 
}
 

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

	
 

	
0 comments (0 inline, 0 general)