Problem solved: A bad wire in my breadboard was causing the failure to read registers. Once that was fixed the code below works perfectly. While troubleshooting this problem i wrote a more elaborate sketch that exercises all of the MAX6959 functions. I will be glad to post that if there is any interest.
I am using a MAX6959 to drive a 4-digit, 7-segment display and 8 discrete LEDs. The MAX6959 also scans eight switches. The MAX6959 is controlled over an I2C bus by a Pololu A-Star 32U4 Micro controller. I am using Wire library functions to communicate with the MAX6959 over the I2C bus.
I have no problem controlling the 4-digit display and LEDs but am unable to read the Keyscan registers in the MAX6959. The sketch I am testing this with follows.
The 4 bytes returned by the Wire.read() function near the bottom of the sketch returns 4 zeros no matter what the state of the switches. Can anyone see what I am doing wrong?
#include <Wire.h>
byte debounced; //Indicates which switches were detected and debounced by the MAX6959
byte pressed; //Indicates which switches were detected as pressed by the MAX6959
void setup() {
//Open the serial port
Serial.begin(9600);
//Initialize the MAX6959 operating state
Wire.begin();
Wire.beginTransmission(0x38); //0x38 is the MAX6959 Slave address
Wire.write(0x01); // sets starting address to decode mode register
Wire.write(0x0F); // reg 0x01 - enable decode mode for all digits
Wire.write(0x20); // reg 0x02 - half intensity
Wire.write(0x03); // reg 0x03 - scan limit 3
Wire.write(0x03); // reg 0x04 - normal operation
// Writing to register 0x05 is forbidden so this must be ended here
Wire.endTransmission();
Wire.beginTransmission(0x38);
Wire.write(0x06); // sets starting address to GPIO register
Wire.write(0x98); /* reg 0x06 - IRQ/SEG9 is segment driver and
Input1 and Input2 are set to keyscan */
Wire.endTransmission();
}
void loop() {
//Read the switches connected to the MAX6959
//Set MAX register address to debounced keys
Wire.beginTransmission(0x38); //Slave address
Wire.write(0x08); //Debounced key register address
Wire.endTransmission();
//Read the debounced key register
debounced = 0x11;
Serial.println(debounced,BIN); //This prints a marker for the beginning of 4 byte input
Wire.requestFrom(0x38, 4); //Request bytes from 4 registers
while(Wire.available())
{
debounced = Wire.read();
Serial.println(debounced,BIN);
}
delay(1000);
}