Forum: Mikrocontroller und Digitale Elektronik Probleme mit PCA9626 und I2C


von Bernd (Gast)


Angehängte Dateien:

Lesenswert?

Hallo!
Ich möchte mit dem PCA9626 24 LEDs steuern und zur Kommuniktion die 
Arduino wire Bibliothek nehmen.
Das funktioniert soweit auch - allerdings lassen sich nur die ersten 
acht PWM register setzen.
Nach dem aufrufen dieser Initialisierungsfunktion sollten ja eigentlich 
alle LEDs an sein (0xFF). Aber es leuchten nnur die ersten acht 
Ausgänge.
1
void PCA9626init(uint8_t addr){
2
  Wire.beginTransmission(addr);
3
  Wire.send(0x80 | 0x00 );//auto increment, begin at address 0 
4
  Wire.send(0x00);//reg mode1 
5
  Wire.send(0x00);//reg mode2 
6
  
7
  for (int i=0; i <= 23; i++){ //PWM0-23
8
      Wire.send(0xFF); 
9
  }
10
    
11
  Wire.send(0xFF);//group duty cycle control
12
  Wire.send(0x00);//group frequency
13
  Wire.send(0x00);//chase control
14
  
15
  for (int i=0; i <= 5; i++){ //LED_Out1-6 PWM Dimming enable
16
      Wire.send(0xAA); 
17
  }
18
  Wire.endTransmission();
19
}

Sieht da jemand spontan wo da der Wurm drin ist?
Anbei das Datenblatt vom Chip.

Gruss

Bernd

von Jörg S. (joerg-s)


Lesenswert?

Im Code sehe ich auf die schnelle keinen Fehler. Sicher das die Hardware 
OK ist?

von Bernd (Gast)


Lesenswert?

Hallo!
Die LEDs sind an allen PINs gleichermaßenangeschlossen.
Der Fehler muss schon in der init Funktion liegen denn da müssten ja 
eigentlich alle PINs auf 0xFF gesetzt werden.
Prinzipiell funktioniert die Kommunikation, ich kann jeden PWM Ausgang 
einzeln einstellen usw aber eben nur die ersten acht.

Könnte es an der Auto Increment Flag liegen? Oder an den SUBCALL 
Adressen (deren Funktion ich nicht ganz verstehe)


Gruss

Bernd

von Koen M. (koenm)


Lesenswert?

Hello Bernd,

I've been working on the same Arduino/PCA9626 combination and I 
experienced the same problem. (Also with the same code as shown in your 
first post)

When counting the number of send commands, I found out that a total of 
36 send operations are performed to complete all the register settings. 
The total buffer of the Arduino I2C library is set to 32.

So there are 4 operations more required than would fit inside the 
buffer; 4 operations times 4 leds per group is 16 leds that couln't be 
initialised. That means only the 8 present leds are initialised.

Setting the buffer to 31 makes only 4 leds light up; the problem must be 
within the buffer of the Arduino library.

I would suggest to set the buffer to 36 or higher, but even with a 
buffer of 33 it won't work. It looks like the buffer is limited to 32 
somewhere else than in 'Wire.h' and 'twi.h'.

My working solution right now is to split the initialization in 2 steps. 
There must be a way to change the buffer length to 36 or more, but I 
haven't found it yet.

Kind regards,
Koen M.

von Koen M. (koenm)


Lesenswert?

Hello Bernd,

Problem solved!

You can change the buffer length in 'Wire.h' en 'twi.h' and make it 
working; setting it to 38 will set the buffer to the size that is 
maximum to be used to communicate with the PCA9626.

Please make sure you delete the temporary files of the Arduino IDE and 
restart the program; I think that's why it didn't work for me the first 
time.

Keep in mind that the buffer is allowcated 5 times within the I2C 
handling of the Arduino so do not choose a buffer length that can lead 
to RAM memory overflows.

Kind regards,
Koen M.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.