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)

Committer:
andrewklmn
Date:
Fri Sep 21 17:56:25 2018 +0000
Revision:
39:aa5f95061409
Parent:
38:a0753c2a4497
Child:
41:978c2d85a0e7
modes added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 5:3c3ef17a17a6 1 #include "stm32f103c8t6.h"
hudakz 0:ab218237069e 2 #include "mbed.h"
andrewklmn 27:007e17df5ba0 3 #include "mbed_events.h"
andrewklmn 27:007e17df5ba0 4 #include <stdio.h>
andrewklmn 17:718e41e971f8 5 #include "DS1820.h"
andrewklmn 26:750f21025bb9 6 #include "PinDetect.h"
andrewklmn 31:0a516ceaec4d 7 #include "Watchdog.h"
andrewklmn 35:74a546766adb 8 #include "eeprom_flash.h"
andrewklmn 19:74f78a777ffa 9 #include <string>
andrewklmn 38:a0753c2a4497 10 #include "temp_controller.h"
andrewklmn 12:187e02ab447f 11
andrewklmn 27:007e17df5ba0 12 // Create a queue that can hold a maximum of 32 events
andrewklmn 27:007e17df5ba0 13 EventQueue queue(32 * EVENTS_EVENT_SIZE);
andrewklmn 27:007e17df5ba0 14 // Create a thread that'll run the event queue's dispatch function
andrewklmn 27:007e17df5ba0 15 //Thread t;
andrewklmn 27:007e17df5ba0 16
andrewklmn 32:aebbfe391bbc 17 Watchdog wd;
andrewklmn 38:a0753c2a4497 18 unsigned int eeprom_config_value;
andrewklmn 27:007e17df5ba0 19
andrewklmn 39:aa5f95061409 20 Serial pc(PA_2, PA_3); // (TX, RX) Pin definition
andrewklmn 12:187e02ab447f 21 char a[128] = ""; // RX command buffer
andrewklmn 12:187e02ab447f 22 char i = 0; // RX char pointer
andrewklmn 14:d954558361b9 23 static char recieved = 0;
andrewklmn 12:187e02ab447f 24
andrewklmn 38:a0753c2a4497 25
andrewklmn 23:33d6689834c6 26 DigitalOut myled(LED1);
andrewklmn 17:718e41e971f8 27
andrewklmn 34:09d8edcce624 28 DigitalOut pomp_OFF(PA_12); // pomp off
andrewklmn 34:09d8edcce624 29 DigitalOut heater_OFF(PA_15); // heater off
andrewklmn 34:09d8edcce624 30
andrewklmn 12:187e02ab447f 31 // This function is called when a character goes into the RX buffer.
andrewklmn 12:187e02ab447f 32 void rxCallback() {
andrewklmn 12:187e02ab447f 33 char c;
andrewklmn 14:d954558361b9 34 c = pc.getc();
andrewklmn 12:187e02ab447f 35 if (recieved == 0){ // skip if command was already received
andrewklmn 12:187e02ab447f 36 if ( c == 0x0d || c == 0x0a ) {
andrewklmn 29:5940a80717e4 37 while ( pc.readable() ) c = pc.getc();
andrewklmn 12:187e02ab447f 38 recieved = 1;
andrewklmn 12:187e02ab447f 39 } else {
andrewklmn 12:187e02ab447f 40 if (i==16){ // max length of command from SERIAL
andrewklmn 12:187e02ab447f 41 a[0] = c;
andrewklmn 12:187e02ab447f 42 a[1] = '\0';
andrewklmn 12:187e02ab447f 43 i = 0;
andrewklmn 12:187e02ab447f 44 } else {
andrewklmn 12:187e02ab447f 45 a[i] = c;
andrewklmn 12:187e02ab447f 46 i++;
andrewklmn 12:187e02ab447f 47 a[i] = '\0';
andrewklmn 12:187e02ab447f 48 };
andrewklmn 14:d954558361b9 49 };
andrewklmn 12:187e02ab447f 50 };
andrewklmn 12:187e02ab447f 51 };
andrewklmn 12:187e02ab447f 52
andrewklmn 23:33d6689834c6 53
andrewklmn 23:33d6689834c6 54 void pb_hit_interrupt (void) {
andrewklmn 38:a0753c2a4497 55
andrewklmn 37:c9b96afec535 56 //writeEEPROMWord(0, 666 );
andrewklmn 38:a0753c2a4497 57 //epprom_config_value++;
andrewklmn 27:007e17df5ba0 58 pc.printf("Button pressed\r\n");
andrewklmn 23:33d6689834c6 59 };
andrewklmn 25:49e5d653d789 60
andrewklmn 25:49e5d653d789 61 void pb_out_interrupt (void) {
andrewklmn 27:007e17df5ba0 62 pc.printf("Button unpressed\r\n");
andrewklmn 25:49e5d653d789 63 };
andrewklmn 27:007e17df5ba0 64
andrewklmn 38:a0753c2a4497 65
andrewklmn 27:007e17df5ba0 66 void at_command(){
andrewklmn 27:007e17df5ba0 67 if (recieved == 1) {
andrewklmn 27:007e17df5ba0 68
andrewklmn 32:aebbfe391bbc 69 __disable_irq();
andrewklmn 32:aebbfe391bbc 70
andrewklmn 27:007e17df5ba0 71 // command was recieved
andrewklmn 32:aebbfe391bbc 72
andrewklmn 32:aebbfe391bbc 73 if (a[0]=='A' && a[1]=='T') {
andrewklmn 32:aebbfe391bbc 74
andrewklmn 32:aebbfe391bbc 75 if ( a[2]=='\0') {
andrewklmn 32:aebbfe391bbc 76 //pc.printf(a);
andrewklmn 38:a0753c2a4497 77 pc.printf("RAM=%u FLASH=%u OK\r\n", eeprom_config_value, readEEPROMWord(0));
andrewklmn 33:2c54746f7518 78 } else {
andrewklmn 39:aa5f95061409 79 pc.printf("Wrong command\r\n");
andrewklmn 32:aebbfe391bbc 80 };
andrewklmn 37:c9b96afec535 81
andrewklmn 37:c9b96afec535 82 //readEEPROMWord(0x01);
andrewklmn 32:aebbfe391bbc 83 } else {
andrewklmn 39:aa5f95061409 84 pc.printf("Bad request\r\n");
andrewklmn 32:aebbfe391bbc 85 };
andrewklmn 27:007e17df5ba0 86
andrewklmn 27:007e17df5ba0 87 // process_command(a);
andrewklmn 27:007e17df5ba0 88
andrewklmn 32:aebbfe391bbc 89 __enable_irq();
andrewklmn 32:aebbfe391bbc 90
andrewklmn 27:007e17df5ba0 91 // ready for new command
andrewklmn 27:007e17df5ba0 92 recieved = 0;
andrewklmn 27:007e17df5ba0 93 a[0] = '\0';
andrewklmn 27:007e17df5ba0 94 i = 0;
andrewklmn 27:007e17df5ba0 95 };
andrewklmn 27:007e17df5ba0 96 };
andrewklmn 39:aa5f95061409 97
hudakz 10:4b88be251088 98
hudakz 0:ab218237069e 99 int main() {
andrewklmn 12:187e02ab447f 100
hudakz 10:4b88be251088 101 confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock)
andrewklmn 37:c9b96afec535 102
andrewklmn 38:a0753c2a4497 103 eeprom_config_value = get_temp_config_value();
andrewklmn 38:a0753c2a4497 104
andrewklmn 37:c9b96afec535 105 wd.Configure(10.0);
andrewklmn 32:aebbfe391bbc 106
andrewklmn 26:750f21025bb9 107 PinDetect pb(PA_11);
andrewklmn 23:33d6689834c6 108 pb.mode(PullUp);
andrewklmn 26:750f21025bb9 109
andrewklmn 26:750f21025bb9 110 // Delay for initial pullup to take effect
andrewklmn 26:750f21025bb9 111 wait(.005);
andrewklmn 26:750f21025bb9 112
andrewklmn 26:750f21025bb9 113 pb.attach_deasserted(&pb_hit_interrupt);
andrewklmn 26:750f21025bb9 114 pb.attach_asserted(&pb_out_interrupt);
andrewklmn 26:750f21025bb9 115 //pb.rise(&pb_out_interrupt);
andrewklmn 26:750f21025bb9 116 pb.setSampleFrequency();
andrewklmn 22:32beca745706 117
andrewklmn 12:187e02ab447f 118 pc.attach(&rxCallback, Serial::RxIrq);
andrewklmn 15:721546347507 119 pc.baud(115200);
andrewklmn 39:aa5f95061409 120 pc.printf("\r\nNaumovich 2.0\r\n");
andrewklmn 19:74f78a777ffa 121
andrewklmn 27:007e17df5ba0 122
andrewklmn 34:09d8edcce624 123 pomp_OFF = 0;
andrewklmn 34:09d8edcce624 124 heater_OFF = 0;
andrewklmn 34:09d8edcce624 125 wait(0.25);
andrewklmn 34:09d8edcce624 126 pomp_OFF = 1;
andrewklmn 34:09d8edcce624 127 heater_OFF = 1;
andrewklmn 34:09d8edcce624 128 wait(0.25);
andrewklmn 34:09d8edcce624 129 pomp_OFF = 0;
andrewklmn 34:09d8edcce624 130 heater_OFF = 0;
andrewklmn 34:09d8edcce624 131 wait(0.25);
andrewklmn 34:09d8edcce624 132 pomp_OFF = 1;
andrewklmn 34:09d8edcce624 133 heater_OFF = 1;
andrewklmn 34:09d8edcce624 134 wait(0.25);
andrewklmn 34:09d8edcce624 135
andrewklmn 17:718e41e971f8 136
andrewklmn 27:007e17df5ba0 137 queue.call( start_temp );
andrewklmn 27:007e17df5ba0 138 queue.call_every(100, at_command);
andrewklmn 37:c9b96afec535 139 queue.call_every(2000, check_temp);
andrewklmn 39:aa5f95061409 140 queue.call_every(3000, process_temp);
andrewklmn 27:007e17df5ba0 141
andrewklmn 27:007e17df5ba0 142 // Start queue
andrewklmn 27:007e17df5ba0 143 queue.dispatch();
andrewklmn 22:32beca745706 144 };
hudakz 8:f1432e9af6c8 145