MCP23017 (16-Bit I2C GPIO Expander) Interfacing with ON Semiconductor RSL10 SENSE GEVK - Hardware Setup

 

MCP23017 c library and main.c is attached below

Additional Code included in main.c

 

The Code to initialize the GPIO_SPARE as output at maximum drive strength and onboard button (PB1) as input using SDK function.

 

Sys_DIO_Config(PIN_GIO_SPARE, DIO_6X_DRIVE | DIO_NO_PULL | DIO_MODE_GPIO_OUT_1);
Sys_DIO_Config(PIN_BUTTON0, DIO_NO_PULL | DIO_LPF_ENABLE | DIO_MODE_GPIO_IN_0);

 

Code to change the output state of GPIO_SPARE without using interrupts when button (PB1) is pressed.

 

if((DIO->DATA & (1 << PIN_BUTTON0)) == 0){    // read button0 value (PB0)
    Sys_GPIO_Set_High(PIN_GIO_SPARE);        // set Spare GPIO high
}else{
    Sys_GPIO_Set_Low(PIN_GIO_SPARE);        // reset Spare GPIO high
}

 

A simple function to read the any GPIO input state. The input parameter "gpio_pin" of this function is GPIO pin number and it will return either 1 or 0 depending on the current GPIO state.

 

uint8_t Sys_DIO_Read(uint8_t gpio_pin){
    return (DIO->DATA & (1 << gpio_pin)) >> gpio_pin;    // return 1 or 0
}

 

DEMO

 

 

 

MCP23017 details: https://www.microchip.com/wwwproducts/en/MCP23017