Rev 260 | Blame | Last modification | View Log | RSS feed
#include "defines.h"
#include "MCP23009.h"
#include "I2C2.h"
void MCP23009_Init(void) {
uint8_t buffer[8];
buffer[0] = 0x00; // Starting register address
buffer[1] = 0xFF; // Set all pins as inputs
buffer[2] = 0xFF; // Reported values are inverted
buffer[3] = 0x00; // Disable interrupt-on-change
buffer[4] = 0x00; // IOC default values
buffer[5] = 0x00; // IOC compare to previous pin value
buffer[6] = 0x00; // Config settings
buffer[7] = 0xFF; // Enable pull-ups on all pins
I2C2_Master_Send(MCP23009_ADDR, 8, buffer);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
}
void MCP23009_Query(BTN_STATUS *status) {
uint8_t buffer[2] = {MCP23009_GPIOA};
I2C2_Master_Send(MCP23009_ADDR, 1, buffer);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
I2C2_Master_Recv(MCP23009_ADDR, 1);
uint8_t result;
do {
result = I2C2_Get_Status();
} while (!result);
I2C2_Read_Buffer(buffer);
status->w = buffer[0];
}