@@ -88,9 +88,6 @@ int main(void)
HAL_Delay(1000);
HAL_GPIO_WritePin(LED_POWER, 1);
/// BEGIN IMPORT/////////////////////////////////////////
// TODO: Awesome pwm of power LED
// Configure 1ms SysTick (change if more temporal resolution needed)
@@ -116,7 +113,6 @@ int main(void)
if(boottobrew)
state = STATE_PREHEAT_BREW; // Go to brew instead of idle if configured thusly
// Main loop
while(1)
{
@@ -127,15 +123,6 @@ int main(void)
machine();
}
/* OLD MAIN
for (;;) {
CDC_Transmit_FS("a", 1); //sizeof(str)); for(count=0; count<32000000; count++); //#endif
HAL_Delay(300);
*/
/** System Clock Configuration
@@ -167,42 +154,35 @@ void SystemClock_Config(void)
// Read temperature and update global temp vars
int32_t temp = 0;
uint8_t temp_frac = 0;
uint8_t state_resume = 0;
// FIXME: Now this needs to work 8bits at a time, or change the port mode on the fly
void update_temp() {
// Assert CS
HAL_GPIO_WritePin(MAX_CS, 0);
HAL_Delay(100);
// This may not clock at all... might need to send 16 bits first
// SPI_I2S_SendData(SPI2, 0xAAAA); // send dummy data
uint8_t rxdatah[1] = {0x00};
uint8_t rxdatal[1] = {0x00};
HAL_SPI_Receive(&hspi1, rxdatah, 1, 100);
HAL_SPI_Receive(&hspi1, rxdatal, 1, 100);
// Deassert CS
// Release CS
HAL_Delay(1);
HAL_GPIO_WritePin(MAX_CS, 1);
//OLD: SPI_I2S_SendData(SPI2, 0xAA); // send dummy data
// OLD: uint16_t temp_pre = SPI_I2S_ReceiveData(SPI2);
// Assemble data array into one var
uint16_t temp_pre = rxdatal[0] | (rxdatah[0]<<8);
if(temp_pre & 0b0000000000000010) {
ssd1306_clearscreen();
ssd1306_DrawString("Fatal Error", 3, 35);
state = STATE_TC_ERROR;
else if(temp_pre & 0b0000000000000001 && !ignore_tc_error) {
@@ -226,23 +206,29 @@ void update_temp() {
temp_frac *= 25; // each bit is .25 a degree, up to fixed point
temp_pre = temp_pre >> 2; // Drop 2 fractional bits
int8_t signint;
if(sign) {
temp = -temp_pre;
signint = -1;
else {
temp = temp_pre;
signint = 1;
if(temp_units == TEMP_UNITS_FAHRENHEIT) {
temp *= 9; // fixed point mul by 1.8
temp /= 5;
temp += 32;
// Convert to Fahrenheit
if(temp_units == TEMP_UNITS_FAHRENHEIT)
temp = signint * ((temp_pre*100) + temp_frac);
temp = temp * 1.8;
temp += 3200;
temp_frac = temp % 100;
temp /= 100;
temp_frac *= 9;
temp_frac /= 5;
temp_frac += 32;
temp += temp_frac/100; // add overflow to above
temp_frac %= 100;
// Use Celsius values
else
temp = temp_pre * signint;
@@ -250,9 +236,13 @@ void update_temp() {
CDC_Transmit_FS("Temp: ", 6);
char tempstr[6];
zitoa(temp, tempstr);
CDC_Transmit_FS(tempstr, 1); //sizeof(tempstr));
CDC_Transmit_FS(tempstr, sizeof(tempstr));
CDC_Transmit_FS("\r\n", 2);
Status change: