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-12
- Revision:
- 17:718e41e971f8
- Parent:
- 16:c7b77648311d
- Child:
- 18:9434e06223c7
File content as of revision 17:718e41e971f8:
#include "stm32f103c8t6.h" #include "mbed.h" #include "DS1820.h" char a[128] = ""; // RX command buffer char i = 0; // RX char pointer static char recieved = 0; Serial pc(PA_2, PA_3); // 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 ) { 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); DS1820 ds1820(PA_9); // substitute PA_9 with actual mbed pin name connected to the DS1820 data pin float temp = 0; int error = 0; pc.attach(&rxCallback, Serial::RxIrq); pc.baud(115200); pc.printf("Hello world! Mbed version\r\n"); if(ds1820.begin()) { pc.printf("DS1820 sensor found!\r\n"); } else { pc.printf("No DS1820 sensor found!\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(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 ds1820.startConversion(); // start temperature conversion from analog to digital wait(1.0); // let DS1820 complete the temperature conversion error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) switch(error) { case 0: // no errors -> 'temp' contains the value of measured temperature pc.printf("sensor temp = %3.1f%cC\r\n", temp, 176); break; case 1: // no sensor present -> 'temp' is not updated pc.printf("no sensor present\n\r"); break; case 2: // CRC error -> 'temp' is not updated pc.printf("sensor CRC error\r\n"); } if (recieved == 1) { // command was recieved pc.printf(a); // ready for new command recieved = 0; a[0] = '\0'; i = 0; }; } }