avr: new version of ds18b20 module.
works better with reportsensor app.
This commit is contained in:
@@ -114,6 +114,8 @@ appReportSensorsTable:
|
||||
.dw 63, SGP30_SendCO2
|
||||
#endif
|
||||
#ifdef MODULES_DS18B20
|
||||
.dw 12, Ds18b20_StartMeasure
|
||||
.dw 46, Ds18b20_ReadResult
|
||||
.dw 84, Ds18b20_SendTemperature
|
||||
#endif
|
||||
#ifdef MODULES_CCS811
|
||||
@@ -129,6 +131,10 @@ appReportSensorsTable:
|
||||
#ifdef APPS_MOTION
|
||||
.dw 108, appMotionSendValue
|
||||
#endif
|
||||
#ifdef APPS_LIGHTCONTROL
|
||||
.dw 110, AppLightControl_ReportState
|
||||
#endif
|
||||
|
||||
; end of table
|
||||
.dw 0, 0
|
||||
|
||||
|
||||
@@ -70,8 +70,13 @@ APP_END_NETWORK:
|
||||
.include "modules/network/msg/pong-w.asm"
|
||||
#endif
|
||||
|
||||
#ifdef APPS_REPORTSENSORS
|
||||
|
||||
#if defined(APPS_REPORTSENSORS) || defined(APPS_STATS)
|
||||
.include "common/walktable.asm"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_REPORTSENSORS
|
||||
.include "apps/reportsensors/data.asm"
|
||||
.include "apps/reportsensors/main.asm"
|
||||
#endif
|
||||
@@ -101,11 +106,17 @@ APP_END_NETWORK:
|
||||
.include "modules/holdtimer/main.asm"
|
||||
.include "modules/triggeractor/defs.asm"
|
||||
.include "modules/triggeractor/main.asm"
|
||||
#ifdef MODULES_NETWORK
|
||||
.include "modules/triggeractor/recv.asm"
|
||||
#endif
|
||||
|
||||
.include "apps/fan_control/defs.asm"
|
||||
.include "apps/fan_control/main.asm"
|
||||
#ifdef MODULES_NETWORK
|
||||
.include "apps/fan_control/recv.asm"
|
||||
.include "apps/fan_control/send.asm"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -21,10 +21,6 @@
|
||||
|
||||
modulesOnEverySecond:
|
||||
|
||||
#ifdef MODULES_DS18B20
|
||||
bigcall Ds18b20_OnEverySecond
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SGP30
|
||||
bigcall SGP30_EverySecond
|
||||
#endif
|
||||
|
||||
@@ -228,7 +228,7 @@ MODULE_END_COM2W2:
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_DS18B20
|
||||
.include "modules/ds18b20/main2.asm"
|
||||
.include "modules/ds18b20/main3.asm"
|
||||
#ifdef MODULES_NETWORK
|
||||
.include "modules/ds18b20/send.asm"
|
||||
#endif
|
||||
|
||||
256
avr/modules/ds18b20/main3.asm
Normal file
256
avr/modules/ds18b20/main3.asm
Normal file
@@ -0,0 +1,256 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2024 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
; * This file is part of the project "AqHome". *
|
||||
; * Please see toplevel file COPYING of that project for license details. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defs
|
||||
|
||||
.equ DS18B20_ROMCMD_READROM = 0x33
|
||||
.equ DS18B20_ROMCMD_SKIPROM = 0xcc
|
||||
.equ DS18B20_FNCMD_CONVERT = 0x44
|
||||
.equ DS18B20_FNCMD_READSCRATCHPAD = 0xbe
|
||||
|
||||
.equ DS18B20_FLAGS_CONV_STARTED = 0x01
|
||||
.equ DS18B20_FLAGS_CONV_UPDATED = 0x02
|
||||
|
||||
.equ DS18B20_POLYNOMIAL = 0x8c
|
||||
|
||||
|
||||
.equ DS18B20_INTERVAL_SECS = 30
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data
|
||||
|
||||
.dseg
|
||||
|
||||
ds18b20DataBegin:
|
||||
ds18b20Flags: .byte 1
|
||||
ds18b20DataBuffer: .byte 9
|
||||
ds18b20DataTemp: .byte 2
|
||||
ds18b20DataEnd:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
DS18B20_BEGIN:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Ds18b20_Init @global
|
||||
;
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @clobbers r16, r17, X
|
||||
|
||||
Ds18b20_Init:
|
||||
; preset SRAM data area
|
||||
clr r16
|
||||
sts ds18b20Flags, r16
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Ds18b20_Fini @global
|
||||
|
||||
Ds18b20_Fini:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
Ds18b20_StartMeasure:
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
ldi r16, DS18B20_FNCMD_CONVERT
|
||||
rcall ds18b20SendCommand
|
||||
out SREG, r15
|
||||
pop r15
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
Ds18b20_ReadResult:
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
ldi xl, LOW(ds18b20DataBuffer)
|
||||
ldi xh, HIGH(ds18b20DataBuffer)
|
||||
rcall ds18b20ReadScratchPad
|
||||
brcc Ds18b20_ReadResult_popr15ret
|
||||
|
||||
ld r16, X+ ; copy temp from scratchpad
|
||||
sts ds18b20DataTemp, r16
|
||||
ld r16, X+
|
||||
sts ds18b20DataTemp+1, r16
|
||||
|
||||
lds r16, ds18b20Flags
|
||||
ori r16, DS18B20_FLAGS_CONV_UPDATED
|
||||
sts ds18b20Flags, r16
|
||||
|
||||
Ds18b20_ReadResult_popr15ret:
|
||||
out SREG, r15
|
||||
pop r15
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ds18b20SendCommand @global
|
||||
;
|
||||
; Reset bus, send SKIP ROM and send command.
|
||||
; Cave: Needs interrupts to be disabled!
|
||||
;
|
||||
; @param r16 command to send
|
||||
; @clobbers r18 (r21, r22)
|
||||
|
||||
ds18b20SendCommand:
|
||||
mov r18, r16
|
||||
|
||||
rcall OwiMaster_Reset ; (r21, r22)
|
||||
tst r16 ; presence detected?
|
||||
breq ds18b20SendCommand_error ; nope, jump
|
||||
|
||||
ldi r16, DS18B20_ROMCMD_SKIPROM ; skip rom
|
||||
rcall OwiMaster_SendByte ; (r21, r22)
|
||||
|
||||
mov r16, r18 ; command to send
|
||||
rcall OwiMaster_SendByte ; (r21, r22)
|
||||
sec
|
||||
ret
|
||||
ds18b20SendCommand_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
#if 0
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ds18b20ReadRom @global
|
||||
;
|
||||
; Send READ ROM and read result into buffer.
|
||||
; Cave: Needs interrupts to be disabled!
|
||||
;
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @return X points directly behind the last byte received
|
||||
; @param X pointer to SDRAM to receive 8 bytes
|
||||
; @clobbers r16, r18, r19, r23, X (r17, r20, r21, r22)
|
||||
|
||||
ds18b20ReadRom:
|
||||
rcall OwiMaster_Reset ; (r21, r22)
|
||||
tst r16 ; presence detected?
|
||||
breq ds18b20ReadRom_error ; nope, jump
|
||||
|
||||
ldi r16, DS18B20_ROMCMD_READROM
|
||||
rcall OwiMaster_SendByte ; (r21, r22)
|
||||
|
||||
ldi r23, 8
|
||||
ds18b20ReadRom_loop1:
|
||||
rcall Utils_WaitFor10MicroSecs
|
||||
; Utils_WaitNanoSecs 10000, 0, r22
|
||||
rcall OwiMaster_RecvByte ; (r21, r22)
|
||||
st X+, r16
|
||||
dec r23
|
||||
brne ds18b20ReadRom_loop1
|
||||
sbiw xh:xl, 8
|
||||
ldi r18, 8
|
||||
ldi r19, DS18B20_POLYNOMIAL
|
||||
rcall crc8Calc ; (R16, R17, R18, R20, R21, X)
|
||||
tst r16
|
||||
brne ds18b20ReadRom_error
|
||||
sec
|
||||
ret
|
||||
ds18b20ReadRom_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ds18b20ReadScratchPad
|
||||
;
|
||||
; Send SKIP_ROM, READ_SCRATCHPAD and read 9 byte result into buffer.
|
||||
;
|
||||
; Cave: Needs interrupts to be disabled!
|
||||
;
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @return X unchanged if CFLAG set (otherwise clobbered)
|
||||
; @param X pointer to SDRAM to receive 8 bytes
|
||||
; @clobbers r16, r18, r19, r23, X (r17, r20, r21, r22)
|
||||
|
||||
ds18b20ReadScratchPad:
|
||||
ldi r16, DS18B20_FNCMD_READSCRATCHPAD
|
||||
rcall ds18b20SendCommand
|
||||
brcc ds18b20ReadScratchPad_error
|
||||
ldi r23, 9
|
||||
ds18b20ReadScratchPad_loop1:
|
||||
rcall Utils_WaitFor10MicroSecs
|
||||
; Utils_WaitNanoSecs 10000, 0, r22
|
||||
rcall OwiMaster_RecvByte ; (r21, r22)
|
||||
st X+, r16
|
||||
dec r23
|
||||
brne ds18b20ReadScratchPad_loop1
|
||||
sbiw xh:xl, 9
|
||||
ldi r18, 9
|
||||
ldi r19, DS18B20_POLYNOMIAL
|
||||
rcall crc8Calc ; (R16, R17, R18, R20, R21, X)
|
||||
tst r16
|
||||
brne ds18b20ReadScratchPad_error
|
||||
sbiw xh:xl, 9
|
||||
sec
|
||||
ret
|
||||
ds18b20ReadScratchPad_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Ds18b20_GetValue @global
|
||||
;
|
||||
; @return CFLAG set if value available, cleared otherwise
|
||||
; @return R19:R18 value
|
||||
; @return R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
||||
; @clobbers R16
|
||||
|
||||
Ds18b20_GetValue:
|
||||
lds r16, ds18b20Flags
|
||||
andi r16, DS18B20_FLAGS_CONV_UPDATED
|
||||
breq Ds18b20_GetValue_done
|
||||
lds r18, ds18b20DataTemp ; value
|
||||
lds r19, ds18b20DataTemp+1
|
||||
ldi r20, 16 ; denominator
|
||||
clr r21
|
||||
sec
|
||||
Ds18b20_GetValue_done:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
DS18B20_END:
|
||||
.equ MODULE_SIZE_DS18B20 = DS18B20_END-DS18B20_BEGIN
|
||||
|
||||
|
||||
Reference in New Issue
Block a user