\ Program Name: f0-lmt01-temp-sensor-simple-version.fs \ Date: Sat 12 Oct 2019 14:18:49 AEDT \ Copyright 2019 by t.j.porter , licensed under the GPLV2 \ This program may require preloaded support files \ For Mecrisp-Stellaris by Matthias Koch. \ https://sourceforge.net/projects/mecrisp/ \ Chip: STM32F051, Board: STM32F0 Discovery Board \ Clock: 8 Mhz using the internal STM32F051 RC clock, unless otherwise stated \ All register names are CMSIS-SVD compliant \ Note: gpio a,b,c,d,e, and uart1 are enabled by Mecrisp-Stellaris Core. \ \ This Program : \ * Reads temperature from a LMT01 temperature sensor via PC0 which uses a interrupt. \ * A blocking delay provides a 105mS window for the LMT01 pulse counting \ \ LMT01: Output Transfer Function: Temp (C) = ((count/4096) *256) -50 \ Temperature (°C) Number of pulses \ ­-49.9375 1 \ -­49.875 2 \ ­-40 160 \ ­-20 480 \ 0 800 \ 30 1280 \ 50 1600 \ 100 2400 \ 150 3200 \ \ ---------------------------------------------------------------------------\ \ GPIO Description \ ---- ----------- \ PC0 Count input \ PC1 LMT01-1 Activate \ ---------------------------------------------------------------------------\ compiletoram \ compiletoflash : lmt01-fault? ( -- ) lmt01.count @ 0 = ; \ if lmt01.count >0, no error : pretty.print ( -- ) 0 <# # 46 hold #s #> type ; \ insert one decimal point : degrees.c.x10 ( -- C * 10 ) \ convert lmt01.count to degC lmt01-fault? not if \ no error, stack value greater than zero lmt01.count @ \ fetch total number of pulses counted 10000 4096 */ 256 * 500000 - 1000 / \ Temp (C) = ((count/4096) *256) -50 scale raw temp into degrees x 10 else ." LMT01 faulty or disconnected " 0 \ error display fault message, stack = 0 then ; : ms.delay ( u -- ) \ millisecond blocking delay 0 do 1526 0 do loop loop ; : read.sensor ( -- ) \ read sensor 0 lmt01.count ! lmt01.power.on green-on \ green led on 105 ms.delay \ start count window. program flow stops for 105 ms but interrupts will still count LMT01 pulses green-off lmt01.power.off lmt01-fault? if \ count window has ended, if no counts there has been an error. ." lmt01-fault ! " then ; : read.temperature DUP ( sensor # -- error | temperature C ) read.sensor degrees.c.x10 pretty.print ." C " ; : t cr read.temperature ; \ shortcut init.gpio init.lmt01 \ todo: supress error degrees number at pretty.print, move error message to read.sensor \ ----------------- Delete following code, only used on my system ----------------\ \ note: library/f0-multitask.fs is autoloaded last, look at last lines of terminal upload to see it. : main \ Words in main are executed about *every* 5uS @ 48 Mhz unless blocked pause ; : init-general \ Words in init-general are executed *once* at boot up. \ f0-disco-48mhz \ already enabled in upload.main.sh. This is for a standalone project \ gpioc_moder_moder8 \ led preconfig \ gpioc_moder_moder9 \ led preconfig \ init.gpio \ init.lmt01 ;