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:
dzoni
Date:
Fri Dec 18 15:23:21 2015 +0000
Revision:
17:94c385ff2641
Parent:
15:a627638edd9c
Child:
18:be0130c42925
Bugfixes. Works but freezes after some time. Button task requires rewrite (InterruptIn).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dzoni 9:645f0e517017 1 #include "mbed.h"
dzoni 9:645f0e517017 2 #include "rtos.h"
dzoni 9:645f0e517017 3
dzoni 9:645f0e517017 4 #include "TextLCD.h"
dzoni 9:645f0e517017 5
dzoni 17:94c385ff2641 6 #include "tsk_main.h"
dzoni 9:645f0e517017 7 #include "tsk_display.h"
dzoni 9:645f0e517017 8 #include "tsk_temp.h"
dzoni 17:94c385ff2641 9 #include "tsk_inttemp.h"
dzoni 9:645f0e517017 10 #include "tsk_dist.h"
dzoni 9:645f0e517017 11
dzoni 15:a627638edd9c 12 static TextLCD *lcd;
dzoni 9:645f0e517017 13
dzoni 12:1de8b271e292 14 uint32_t initDisplay(void const *args) {
dzoni 13:f62b10a6e1c5 15
dzoni 13:f62b10a6e1c5 16 lcd = new TextLCD(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2);
dzoni 13:f62b10a6e1c5 17
dzoni 17:94c385ff2641 18 wait_ms(250);
dzoni 13:f62b10a6e1c5 19 lcd->cls();
dzoni 13:f62b10a6e1c5 20
dzoni 13:f62b10a6e1c5 21 return 1;
dzoni 13:f62b10a6e1c5 22 }
dzoni 13:f62b10a6e1c5 23
dzoni 13:f62b10a6e1c5 24 uint32_t disposeDisplay(void const *args) {
dzoni 13:f62b10a6e1c5 25
dzoni 13:f62b10a6e1c5 26 delete lcd;
dzoni 13:f62b10a6e1c5 27 lcd = NULL;
dzoni 13:f62b10a6e1c5 28
dzoni 12:1de8b271e292 29 return 1;
dzoni 12:1de8b271e292 30 }
dzoni 12:1de8b271e292 31
dzoni 12:1de8b271e292 32
dzoni 9:645f0e517017 33 void disp_thread(void const *args) {
dzoni 17:94c385ff2641 34 float dist;
dzoni 17:94c385ff2641 35 float temp;
dzoni 17:94c385ff2641 36 float intTemp;
dzoni 17:94c385ff2641 37 uint32_t dist_raw;
dzoni 17:94c385ff2641 38 uint32_t temp_raw;
dzoni 17:94c385ff2641 39
dzoni 17:94c385ff2641 40 while (true) {
dzoni 17:94c385ff2641 41 mutexDist.lock();
dzoni 17:94c385ff2641 42 dist = dist_data.distance;
dzoni 17:94c385ff2641 43 dist_raw = dist_data.timerTicks;
dzoni 17:94c385ff2641 44 mutexDist.unlock();
dzoni 9:645f0e517017 45
dzoni 17:94c385ff2641 46 mutexTemp.lock();
dzoni 17:94c385ff2641 47 temp = temp_data.temperature;
dzoni 17:94c385ff2641 48 temp_raw = temp_data.temp_raw;
dzoni 17:94c385ff2641 49 mutexTemp.unlock();
dzoni 17:94c385ff2641 50
dzoni 17:94c385ff2641 51 mutexIntTemp.lock();
dzoni 17:94c385ff2641 52 intTemp = int_temp_data.temperature;
dzoni 17:94c385ff2641 53 mutexIntTemp.unlock();
dzoni 17:94c385ff2641 54
dzoni 17:94c385ff2641 55 uiCnt += 2;
dzoni 17:94c385ff2641 56
dzoni 13:f62b10a6e1c5 57 lcd->cls();
dzoni 17:94c385ff2641 58 // lcd->printf("%4.2fmm (%4u)", dist, dist_raw);
dzoni 17:94c385ff2641 59 lcd->printf("%4.2fmm (%4u)", dist, uiCnt);
dzoni 13:f62b10a6e1c5 60 lcd->locate(0, 1);
dzoni 17:94c385ff2641 61 // lcd->printf("%3.2f%cC (%3u)", temp, 0xdf, temp_raw);
dzoni 17:94c385ff2641 62 lcd->printf("%3.1f%cC (%2.1f)", temp, 0xdf, intTemp);
dzoni 12:1de8b271e292 63
dzoni 17:94c385ff2641 64 Thread::wait(2000);
dzoni 9:645f0e517017 65 }
dzoni 13:f62b10a6e1c5 66 }