From 2d09e22ec62f73533241b0e3eff0e04ebfb7d6b3 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Fri, 13 Sep 2024 21:40:22 +0200 Subject: [PATCH] avr: "Utils_WaitNanoSecs 100000" doesn't work at 8MHz (too many cycles). --- avr/common/utils_wait_fixed.asm | 24 +++++++++++++++++++----- avr/modules/si7021/main.asm | 5 +++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/avr/common/utils_wait_fixed.asm b/avr/common/utils_wait_fixed.asm index 66ba62c..028774d 100644 --- a/avr/common/utils_wait_fixed.asm +++ b/avr/common/utils_wait_fixed.asm @@ -11,14 +11,28 @@ ; --------------------------------------------------------------------------- +; @routine Utils_WaitFor10MicroSecs @global +; ; wait for 10 microsecs (minus cycles for call and ret). ; -; IN: -; - nothing -; OUT: -; - nothing -; REGS: r22 +; @clobbers r22 Utils_WaitFor10MicroSecs: Utils_WaitNanoSecs 10000, 7, r22 ; wait for 10us (minus RCALL and RET) ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Utils_WaitFor50MicroSecs @global +; +; wait for 50 microsecs (minus cycles for call and ret). +; +; @clobbers r22 + +Utils_WaitFor50MicroSecs: + Utils_WaitNanoSecs 50000, 7, r22 ; wait for 50us (minus RCALL and RET) + ret +; @end + diff --git a/avr/modules/si7021/main.asm b/avr/modules/si7021/main.asm index efa15b6..e6cd350 100644 --- a/avr/modules/si7021/main.asm +++ b/avr/modules/si7021/main.asm @@ -294,8 +294,9 @@ si7021MeasureAny_loop: ; (R22) rcall twiSendByteExpectAck ; (R16, R17, R18, R22) brcs si7021MeasureAny_gotValue ; chip responds, receive values dec r14 - breq si7021MeasureAny_error ; timeout - Utils_WaitNanoSecs 100000, 0, r22 + breq si7021MeasureAny_error ; timeout + rcall Utils_WaitFor50MicroSecs ; wait for 100usecs total + rcall Utils_WaitFor50MicroSecs rjmp si7021MeasureAny_loop si7021MeasureAny_gotValue: