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)
main.cpp
- Committer:
- andrewklmn
- Date:
- 2018-09-18
- Revision:
- 38:a0753c2a4497
- Parent:
- 37:c9b96afec535
- Child:
- 39:aa5f95061409
File content as of revision 38:a0753c2a4497:
#include "stm32f103c8t6.h" #include "mbed.h" #include "mbed_events.h" #include <stdio.h> #include "DS1820.h" #include "PinDetect.h" #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); // Create a thread that'll run the event queue's dispatch function //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; DigitalOut myled(LED1); DigitalOut pomp_OFF(PA_12); // pomp off DigitalOut heater_OFF(PA_15); // heater off // 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 a[0] = c; a[1] = '\0'; i = 0; } else { a[i] = c; i++; a[i] = '\0'; }; }; }; }; void pb_hit_interrupt (void) { //writeEEPROMWord(0, 666 ); //epprom_config_value++; pc.printf("Button pressed\r\n"); }; void pb_out_interrupt (void) { pc.printf("Button unpressed\r\n"); }; void at_command(){ if (recieved == 1) { __disable_irq(); // command was recieved if (a[0]=='A' && a[1]=='T') { if ( a[2]=='\0') { //pc.printf(a); pc.printf("RAM=%u FLASH=%u OK\r\n", eeprom_config_value, readEEPROMWord(0)); } else { pc.printf("Wrong AT command\r\n"); }; //readEEPROMWord(0x01); } else { pc.printf("Wrong request\r\n"); }; // process_command(a); __enable_irq(); // ready for new command recieved = 0; a[0] = '\0'; i = 0; }; }; int main() { confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) eeprom_config_value = get_temp_config_value(); wd.Configure(10.0); PinDetect pb(PA_11); pb.mode(PullUp); // Delay for initial pullup to take effect wait(.005); pb.attach_deasserted(&pb_hit_interrupt); pb.attach_asserted(&pb_out_interrupt); //pb.rise(&pb_out_interrupt); pb.setSampleFrequency(); pc.attach(&rxCallback, Serial::RxIrq); pc.baud(115200); pc.printf("\r\n\r\nWifi Heating system\r\n"); pomp_OFF = 0; heater_OFF = 0; wait(0.25); pomp_OFF = 1; heater_OFF = 1; wait(0.25); pomp_OFF = 0; heater_OFF = 0; wait(0.25); pomp_OFF = 1; heater_OFF = 1; wait(0.25); queue.call( start_temp ); queue.call_every(100, at_command); queue.call_every(2000, check_temp); // Start queue queue.dispatch(); };