0.3.8 PCF8574

This commit is contained in:
rob tillaart 2023-02-04 16:53:26 +01:00
parent 0c634c511d
commit 08d061c88d
11 changed files with 75 additions and 37 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.8] - 2023-02-04
- update readme.md
- update GitHub actions
- update license 2023
## [0.3.7] - 2022-11-16
- fix #40 - add interrupt section to readme.md

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2013-2022 Rob Tillaart
Copyright (c) 2013-2023 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -2,13 +2,11 @@
// FILE: PCF8574.cpp
// AUTHOR: Rob Tillaart
// DATE: 02-febr-2013
// VERSION: 0.3.7
// VERSION: 0.3.8
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8574
// http://forum.arduino.cc/index.php?topic=184800
//
// HISTORY: See CHANGELOG.md
//
#include "PCF8574.h"
@ -186,7 +184,7 @@ void PCF8574::rotateLeft(const uint8_t n)
}
void PCF8574::reverse() // quite fast: 14 shifts, 3 or, 3 assignment.
void PCF8574::reverse() // quite fast: 4 and, 14 shifts, 3 or, 3 assignment.
{
uint8_t x = _dataOut;
x = (((x & 0xAA) >> 1) | ((x & 0x55) << 1));
@ -240,6 +238,5 @@ void PCF8574::selectN(const uint8_t pin)
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -3,18 +3,17 @@
// FILE: PCF8574.h
// AUTHOR: Rob Tillaart
// DATE: 02-febr-2013
// VERSION: 0.3.7
// VERSION: 0.3.8
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8574
// http://forum.arduino.cc/index.php?topic=184800
//
#include "Arduino.h"
#include "Wire.h"
#define PCF8574_LIB_VERSION (F("0.3.7"))
#define PCF8574_LIB_VERSION (F("0.3.8"))
#ifndef PCF8574_INITIAL_VALUE
#define PCF8574_INITIAL_VALUE 0xFF
@ -40,7 +39,7 @@ public:
// note: setting the address corrupt internal buffer values
// a read8() / write8() call updates them.
bool setAddress(const uint8_t deviceAddress);
uint8_t getAddress();
uint8_t getAddress();
uint8_t read8();
@ -63,7 +62,8 @@ public:
// rotate, shift, toggle, reverse expect all lines are output
void toggle(const uint8_t pin);
void toggleMask(const uint8_t mask = 0xFF); // default 0xFF ==> invertAll()
// default 0xFF ==> invertAll()
void toggleMask(const uint8_t mask = 0xFF);
void shiftRight(const uint8_t n = 1);
void shiftLeft(const uint8_t n = 1);
void rotateRight(const uint8_t n = 1);
@ -91,5 +91,5 @@ private:
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -18,10 +18,11 @@ Related to the PCF8575 16 channel IO expander library https://github.com/RobTil
This library gives easy control over the 8 pins of a PCF8574 and PCF8574A chip.
These chips are identical in behaviour although there are two distinct address ranges.
| TYPE | ADDRESS-RANGE | notes |
|:---------|:-------------:|:------------------------:|
|PCF8574 | 0x20 to 0x27 | same range as PCF8575 !! |
|PCF8574A | 0x38 to 0x3F | |
| type | address-range | notes |
|:-----------|:---------------:|:-------------------------:|
| PCF8574 | 0x20 to 0x27 | same range as PCF8575 ! |
| PCF8574A | 0x38 to 0x3F |
So you can connect up to 16 PCF8574 on one I2C bus, giving access
to 16 x 8 = 128 IO lines. To maximize IO lines combine 8 x PCF8575 + 8 x PCF8574A giving
@ -34,33 +35,55 @@ Furthermore some additional functions are implemented that are playful and usefu
#### Interrupts
The PCF8574 has an interrupt output line (INT) to notice a MCU that one of the input lines has changed.
The PCF8574 has an interrupt output line (INT) to notify an MCU that one of the input lines has changed.
This can be used to prevent active polling of the PCF8574, which can be more efficient.
The library does not support this internally.
The library cannot handle the PCF8574 interrupts as it has no code for it.
The user should catch the interrupt in his own code and can use the library to see which line has changed.
There are two examples to show how interrupts can be used:
- PCF8574_interrupt.ino
- PCF8574_rotaryEncoder.ino
#### Related
16 bit port expanders
- https://github.com/RobTillaart/MCP23017_RT
- https://github.com/RobTillaart/MCP23S17
- https://github.com/RobTillaart/PCF8575
8 bit port expanders
- https://github.com/RobTillaart/MCP23008
- https://github.com/RobTillaart/MCP23S08
- https://github.com/RobTillaart/PCF8574
## I2C Clock
Tested on UNO with **PCF8574_performance** showed that the PCF8574 still works at 500 KHz and failed at 600 KHz.
These values are outside the specs of the datasheet so they are not recommended.
However when performance is needed you can try to overclock the chip.
| clock speed | Read | Write | Notes |
|:-----------:|:------:|:-------:|:------------------|
| 100000 | 236 | 240 | spec datasheet |
| clock speed | Read | Write | Notes |
|:-----------:|:------:|:-------:|:--------------------|
| 100000 | 236 | 240 | spec datasheet |
| 200000 | 132 | 140 |
| 300000 | 104 | 108 |
| 400000 | 96 | 96 | max advised speed |
| 500000 | 92 | 92 | not recommended |
| 400000 | 96 | 96 | max advised speed |
| 500000 | 92 | 92 | not recommended |
| 600000 | crash | crash |
## Interface
```cpp
#include "PCF8574.h"
```
**PCF8574_INITIAL_VALUE** is a define that can be set compile time or before
the include of "pcf8574.h" to overrule the default value used with the **begin()** call.
@ -142,11 +165,11 @@ This can typical be used to implement a VU meter.
## Error codes
| name | value | description |
|:-------------------|:-----:|:------------------------|
| PCF8574_OK | 0x00 | no error |
| PCF8574_PIN_ERROR | 0x81 | pin number out of range |
| PCF8574_I2C_ERROR | 0x82 | I2C communication error |
| name | value | description |
|:--------------------|:-------:|:--------------------------|
| PCF8574_OK | 0x00 | no error |
| PCF8574_PIN_ERROR | 0x81 | pin number out of range |
| PCF8574_I2C_ERROR | 0x82 | I2C communication error |
## Operation
@ -158,6 +181,17 @@ It is advised to use pull-up or pull-down resistors so the lines have a defined
## Future
-
#### Must
- keep in sync with PCF8575
#### Should
#### Could
- move code to .cpp
#### Wont

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/PCF8574.git"
},
"version": "0.3.7",
"version": "0.3.8",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=PCF8574
version=0.3.7
version=0.3.8
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCF8574 - 8 channel I2C IO expander

View File

@ -105,4 +105,5 @@ unittest(test_address)
unittest_main()
// --------
// -- END OF FILE --