From 4a0f1c293336ee1a4f47dcc143b37c6e58009e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 23 Nov 2017 11:09:24 +0100 Subject: [PATCH] Clean I2C module --- code/espurna/i2c.ino | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/code/espurna/i2c.ino b/code/espurna/i2c.ino index 5382af0a..98499a9d 100644 --- a/code/espurna/i2c.ino +++ b/code/espurna/i2c.ino @@ -10,19 +10,18 @@ Copyright (C) 2017 by Xose PĂ©rez #include "brzo_i2c.h" -void i2cScan() { - - uint8_t address; - uint8_t response; - uint8_t buffer[1]; - int nDevices = 0; +bool i2cCheck(unsigned char address) { + brzo_i2c_start_transaction(address, I2C_SCL_FREQUENCY); + brzo_i2c_ACK_polling(1000); + return brzo_i2c_end_transaction(); +} - for (address = 1; address < 128; address++) { +void i2cScan() { - brzo_i2c_start_transaction(address, I2C_SCL_FREQUENCY); - brzo_i2c_ACK_polling(1000); - response = brzo_i2c_end_transaction(); + unsigned char nDevices = 0; + for (unsigned char address = 1; address < 128; address++) { + unsigned char response = i2cCheck(address); if (response == 0) { DEBUG_MSG_P(PSTR("[I2C] Device found at address 0x%02X\n"), address); nDevices++; @@ -31,7 +30,7 @@ void i2cScan() { } } - if (nDevices == 0) DEBUG_MSG_P(PSTR("[I2C] No devices found")); + if (nDevices == 0) DEBUG_MSG_P(PSTR("[I2C] No devices found\n")); }