pi@RPi3B:~/rpi8th/rpi32_shat $ ./test
Exception: Error powering down the device.: : user:power-down
pi@RPi3B:~/rpi8th/rpi32_shat $
Seems I made a stupid mistake on one word by throwing exception on success, not the other way around. Then I copy pasted it to other words as well!
Here is the corrected version:
: DEV_ID 0x5c ;
: WHO_AM_I 0x0f ;
: CTRL_REG1 0x20 ;
: CTRL_REG2 0x21 ;
: TEMP_OUT_L 0x2b ;
: TEMP_OUT_H 0x2c ;
var LPS25H
: init
1 DEV_ID hw:i2c null? if
drop
DEV_ID "Cannot connect to the LPS25H on I2C address %02x" s:strfmt throw
else
WHO_AM_I true hw:i2c@reg null? not if
0xbd n:= not if
"who_am_i error" throw
then
else
WHO_AM_I "error reading from %02x" s:strfmt throw
then
then
LPS25H ! ;
: power-down
LPS25H @ CTRL_REG1 0x00 true hw:i2c!reg nip not if
"Error powering down the device" throw
then ;
: set-mode
LPS25H @ CTRL_REG1 0x84 true hw:i2c!reg nip not if
"Error turning on the pressure sensor analog front end in single shot mode" throw
then ;
: one-shot-measure
LPS25H @ CTRL_REG2 0x01 true hw:i2c!reg nip not if
"Error running one-shot measurement (temperature and pressure)" throw
then ;
: wait-results
repeat
0.025 sleep
LPS25H @ CTRL_REG2 true hw:i2c@reg nip null? if
drop
"Error reading measurement status" throw
then
0 n:= not if
break
then
again ;
: get-temp \ -- temp
LPS25H @ TEMP_OUT_L true hw:i2c@reg nip null? if
drop
"Error reading low byte of the temperature" throw
then
LPS25H @ TEMP_OUT_H true hw:i2c@reg nip null? if
drop
"Error reading high byte of the temperature" throw
then
8 n:shl n:bor 480 n:/ 42.5 n:+ ;
: app:main
init
power-down
set-mode
one-shot-measure
wait-results
get-temp . cr
power-down
bye ;
John could you download fixed
version and test it on real hardware? It should just output temperature value if it succeeds. If it fails, it's exception time...