
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
Revision 5:ff77acf7d21d, committed 2015-12-13
- Comitter:
- dzoni
- Date:
- Sun Dec 13 06:25:45 2015 +0000
- Parent:
- 4:c163c99d6f89
- Child:
- 6:d1435e38c1b4
- Commit message:
- Initial commit.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-rtos.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Dec 12 20:24:37 2015 +0000 +++ b/main.cpp Sun Dec 13 06:25:45 2015 +0000 @@ -1,45 +1,60 @@ #include "mbed.h" +#include "rtos.h" #include "DS1620.h" #include "TextLCD.h" - -DigitalOut myled(LED1); - -int main() { - - wait_us(500000); +TextLCD lcd(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2); + +DS1620 ds1620Sensor(PB_4, PB_10, PB_3); - TextLCD lcd(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2); - - DS1620 ds1620Sensor(PB_4, PB_10, PB_3); - - float temperature; - uint32_t uiCnt=0; +static float temperature = 0.0f; +static uint32_t temp_raw = 0; +static uint32_t uiCnt=0; +static DigitalOut myled(LED1); +static void initDS1620Temp() { ds1620Sensor.setSerialClockFrequency(freq500k); if ((ds1620Sensor.readConfig() & 0x03) != 0x03) { ds1620Sensor.writeConfig(0x03); } +} - while(1) { +void temp_thread(void const *args) { + while (1) { myled = myled ^ 1; + ds1620Sensor.startConversion(); - ds1620Sensor.startConversion(); - // Wait for conversion completion (Tconv = 750 ms typ) - wait_us(750000); + Thread::wait(750); while (!(ds1620Sensor.readConfig() & 0x80)) - wait_us(10000); - + Thread::wait(10); + temperature = ds1620Sensor.getHighResolutionTemperature(); - + temp_raw = ds1620Sensor.readTemperatureRaw(); + } +} + +void disp_thread(void const *args) { + while (1) { lcd.cls(); - lcd.printf("Raw: %u", ds1620Sensor.readTemperatureRaw()); - uiCnt += 1; + lcd.printf("Raw: %u", temp_raw); + uiCnt += 2; lcd.locate(0, 1); lcd.printf("Float: %3.2f%cC", temperature, 0xdf); - wait_us(250000); + Thread::wait(1900); } } + +int main() { + + Thread::wait(1000); + + initDS1620Temp(); + + Thread dispThread(disp_thread, NULL, osPriorityNormal); + Thread tempThread(temp_thread, NULL, osPriorityNormal); + + Thread::wait(osWaitForever); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sun Dec 13 06:25:45 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#c825593ece39