From 2f1a915390f886697a7a29460b6fd1034ba4b199 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 29 Jan 2023 15:46:58 +0100 Subject: [PATCH] Increased I2C speed. Added twiSendByteExpectAck. --- avr/twimaster.asm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/avr/twimaster.asm b/avr/twimaster.asm index 6f20562..5b156a3 100644 --- a/avr/twimaster.asm +++ b/avr/twimaster.asm @@ -2,7 +2,7 @@ ; *************************************************************************** ; defines -.equ TWI_BIT_LENGTH = 100000 ; 100000 and 200000 works for display +.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000 @@ -285,6 +285,30 @@ twiSendByte_error: +; --------------------------------------------------------------------------- +; twiSendByteExpectAck +; +; Write a byte to the bus and expect ACK response. +; +; IN: +; - R16: byte to send +; OUT: +; - CARRY flag set: okay, cleared on error (including case of non-ACK response) +; USED: R16, R17, R18, R22 + +twiSendByteExpectAck: + rcall twiSendByte + brcc twiSendByteExpectAck_error + tst r16 + brne twiSendByteExpectAck_error + sec + ret +twiSendByteExpectAck_error: + clc + ret + + + ; --------------------------------------------------------------------------- ; twiReceiveByte ;