I2c gpio expander config problem

yinon

Member
Hi everyone,

We have recently developed a kind of simple LEDs controller (just on/off - no PWM output) using PCA9655E, some MOSFETs, and teensy 3.2 as UART to i2c bridge.

The unit works as expected most of the time except the first when the power turns ON.
the current solution is to reprogram the teensy using the program button and after that everything is working well.

My guess is something on the initialization step of the expenders but I don't know.
same issue with other boards: UNO and PRO MINI.

thanks for the help,
yinon


Code:
#include <Wire.h>
//#include <i2c_t3.h>


#include "pinsMap.h"
#include "blinkUnit.h"
#include "readInputUnit.h"

char colors[8]{'R','G','B','Y','P','T','W','C'};
bool States[BOARD_NUMBER*8+1]={0,0,0,0,0,0,0,0,0};

String inputString = "";         
bool stringComplete = false; 
bool gameOn=false;

 char buff[20];
 char *ptr0[2];
 char *ptr1[2];

void pressEvent(int unit){
  Serial.println(unit);
  //Serial1.print(unit);
  //Serial1.flush();
}


 
void setup() {
  delay (100);
  Serial.begin(9600);
  //Serial1.begin(9600);
  
  inputString.reserve(100); 

  pinMode(13,OUTPUT);
  randomSeed(A0);

  Wire.begin();
   delay(100);
      
  for(int i=0;i<=EXPENDERS_NUMBER-1;i++){

      I2CSetValue(expAdd[i], PORT0_CONFIG, 0x88);
      delay (10);
      I2CSetValue(expAdd[i], PORT1_CONFIG, 0x88);
      delay (10);
      I2CSetValue(expAdd[i], OUTPUT_PORT0, 0x00);
      delay (10);
      I2CSetValue(expAdd[i], OUTPUT_PORT1, 0x00);
      delay (10);
    } 

    delay(100);
    
      blinkAllUnits('R');
      delay(550); 
      blinkAllUnits('C');
      delay(550);
  
    while(1){
      for (int d=1; d<=8 ; d++ ) {
        blinkUnit(d,'G');
        Serial.println(d);
         delay(250);           
      }
      
       blinkAllUnits('C');
          delay(550);
}
     
  }



void loop() {
    
      if (stringComplete) {
      Serial.println(inputString);
      inputString.toCharArray(buff,20);

      *ptr0 = strtok(buff,":"); //set unit
      int unit=atoi(*ptr0);

  
     *ptr1 = strtok(NULL, ":"); //set color
     char color=*ptr1[0];

  if(unit==0)
    blinkAllUnits(color);
  

  else blinkUnit(unit,color);
    
    inputString = "";
    stringComplete = false;
    }

    while (Serial.available()){
    char inChar = (char)Serial.read();
    if (inChar == '\n')
      stringComplete = true;
    else inputString += inChar;  
    }
  
    scanInputs();
          
    }
 
I suspect that the Teensy is powering up too quickly for the PCA9655E. Also you are NOT waiting for the Serial (USB) to become fully initialised.
I suggest you add the line "while (!Serial & (millis() < 4000 );" after "Serial.begin(9600);" in setup.
This will give up to 4 seconds for the Teensy to initialise it's Serial (USB) port and give a time for the PCA9655E to wake up.
You also don't seem to be initialising Serial1.
You had it in there, then commented it out.
 
thanks for help :) we are still working on it. we found a kind of solution with 160uF Capacitor between VCC and GND that acts as an "inrush current" filter.
that was the first time that I heard about this kind of phenomenon called "Inrush current".

another affectable fix is to set up the pin directions every time. for an unknown reason, the pins directions are sometimes reset, this is the main bug of the system.
 
Back
Top