STM32F103C8T6_WIFI_Heating_system

Dependencies:   mbed mbed-STM32F103C8T6 eeprom_flash Watchdog PinDetect DS1820

  1. Bluepill STM32F103C8T6 Heating system
    1. _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)

Revision:
29:5940a80717e4
Parent:
27:007e17df5ba0
Child:
30:b696b5799507
--- a/main.cpp	Sun Sep 16 08:46:15 2018 +0000
+++ b/main.cpp	Sun Sep 16 16:47:24 2018 +0000
@@ -45,12 +45,34 @@
                         };
 
 
+class Watchdog {
+public:
+// Load timeout value in watchdog timer and enable
+    void kick(float s) {
+        LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+        uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
+        LPC_WDT->WDTC = s * (float)clk;
+        LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
+        kick();
+    }
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+    void kick() {
+        LPC_WDT->WDFEED = 0xAA;
+        LPC_WDT->WDFEED = 0x55;
+    }
+};
+
+
+
+
 // This function is called when a character goes into the RX buffer.
 void rxCallback() {
     char c;
     c = pc.getc();
     if (recieved == 0){ // skip if command was already received
         if ( c  == 0x0d || c  == 0x0a ) { 
+             while ( pc.readable() ) c = pc.getc();
              recieved = 1;
         } else {
             if (i==16){     // max length of command from SERIAL
@@ -76,6 +98,9 @@
 }; 
 
 void start_temp(){
+    
+    __disable_irq(); 
+        
     for ( int j=0; j < 5; j++ ) {
         if(ds1820[j].begin()) { 
             ds1820[j].startConversion();
@@ -84,6 +109,8 @@
             pc.printf("No %s sensor found!\r\n", labels[j].c_str());         
         };
     };
+    __enable_irq(); 
+        
 };
 
 void at_command(){
@@ -107,6 +134,9 @@
        
        myled = 0;      // turn the LED on
        
+       
+       __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)
@@ -124,13 +154,17 @@
             // 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("=======================================");
+        
+        __enable_irq(); 
+        
         myled = 1;      // turn the LED off
 };
 
+Watchdog wdt;
 
   
 int main() {
@@ -140,6 +174,8 @@
     PinDetect   pb(PA_11);
     pb.mode(PullUp);
     
+    wdt.kick(10.0);  
+    
     // Delay for initial pullup to take effect
     wait(.005);