STM32F103C8T6_WIFI_Heating_system
Dependencies: mbed mbed-STM32F103C8T6 eeprom_flash Watchdog PinDetect DS1820
- Bluepill STM32F103C8T6 Heating system
- _This project is core part of bigger heating system project!_
Features
- Reading temperature from four DS18B20 sensors
- Making a decision about switching on/off heater and pomp
- Executing simple user commands from UART
- Storing state parameters to program memory (EEPROM emulation)
Diff: main.cpp
- Revision:
- 38:a0753c2a4497
- Parent:
- 37:c9b96afec535
- Child:
- 39:aa5f95061409
--- a/main.cpp Tue Sep 18 06:40:34 2018 +0000 +++ b/main.cpp Tue Sep 18 20:49:05 2018 +0000 @@ -7,6 +7,7 @@ #include "Watchdog.h" #include "eeprom_flash.h" #include <string> +#include "temp_controller.h" // Create a queue that can hold a maximum of 32 events EventQueue queue(32 * EVENTS_EVENT_SIZE); @@ -14,45 +15,19 @@ //Thread t; Watchdog wd; +unsigned int eeprom_config_value; +Serial pc(PA_2, PA_3); char a[128] = ""; // RX command buffer char i = 0; // RX char pointer static char recieved = 0; -Serial pc(PA_2, PA_3); + DigitalOut myled(LED1); DigitalOut pomp_OFF(PA_12); // pomp off DigitalOut heater_OFF(PA_15); // heater off -unsigned int epprom_value = 0; - -float temp[5] = { - 85,85,85,85,85 // initial temperature - }; - -int temp_error[5] = { - 0,0,0,0,0 // initial state - }; - -string labels[5] = { - "OUTDOOR", - "LITOS", - "MEBEL", - "HOT WATER", - "BACK WATER" - }; - -DS1820 ds1820[5] = { - DS1820(PA_9), // substitute PA_9 with actual mbed pin name connected to the OUTDOOR - DS1820(PA_8), // substitute PA_8 with actual mbed pin name connected to the INDOOR LITOS - DS1820(PA_7), // substitute PA_7 with actual mbed pin name connected to the INDOOR MEBEL - DS1820(PA_6), // substitute PA_6 with actual mbed pin name connected to the HOT WATER - DS1820(PA_5) // substitute PA_6 with actual mbed pin name connected to the HOT WATER - }; - - - // This function is called when a character goes into the RX buffer. void rxCallback() { char c; @@ -77,8 +52,9 @@ void pb_hit_interrupt (void) { + //writeEEPROMWord(0, 666 ); - epprom_value++; + //epprom_config_value++; pc.printf("Button pressed\r\n"); }; @@ -86,21 +62,7 @@ pc.printf("Button unpressed\r\n"); }; -void start_temp(){ - - __disable_irq(); - - for ( int j=0; j < 5; j++ ) { - if(ds1820[j].begin()) { - ds1820[j].startConversion(); - pc.printf("%s sensor present!\r\n", labels[j].c_str()); - } else { - pc.printf("No %s sensor found!\r\n", labels[j].c_str()); - }; - }; - __enable_irq(); - -}; + void at_command(){ if (recieved == 1) { @@ -113,7 +75,7 @@ if ( a[2]=='\0') { //pc.printf(a); - pc.printf("RAM=%u FLASH=%u OK\r\n", epprom_value, readEEPROMWord(0)); + pc.printf("RAM=%u FLASH=%u OK\r\n", eeprom_config_value, readEEPROMWord(0)); } else { pc.printf("Wrong AT command\r\n"); }; @@ -133,60 +95,13 @@ i = 0; }; }; - - -void check_temp(){ - - myled = 0; // turn the LED on - - // kick the watchdog - wd.Service(); - - __disable_irq(); - - for ( int j=0; j < 5; j++ ) { - - temp_error[j] = ds1820[j].read(temp[j]); // read temperature from DS1820 and perform cyclic redundancy check (CRC) - - switch(temp_error[j]) { - case 0: // no errors -> 'temp' contains the value of measured temperature - pc.printf("%s = %3.1fC \r\n", labels[j].c_str() , temp[j]); - break; - case 1: // no sensor present -> 'temp' is not updated - pc.printf("no %s sensor present \r\n", labels[j].c_str() ); - break; - case 2: // CRC error -> 'temp' is not updated - pc.printf("%s sensor CRC error \r\n", labels[j].c_str() ); - }; - // start temperature conversion from analog to digital - ds1820[j].startConversion(); - }; - - pc.printf("State %d|%d|%d|%d|%d\r\n", temp_error[0], temp_error[1], temp_error[2], temp_error[3], temp_error[4] ); - pc.printf("Temp %3.1f|%3.1f|%3.1f|%3.1f|%3.1f\r\n", temp[0], temp[1], temp[2], temp[3], temp[4] ); - pc.printf("======================================="); - - if (readEEPROMWord(0)!=epprom_value) { - enableEEPROMWriting(); - writeEEPROMWord(0,epprom_value); - disableEEPROMWriting(); - }; - - - __enable_irq(); - - myled = 1; // turn the LED off -}; - - - int main() { confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) - epprom_value = readEEPROMWord(0); - + eeprom_config_value = get_temp_config_value(); + wd.Configure(10.0); PinDetect pb(PA_11);