@@ -76,25 +76,25 @@ SRC+=usb_endp.c
SRC+=usb_istr.c
SRC+=usb_prop.c
SRC+=usb_pwr.c
CDEFS=-DUSE_STDPERIPH_DRIVER
CDEFS+=-DSTM32L1XX
CDEFS+=-DMANGUSTA_DISCOVERY
#CDEFS+=-DUSE_USB_OTG_FS
CDEFS+=-DHSE_VALUE=8000000
#EMZ Optimized:
MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections
MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -mfloat-abi=soft
# Default: MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections
#MCUFLAGS=-mcpu=cortex-m4 -mthumb -mlittle-endian -mfpu=fpa -mfloat-abi=hard -mthumb-interwork
#MCUFLAGS=-mcpu=cortex-m4 -mfpu=vfpv4-sp-d16 -mfloat-abi=hard
COMMONFLAGS=-O$(OPTLVL) -g -Wall
CFLAGS=$(COMMONFLAGS) $(MCUFLAGS) $(INCLUDE) $(CDEFS)
LDLIBS=
LDFLAGS=$(COMMONFLAGS) -fno-exceptions -ffunction-sections -fdata-sections \
-nostartfiles -Wl,--gc-sections,-T$(LINKER_SCRIPT)
@@ -133,25 +133,25 @@ int main(void)
// Main loop
while(1)
{
// Process sensor inputs
process();
// Run state machine
machine();
}
// Read temperature and update global temp vars
int16_t temp = 0;
int32_t temp = 0;
uint8_t temp_frac = 0;
void update_temp() {
// Assert CS
GPIO_ResetBits(MAX_CS);
delay(1);
// This may not clock at all... might need to send 16 bits first
SPI_I2S_SendData(SPI2, 0xAAAA); // send dummy data
//SPI_I2S_SendData(SPI2, 0xAA); // send dummy data
uint16_t temp_pre = SPI_I2S_ReceiveData(SPI2);
@@ -172,28 +172,33 @@ void update_temp() {
temp_frac = temp_pre & 0b11; // get fractional part
temp_frac *= 25; // each bit is .25 a degree, up to fixed point
temp_pre = temp_pre >> 2; // Drop 2 fractional bits
if(sign) {
temp = -temp_pre;
else {
temp = temp_pre;
if(temp_units == TEMP_UNITS_FAHRENHEIT) {
temp *= 10; // fixed point mul by 1.8
temp *= 18;
temp /= 100;
temp *= 9; // fixed point mul by 1.8
temp /= 5;
temp += 32;
temp_frac *= 9;
temp_frac /= 5;
temp_frac += 32;
temp += temp_frac/100; // add overflow to above
temp_frac %= 100;
// Deassert CS
GPIO_SetBits(MAX_CS);
// PID implementation
// TODO: Make struct that has the last_temp and i_state in it, pass by ref. Make struct that has other input values maybe.
int16_t last_pid_temp = 0;
Status change: