Simple test program to get familiar with functionality of MBED RTOS on ST Nucleo-F411RE. Tasks for LED blinking, user button, temperature measurement with DS1620, temperature measurement with internal temperature sensor of ST32F411RE, ultrasonic distance measurement and displaying result on 16x2 TextLCD.

Dependencies:   DS1620_improved TextLCD_improved mbed-rtos mbed

Committer:
Jan Tetour
Date:
Fri Dec 18 20:00:56 2015 +0100
Revision:
18:be0130c42925
Parent:
17:94c385ff2641
Minor formatting changes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jan Tetour 18:be0130c42925 1 /*
Jan Tetour 18:be0130c42925 2 * TSK_TEMP.CPP
Jan Tetour 18:be0130c42925 3 */
dzoni 9:645f0e517017 4 #include "mbed.h"
dzoni 9:645f0e517017 5 #include "rtos.h"
dzoni 9:645f0e517017 6
dzoni 9:645f0e517017 7 #include "DS1620.h"
dzoni 9:645f0e517017 8
dzoni 17:94c385ff2641 9 #include "tsk_main.h"
dzoni 9:645f0e517017 10 #include "tsk_temp.h"
dzoni 9:645f0e517017 11
dzoni 9:645f0e517017 12
dzoni 17:94c385ff2641 13 struct temp_data_struct temp_data;
dzoni 9:645f0e517017 14
dzoni 9:645f0e517017 15 static DS1620 ds1620Sensor(PB_4, PB_10, PB_3);
dzoni 9:645f0e517017 16
dzoni 9:645f0e517017 17
dzoni 11:e89f89c0920b 18 uint32_t initDS1620Temp(void const *args) {
dzoni 9:645f0e517017 19
dzoni 17:94c385ff2641 20 temp_data.temperature = 10.0f;
dzoni 17:94c385ff2641 21 temp_data.temp_raw = 10;
dzoni 17:94c385ff2641 22
dzoni 17:94c385ff2641 23 ds1620Sensor.setSerialClockFrequency(freq250k);
dzoni 9:645f0e517017 24
dzoni 9:645f0e517017 25 if ((ds1620Sensor.readConfig() & 0x03) != 0x03) {
dzoni 9:645f0e517017 26 ds1620Sensor.writeConfig(0x03);
dzoni 9:645f0e517017 27 }
dzoni 11:e89f89c0920b 28
dzoni 11:e89f89c0920b 29 if ((ds1620Sensor.readConfig() & 0x03) != 0x03) {
dzoni 11:e89f89c0920b 30 return 0;
dzoni 11:e89f89c0920b 31 }
dzoni 11:e89f89c0920b 32
dzoni 11:e89f89c0920b 33 return 1;
dzoni 9:645f0e517017 34 }
dzoni 9:645f0e517017 35
dzoni 9:645f0e517017 36 void temp_thread(void const *args) {
dzoni 9:645f0e517017 37
dzoni 17:94c385ff2641 38 float temp;
dzoni 17:94c385ff2641 39 uint32_t temp_raw;
dzoni 17:94c385ff2641 40
dzoni 9:645f0e517017 41 while (true) {
dzoni 9:645f0e517017 42 ds1620Sensor.startConversion();
dzoni 9:645f0e517017 43
dzoni 9:645f0e517017 44 // Wait for conversion completion (Tconv = 750 ms typ)
dzoni 9:645f0e517017 45 Thread::wait(750);
dzoni 9:645f0e517017 46 while (!(ds1620Sensor.readConfig() & 0x80))
dzoni 9:645f0e517017 47 Thread::wait(10);
dzoni 9:645f0e517017 48
dzoni 17:94c385ff2641 49 temp = ds1620Sensor.getHighResolutionTemperature();
dzoni 17:94c385ff2641 50 temp_raw = ds1620Sensor.readTemperatureRaw();
dzoni 17:94c385ff2641 51
dzoni 17:94c385ff2641 52 mutexTemp.lock();
dzoni 17:94c385ff2641 53 temp_data.temperature = temp;
dzoni 17:94c385ff2641 54 temp_data.temp_raw = temp_raw;
dzoni 17:94c385ff2641 55 mutexTemp.unlock();
dzoni 17:94c385ff2641 56
dzoni 17:94c385ff2641 57 Thread::wait(1250);
dzoni 9:645f0e517017 58 }
dzoni 9:645f0e517017 59 }