Skip to content

Commit

Permalink
updated I2C tests to use LM75B instead of TMP102 sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackstoneEngineering committed Sep 12, 2016
1 parent 908003b commit 4d784e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions LM75B.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://developer.mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac
18 changes: 11 additions & 7 deletions TESTS/API/I2C/I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "unity.h"
#include "utest.h"
#include "rtos.h"
#include "TMP102.h"
#include "LM75B.h"
#include <I2CEeprom.h>

using namespace utest::v1;
Expand All @@ -12,29 +12,33 @@ using namespace utest::v1;

const char *convBool(bool value) { return value ? "true" : "false"; }

#define I2C_SENTINAL 'Z'
#define I2C_SENTINAL 'Z' //TODO: make this a random letter or string
#define TMP102_ADDR 0x90
#define EEPROM_ADDR 0xA0

// a test to see if the temperature can be read. A I2C failure returns a 0
void test_tmp102(){
TMP102 temperature(I2C_SDA, I2C_SCL, TMP102_ADDR); //A0 pin is connected to ground
TEST_ASSERT(0 != temperature.read());
//TMP102 temperature(I2C_SDA, I2C_SCL, TMP102_ADDR); //A0 pin is connected to ground
LM75B temperature(I2C_SDA, I2C_SCL);
TEST_ASSERT_MESSAGE(0 != temperature.open(),"Failed to open sensor");
TEST_ASSERT_MESSAGE(NULL != temperature.temp(),"Invalid value NULL returned");
TEST_ASSERT_MESSAGE(50 > temperature.temp(),"Its too Hot (>10C), Faulty Sensor?");
TEST_ASSERT_MESSAGE(0 < temperature.temp(),"Its Too Cold (<0C), Faulty Sensor?");
}

// A test to write the EEprom
void test_eeprom_W(){
I2CEeprom memory(I2C_SDA,I2C_SCL, EEPROM_ADDR, 32, 0);
TEST_ASSERT(memory.write(1, I2C_SENTINAL) == 1); // check data was written
TEST_ASSERT_MESSAGE(memory.write(1, I2C_SENTINAL) == 1,"data not written, error with EEPROM?"); // check data was written
}


// A test to read the EEprom
void test_eeprom_R(){
I2CEeprom memory(I2C_SDA,I2C_SCL, EEPROM_ADDR, 32, 0);
char value = 'a';
TEST_ASSERT(memory.read(1,value) == 1); // check data was read
TEST_ASSERT(I2C_SENTINAL == value); // check data integrity
TEST_ASSERT_MESSAGE(memory.read(1,value) == 1,"data failed to be read correctly"); // check data was read
TEST_ASSERT_MESSAGE(I2C_SENTINAL == value,"data read does not match data written! bad EEPROM?"); // check data integrity
}

// A test to Write then read the eeprom
Expand Down
1 change: 0 additions & 1 deletion TMP102.lib

This file was deleted.

0 comments on commit 4d784e5

Please sign in to comment.