0.2.2 PCA9634

This commit is contained in:
rob tillaart 2022-09-07 19:22:42 +02:00
parent da07272e95
commit 196397b8ca
9 changed files with 128 additions and 7 deletions

View File

@ -2,7 +2,7 @@
// FILE: PCA9634.cpp
// AUTHOR: Rob Tillaart
// DATE: 03-01-2022
// VERSION: 0.2.1
// VERSION: 0.2.2
// PURPOSE: Arduino library for PCA9634 I2C LED driver
// URL: https://github.com/RobTillaart/PCA9634
//
@ -18,6 +18,7 @@
// update documentation.
// renamed PCA9634_MODE2_STOP to PCA9634_MODE2_ACK
// 0.2.1 2022-05-30 add mode parameters to begin()
// 0.2.2 2022-09-02 add static I2C_SoftwareReset()
#include "PCA9634.h"
@ -296,6 +297,30 @@ uint8_t PCA9634::getAllCallAddress()
}
//////////////////////////////////////////////////////
//
// EXPERIMENTAL
//
int PCA9634::I2C_SoftwareReset(uint8_t method)
{
// only support 0 and 1
if (method > 1) return -999;
if (method == 1)
{
// from https://github.com/RobTillaart/PCA9634/issues/10#issuecomment-1206326417
const uint8_t SW_RESET = 0x03;
_wire->beginTransmission(SW_RESET);
_wire->write(0xA5);
_wire->write(0x5A);
return _wire->endTransmission(true);
}
// default - based upon NXP specification - UM10204.pdf - page 16
_wire->beginTransmission(0x00);
_wire->write(0x06);
return _wire->endTransmission(true);
}
/////////////////////////////////////////////////////
//

View File

@ -3,7 +3,7 @@
// FILE: PCA9634.h
// AUTHOR: Rob Tillaart
// DATE: 03-01-2022
// VERSION: 0.2.1
// VERSION: 0.2.2
// PURPOSE: Arduino library for PCA9634 I2C LED driver, 8 channel
// URL: https://github.com/RobTillaart/PCA9634
@ -12,7 +12,7 @@
#include "Wire.h"
#define PCA9634_LIB_VERSION (F("0.2.1"))
#define PCA9634_LIB_VERSION (F("0.2.2"))
#define PCA9634_MODE1 0x00
#define PCA9634_MODE2 0x01
@ -130,6 +130,9 @@ public:
bool setAllCallAddress(uint8_t address);
uint8_t getAllCallAddress();
// EXPERIMENTAL 0.2.2
int I2C_SoftwareReset(uint8_t method);
private:
// DIRECT CONTROL
@ -146,5 +149,6 @@ private:
};
// -- END OF FILE --

View File

@ -36,7 +36,7 @@ See PCA9634.h and datasheet for settings possible.
idem, ESP32 ESP8266 only.
- **void configure(uint8_t mode1_mask, uint8_t mode2_mask)**
To configure the library after startup one can set the MODE1 and MODE2 configuration registers.
See PCA9634.h and datasheet for settings possible.
See PCA9634.h and datasheet for settings possible.
- **bool isConnected()** checks if address is available on I2C bus.
- **uint8_t channelCount()** returns the number of channels = 8.
@ -102,12 +102,13 @@ useful to add or remove a single flag (bit masking).
| PCA9634_MODE1_SUB2 | 0x04 | 0 = disable 1 = enable |
| PCA9634_MODE1_SUB3 | 0x02 | 0 = disable 1 = enable |
| PCA9634_MODE1_ALLCALL | 0x01 | 0 = disable 1 = enable |
| PCA9634_MODE1_NONE | 0x00 | |
| | | |
| PCA9634_MODE2_BLINK | 0x20 | 0 = dim 1 = blink |
| PCA9634_MODE2_INVERT | 0x10 | 0 = normal 1 = inverted |
| PCA9634_MODE2_STOP | 0x08 | 0 = on STOP 1 = on ACK |
| PCA9634_MODE2_TOTEMPOLE | 0x04 | 0 = open drain 1 = totem-pole |
| PCA9634_MODE2_NONE | 0x00 | |
These constants makes it easier to set modes without using a non descriptive
bit mask. The constants can be merged by OR-ing them together, see snippet:
@ -175,6 +176,7 @@ it with **enableSubCall(nr)**.
In the same way one can become member of an **ALL CALL** group.
Typically there is only one such group but one can configure more of them by applying different addresses.
#### Interface
The functions to enable all/sub-addresses are straightforward:
@ -192,6 +194,30 @@ The functions to enable all/sub-addresses are straightforward:
- **uint8_t getAllCallAddress()**
### I2C Software reset
#### 0.2.2 experimental
The goal of the i2C software reset is to reset ALL PCA9634 (and compatible)
devices on the I2C bus. But....
Since version 0.2.2 the PCA9634 library supports a I2C software reset.
However the documentation about the I2C software reset is ambiguous.
Different sources tell about different commands to execute.
The implementation is a function with the two described methods.
- method 1 is the PCA9634 specific reset.
- method 0 is the NXP described reset.
Note: side effect of this function can be that all devices on the I2C bus
that support the software reset will reset themselves.
See - https://github.com/RobTillaart/PCA9634/issues/10#issuecomment-1206326417
Feedback and experiences with this function is welcome.
## Operation
See examples

Binary file not shown.

View File

@ -0,0 +1,61 @@
//
// FILE: PCA9634_software_reset.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test PCA9634 library
#include "Arduino.h"
#include "Wire.h"
#include "PCA9634.h"
PCA9634 ledArray(0x20);
void setup()
{
Serial.begin(115200);
Serial.print("PCA9634 LIB version: ");
Serial.println(PCA9634_LIB_VERSION);
Serial.println();
ledArray.begin();
ledArray.setLedDriverMode(0, PCA9634_LEDON);
delay(100);
ledArray.I2C_SoftwareReset(0);
delay(100);
Serial.print("I2C_SoftwareReset(0) did ");
if (ledArray.getLedDriverMode(0) == PCA9634_LEDON)
{
Serial.print("not ");
}
Serial.println("work. ");
delay(2000);
ledArray.begin();
ledArray.setLedDriverMode(0, PCA9634_LEDON);
delay(100);
ledArray. I2C_SoftwareReset(1);
delay(100);
Serial.print("I2C_SoftwareReset(1) did ");
if (ledArray.getLedDriverMode(0) == PCA9634_LEDON)
{
Serial.print("not ");
}
Serial.println("work. ");
delay(2000);
// Forced led off.
ledArray.setLedDriverMode(0, PCA9634_LEDOFF);
Serial.println("done...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -38,6 +38,8 @@ enableAllCall KEYWORD2
disableAllCall KEYWORD2
isEnabledAllCall KEYWORD2
I2C_SoftwareReset KEYWORD2
# Constants ( LITERAL1)
PCA9634_LIB_VERSION LITERAL1

View File

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

View File

@ -1,5 +1,5 @@
name=PCA9634
version=0.2.1
version=0.2.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCA9634 I2C LED driver 8 channel

View File

@ -48,9 +48,12 @@ unittest_teardown()
unittest(test_constants)
{
fprintf(stderr, "\nregisters");
assertEqual(PCA9634_MODE1 , 0x00);
assertEqual(PCA9634_MODE2 , 0x01);
assertEqual(PCA9634_PWM(0) , 0x82);
assertEqual(PCA9634_PWM(1) , 0x83);
assertEqual(PCA9634_GRPPWM , 0x0A);
assertEqual(PCA9634_GRPFREQ , 0x0B);
assertEqual(PCA9634_LEDOUT_BASE, 0x0C);