Other Parts Discussed in Thread: PCF8574, , TCA6416A, TCA9534
Hi There:
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hey Kay,
May I ask why you are making a switch from the PCF series?
"What items need to be take care or which issue would be happend if directly swap those two? "
The major difference is that PCF device does not have internal registers to set while the 9534 has 4 registers. The software would need to be changed to be able to address this difference.
Thanks,
-Bobby
Hey Kay,
I would recommend our TCA family. It is more cost competitive than our PCA line up and fixes some bugs from the older PCA design. They also support wider Vcc ranges.
I have example C code from an Arduino MCU I made for fun on my off time (See Below). We typically do not off software support/drivers for our I2C devices. Also please do not treat the code below as something that represents/owned by TI as Arduino is open source and the code was developed outside of TI.
Code was written for TCA6416A but it should be similar to PCA9534/TCA9534 in the sense of accessing registers through I2C.
#include <Wire.h> int GPIO = 31; int input = 0; int readdata = 0; int flowcontrol = 0; int dataread[2]={0,0}; //this is the users input converted hex which can be used after using datainput1() int totalHEX = 0; //this is an 8 bit number in hex which can be used after using datainput1(), int deviceAddress = 0x21; int command = 0; int datawrite = 0; void setup() { // put your setup code here, to run once: pinMode(GPIO, INPUT); Serial.begin(9600); Wire.begin(); Wire.setClock(400000L); Serial.println("Press 0 to set GPIO low or press 1 to set GPIO HIGH || enter custome mode by entering 9"); } void loop() { if (Serial.available()){ input = userinput(); //toggles a GPIO LOW for input mode if (input==0){ pinMode(GPIO, OUTPUT); digitalWrite(GPIO, LOW); Serial.println("GPIO set low"); Serial.println("GPIO will revert to an input in:\n"); for(int i=10; i>=0; i--){ Serial.println(i); delay(1000); } pinMode(GPIO, INPUT); } //toggles GPIO HIGH for input mode else if (input==1){ pinMode(GPIO, OUTPUT); digitalWrite(GPIO, HIGH); Serial.println("GPIO set HIGH"); Serial.println("GPIO will revert to an input in:\n"); for(int i=10; i>0; i++){ Serial.print(i); delay(1000); } pinMode(GPIO, INPUT); } //changes device to be an INPUT else if (input==3){ Wire.beginTransmission(deviceAddress); Wire.write(0x06); Wire.write(0xFF); Wire.write(0xFF); Wire.endTransmission(); Serial.println("Device configured as an INPUT"); Wire.beginTransmission(deviceAddress); Wire.write(0x06); Wire.endTransmission(); Wire.requestFrom(deviceAddress, 2); Wire.endTransmission(); Serial.println("I2C programing complete"); for (int i=0;i<=1;i++){ readdata = Wire.read(); Serial.println(readdata); } } //changes device to be an output else if (input==4){ Wire.beginTransmission(deviceAddress); Wire.write(0x06); Wire.write(0x00); Wire.write(0x00); Wire.endTransmission(); Serial.println("Device configured as an output"); Wire.beginTransmission(deviceAddress); Wire.write(0x06); Wire.endTransmission(); Wire.requestFrom(deviceAddress, 2); Wire.endTransmission(); Serial.println("I2C programing complete"); for (int i=0;i<=1;i++){ readdata = Wire.read(); Serial.println(readdata); } } //automatically sets outputs as low (does not configure as outputs though) else if (input==5){ Wire.beginTransmission(deviceAddress); Wire.write(0x02); Wire.write(0x00); Wire.write(0x00); Wire.endTransmission(); Serial.println("outputs set LOW"); Wire.beginTransmission(deviceAddress); Wire.write(0x02); Wire.endTransmission(); Wire.requestFrom(deviceAddress, 2); Wire.endTransmission(); Serial.println("I2C programing complete"); for (int i=0;i<=1;i++){ readdata = Wire.read(); Serial.println(readdata); } } // //automatically sets outputs as HIGH (does not configure as outputs though) else if (input==6){ Wire.beginTransmission(deviceAddress); Wire.write(0x02); Wire.write(0xFF); Wire.write(0xFF); Wire.endTransmission(); Serial.println("outputs set HIGH"); //read what we wrote Wire.beginTransmission(deviceAddress); Wire.write(0x02); Wire.endTransmission(); Wire.requestFrom(deviceAddress, 2); Wire.endTransmission(); Serial.println("I2C programing complete"); for (int i=0;i<=1;i++){ readdata = Wire.read(); Serial.println(readdata); } } //reads input ports 0 and 1 else if(input==8){ Wire.beginTransmission(deviceAddress); Wire.write(0x00); Wire.endTransmission(); Wire.requestFrom(deviceAddress, 2); Wire.endTransmission(); Serial.print("Input registers 0 and 1 have been read, INT should reset\n"); } else if(input==9){ Serial.print( "Device Registers:\n" "--------------------------------------------------\n" "0x00 - INPUT PORT0 \n" "0x01 - INPUT PORT1 \n" "0x02 - OUTPUT PORT0 \n" "0x03 - OUTPUT Port1 \n" "0x04 - Polarity Inversion 0 \n" "0x05 - Polarity Inversion 1 \n" "0x06 - Configure 0 \n" "0x07 - Configure 1 \n" "--------------------------------------------------\n" ); Serial.print("\n ----------------------------\n" "[input command byte to send]\n"); datainput(); command = totalHEX; Serial.print("Command byte 0x"); Serial.println(command, HEX); Serial.print("\n ----------------------------\n" "[input data byte to write]\n\n"); datainput(); datawrite = totalHEX; Serial.print("data to write 0x"); Serial.println(datawrite, HEX); Wire.beginTransmission(deviceAddress); Wire.write(command); Wire.write(datawrite); Wire.endTransmission(); Serial.println("I2C transaction has been sent\n"); Serial.print("doing a read transaction, please check to see if the data read matches\n"); Wire.beginTransmission(deviceAddress); Wire.write(command); Wire.endTransmission(); Wire.requestFrom(deviceAddress, 1); Wire.endTransmission(); while (Wire.available()){ Serial.print("data read is: 0x"); Serial.println(Wire.read(),HEX); } } else{ Serial.println("invald input, please try again"); } } } int userinput(){ char value = Serial.read(); Serial.println(value); value = value - 48; //ASCII to 0-9 inputs return value; delay(50); } int datainput(){ flowcontrol = 0; int datacheck[2]={0,0}; Serial.println("Input 2 characters in HEX then hit enter"); while(flowcontrol==0){ delay(50); if(Serial.available()==2){ //when we have 2 inputs from user, we will read and store the inputs for(int i=0; i<=1; i++){ dataread[i]=Serial.read(); if(dataread[i]<=57 && dataread[i]>=48){ //need to convert the input into hex dataread[i]= dataread[i]-48; datacheck[i] = 1; } else if(dataread[i]<=70 && dataread[i]>=65){ //need to convert the input into hex dataread[i]= dataread[i]-55; datacheck[i] = 1; } else if(dataread[i]<=102 && dataread[i]>=97){ //need to convert the input into hex dataread[i]= dataread[i]-87; datacheck[i] = 1; } else{ Serial.println("Invalid character input"); datacheck[i] = 0; } Serial.print("Input in hex: "); Serial.println(dataread[i], DEC); } if ((datacheck[0]&datacheck[1])==1){ totalHEX=(dataread[0]<<4)+dataread[1]; flowcontrol = 1; } else { flowcontrol = 0; Serial.println("one more both of the inputs were note valid, enter 2 valid hex inputs again"); } } else if(Serial.available()>2){ Serial.println("too many inputs, Input only 2 characters"); //need to flush the serial buffer while(Serial.available()){ Serial.read(); flowcontrol = 0; } } //if else statement for flow control incase any inputs were not acceptable } return 1; }
-Bobby