This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TM4C123GH6PM: Having trouble using I2C between this board and an MCP23017 I/O port expander

Part Number: TM4C123GH6PM

Tool/software: TI C/C++ Compiler

Hi all,

I am currently working on a small game that requires quite a few LEDs to function, so I decided to try my hand at using port extenders for the project. Unfortunately, I have no experience with I2C, so I have no idea why my current code is not working.

My Current Code:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"
#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"

#define SLAVE_ADDRESS 0x20


void writeByte (int dataByte1, int dataByte2){ //Send data to the slave
    I2CMasterDataPut(I2C1_BASE, dataByte1);

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C1_BASE))
        {
        }

    I2CMasterDataPut(I2C1_BASE, dataByte2);

    I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(I2CMasterBusy(I2C1_BASE))
        {
        }
}




int main(void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
   
    //Initialize I2C Ports/Clock
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
    SysCtlPeripheralReset(SYSCTL_PERIPH_I2C1);


    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA6_I2C1SCL);
    GPIOPinConfigure(GPIO_PA7_I2C1SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
    GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);


    I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);


    I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDRESS, false);

    //Data to be sent
    writeByte(0x00, 0x00);
    writeByte(0x12, 0xFF);


return 0;
}

The Slave address should be correct, and all of the functions are compiling properly, but I can get anything to happen with the extender. Any ideas?

Data Sheet for Extender: cdn-shop.adafruit.com/.../mcp23017.pdf

  • Hello Mason,

    Sorry that this slipped through the cracks over the holidays!

    First off from a hardware level, have you checked if the proper pullup resistors are being used?

    Also looking at the device datasheet, it looks like there is a RESET line on the MCP part. Are you handling that at all? If it is not handled right the part may be kept in Reset.

    Code wise I don't see anything glaringly wrong, though I do wonder what result you are expecting? There is no read back, so how do you know that nothing is happening with the extender?