From 301c6e771a241debc2d8697d5ca7dda244089bb1 Mon Sep 17 00:00:00 2001 From: Andreas Taylor Date: Tue, 10 Jan 2023 15:01:36 -0600 Subject: [PATCH] Fixes #9. Update to version 2.0.1. --- LICENSE | 2 +- README.md | 2 +- library.properties | 2 +- src/SWI2C.cpp | 3 +++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index e2dbade..7994099 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 - 2022 Andreas Taylor +Copyright (c) 2018 - 2023 Andreas Taylor Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 59885b3..e2b7845 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ void loop() { // Write a byte to a device register: myDevice.writeToRegister(regAddress, byte_to_write); // Read a byte from a device register: - myDevice.readFromRegister(regAddress, &byte_to_read); + myDevice.readFromRegister(regAddress, byte_to_read); // Write several bytes to a device register: myDevice.writeToRegister(regAddress, buffer, 10); diff --git a/library.properties b/library.properties index 12977f9..05db7f5 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SWI2C -version=2.0.0 +version=2.0.1 author=Andreas Taylor maintainer=Andreas Taylor sentence=Software I2C library. diff --git a/src/SWI2C.cpp b/src/SWI2C.cpp index bda53fe..579f956 100644 --- a/src/SWI2C.cpp +++ b/src/SWI2C.cpp @@ -13,6 +13,7 @@ 07/27/2022 - Andy4495 - Support single-register devices (Issue #3) 08/19/2022 - Andy4495 - Consistently use unsigned, fix-sized types where appropriate - Add simpler, basic high-level methods + 01/10/2023 - Andy4495 - Fix #9 (send NACK after reading byte from device) */ #include "SWI2C.h" @@ -137,6 +138,7 @@ int SWI2C::readFromDevice(uint8_t &data, bool sendStopBit) { writeAddress(1); // 1 == Read bit if (checkAckBit()) {stopBit(); return 0;} // Immediately end transmission and return 0 if NACK detected data = read1Byte(); + checkAckBit(); // Controller needs to send NACK when done reading data if (sendStopBit) stopBit(); return 1; // Return 1 if no NACKs } @@ -267,6 +269,7 @@ int SWI2C::read1bFromDevice(uint8_t* data, bool sendStopBit){ writeAddress(1); // 1 == Read bit if (checkAckBit()) {stopBit(); return 0;} // Immediately end transmission and return 0 if NACK detected *data = read1Byte(); + checkAckBit(); // Controller needs to send NACK when done reading data if (sendStopBit) stopBit(); return 1; // Return 1 if no NACKs }