mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
151 lines
2.9 KiB
C++
151 lines
2.9 KiB
C++
//
|
|
// FILE: MCP23017_test.ino
|
|
// AUTHOR: Rob Tillaart
|
|
// DATE: 2022-06-28
|
|
// PUPROSE: test MCP23017 library
|
|
|
|
|
|
#include "MCP23017.h"
|
|
#include "Wire.h"
|
|
|
|
|
|
MCP23017 MCP(0x27);
|
|
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
Serial.println();
|
|
Serial.print("MCP23017_LIB_VERSION: ");
|
|
Serial.println(MCP23017_LIB_VERSION);
|
|
Serial.println();
|
|
delay(100);
|
|
|
|
Wire.begin();
|
|
bool b = MCP.begin();
|
|
Serial.println(b ? "true" : "false");
|
|
|
|
MCP.pinMode8(0, 0x00); // 0 = output , 1 = input
|
|
MCP.pinMode8(1, 0x00);
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
//
|
|
// test 8 bit interface
|
|
//
|
|
Serial.println("TEST digitalWrite8(port, value)");
|
|
for (uint16_t i = 0; i < 256; i++)
|
|
{
|
|
MCP.write8(0, i);
|
|
MCP.write8(1, i);
|
|
uint8_t mask0 = MCP.read8(0);
|
|
uint8_t mask1 = MCP.read8(1);
|
|
if ((mask0 != i) || (mask1 != i))
|
|
{
|
|
Serial.print(i);
|
|
Serial.print("\t");
|
|
Serial.print(MCP.read8(0));
|
|
Serial.print("\t");
|
|
Serial.print(MCP.read8(1));
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
|
|
Serial.println("TEST setPullup8(port, value)");
|
|
for (uint16_t i = 0; i < 256; i++)
|
|
{
|
|
MCP.setPullup8(0, i);
|
|
MCP.setPullup8(1, i);
|
|
uint8_t mask0, mask1;
|
|
MCP.getPullup8(0, mask0);
|
|
MCP.getPullup8(1, mask1);
|
|
if ((mask0 != i) || (mask1 != i))
|
|
{
|
|
Serial.print(i);
|
|
Serial.print("\t");
|
|
Serial.print(mask0);
|
|
Serial.print("\t");
|
|
Serial.print(mask1);
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
|
|
Serial.println("TEST setPolarity8(port, value)");
|
|
for (uint16_t i = 0; i < 256; i++)
|
|
{
|
|
MCP.setPolarity8(0, i);
|
|
MCP.setPolarity8(1, i);
|
|
uint8_t mask0, mask1;
|
|
MCP.getPolarity8(0, mask0);
|
|
MCP.getPolarity8(1, mask1);
|
|
if ((mask0 != i) || (mask1 != i))
|
|
{
|
|
Serial.print(i);
|
|
Serial.print("\t");
|
|
Serial.print(mask0);
|
|
Serial.print("\t");
|
|
Serial.print(mask1);
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
//
|
|
// test 16 bit interface
|
|
//
|
|
Serial.println("TEST digitalWrite16(value)");
|
|
for (uint32_t i = 0; i < 65535; i++)
|
|
{
|
|
MCP.write16(i);
|
|
if (MCP.read16() != i)
|
|
{
|
|
Serial.print(i);
|
|
Serial.print("\t");
|
|
Serial.print(MCP.read16());
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
Serial.println("TEST setPullup16(value)");
|
|
for (uint32_t i = 0; i < 65535; i++)
|
|
{
|
|
MCP.setPullup16(i);
|
|
uint16_t mask = 0;
|
|
MCP.getPullup16(mask);
|
|
if (mask != i)
|
|
{
|
|
Serial.print(i);
|
|
Serial.print("\t");
|
|
Serial.print(mask);
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
Serial.println("TEST setPolarity16(value)");
|
|
for (uint32_t i = 0; i < 65535; i++)
|
|
{
|
|
MCP.setPolarity16(i);
|
|
uint16_t mask = 0;
|
|
MCP.getPolarity16(mask);
|
|
if (mask != i)
|
|
{
|
|
Serial.print(i);
|
|
Serial.print("\t");
|
|
Serial.print(mask);
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void loop()
|
|
{
|
|
}
|
|
|
|
|
|
// -- END OF FILE --
|