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:
12:187e02ab447f
Parent:
10:4b88be251088
Child:
14:d954558361b9
--- a/main.cpp	Mon Jun 26 13:53:25 2017 +0000
+++ b/main.cpp	Mon Sep 10 17:39:16 2018 +0000
@@ -1,20 +1,67 @@
 #include "stm32f103c8t6.h"
 #include "mbed.h"
+
+Serial  pc(PA_2, PA_3);
+
+char a[128] = "";       // RX command buffer
+char i = 0;             // RX char pointer
+char recieved = 0;
+
+// This function is called when a character goes into the RX buffer.
+void rxCallback() {
+    char c;
+    if (recieved == 0){ // skip if command was already received
+        c = pc.getc();
+        if ( c  == 0x0d || c  == 0x0a ) { 
+             recieved = 1;
+        } else {
+            if (i==16){     // max length of command from SERIAL
+                a[0] = c;
+                a[1] = '\0';
+                i = 0;
+            } else { 
+                a[i] = c;
+                i++;
+                a[i] = '\0';
+            };
+        };
+    };
+};
+ 
   
 int main() {
+        
     confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
+    DigitalOut  myled(LED1);
     
-    Serial      pc(PA_2, PA_3);
-    DigitalOut  myled(LED1);
+    pc.attach(&rxCallback, Serial::RxIrq);
+    pc.baud(115200);  
+    pc.printf("Hello world!\r\n");
     
     while(1) {
         // The on-board LED is connected, via a resistor, to +3.3V (not to GND). 
         // So to turn the LED on or off we have to set it to 0 or 1 respectively
         myled = 0;      // turn the LED on
-        wait_ms(200);   // 200 millisecond
+        wait_ms(50);   // 200 millisecond
+        myled = 1;      // turn the LED off
+        wait_ms(50);  // 1000 millisecond
+        myled = 0;      // turn the LED on
+        wait_ms(50);   // 200 millisecond
+        myled = 1;      // turn the LED off
+        wait_ms(50);  // 1000 millisecond
+        myled = 0;      // turn the LED on
+        wait_ms(50);   // 200 millisecond
         myled = 1;      // turn the LED off
         wait_ms(1000);  // 1000 millisecond
-        pc.printf("Blink\r\n");
+        if (recieved == 1) {
+            // command was recieved
+            pc.printf(a);
+            
+            // ready for new command
+            a[0] = '\0';
+            i = 0;
+            recieved = 0;
+        };
     }
 }
  
\ No newline at end of file