Sample code for interfacing the MAX7360 and PICO board (can be used for most of the mbed boards, with minor changes)
int main()
{
//Writing the configuration register (0x01). Please refer to page 10 and table 8 of the data sheet
//default values, except disable key release
char Datawrite_config[2];
Datawrite_config[0] = 0x01;
//Datawrite_config[1] = 0x83; //Datawrite_config[0] = 0xAA;
Datawrite_config[1] = 0x20;
i2c.write( Slave_address, Datawrite_config, 2 );
//Writing the Key switch interrupt register (0x03). Please refer to table 10 of the data sheet
char Datawrite_Key_Switch_Interrupt[2];
Datawrite_Key_Switch_Interrupt[0] = 0x03;
Datawrite_Key_Switch_Interrupt[1] = 0x08; //INTK asserts every 8 debounce cycles
i2c.write( Slave_address, Datawrite_Key_Switch_Interrupt, 2 );
//Writing the auto sleep register (0x06) Autosleep Register no autosleep
char Autosleep[2];
Autosleep[0] = 0x06;
Autosleep[1] = 0x00;
i2c.write( Slave_address, Autosleep, 2 );
//Writing the GPIO Global Configuration (0x40) Enable rotary encoder and normal GPIO operation
char GlobalConfig[2];
GlobalConfig[0] = 0x40;
GlobalConfig[1] = 0x90;
i2c.write( Slave_address, GlobalConfig, 2 );
//Writing GPIO Control Register All GPIOs configured as output, except ports 6 and 7, because they are connected to the rotary encoder
char GPIOControl[2];
GPIOControl[0] = 0x41;
GPIOControl[1] = 0x3F;
i2c.write( Slave_address, GPIOControl, 2 );
//Writing the Rotatory switch configuration (0x46). Please refer to table 20 of the data sheet
char Datawrite_Rotatory_Switch_configuration[2];
//Rotary Switch Configuration Register INTI asserted 25ms after first debounced event, no debounce cycle time
Datawrite_Rotatory_Switch_configuration[0] = 0x46;
Datawrite_Rotatory_Switch_configuration[1] = 0x90; // Rotary Switch Configuration Register INTI asserted 25ms after first debounced event, no debounce cycle time
//Datawrite_Rotatory_Switch_configuration[1] = 0x11;
i2c.write( Slave_address, Datawrite_Rotatory_Switch_configuration, 2 );
// Writing PORT6 Configuration Register mask interrupt (0x5E)
char Port6[2];
Port6[0] = 0x5E;
Port6[1] = 0x80;
i2c.write( Slave_address, Port6, 2 );
// Writing PORT7 Configuration Register mask interrupt (0x5F)
char Port7[2];
Port7[0] = 0x5F;
Port7[1] = 0x80;
i2c.write( Slave_address, Port7, 2 );
//-----------------------------------------------------------------------------
//Default register values
//-----------------------------------------------------------------------------
//writeMAX7360(0x02,0xFF);// Debounce Register only column 0 enabled, debounce set to 40ms
// writeMAX7360(0x04,0xFE); // Ports Register
// writeMAX7360(0x05,0x00); // Autorepeat Register
// writeMAX7360(0x42,0x00); // GPIO Debounce Configuration Register
// writeMAX7360(0x43,0xC0); // GPIO Constant-Current Setting Register
// writeMAX7360(0x44,0x00); // GPIO Output Mode Register
// writeMAX7360(0x45,0x00); // Common PWM Register
while(1)
{
//Reading the Key FIFO register (0x00). Please refer to page 10 and table 7 of the data sheet
char KeyFIFOData;
char l = 0x00;
i2c.write( Slave_address, &l, 1 );
i2c.read( Slave_address, &KeyFIFOData, 1 );
if(KeyFIFOData!= 63)
{
microUSB.printf("KeyFIFOData = %d \n\r", KeyFIFOData);
}