I have been trying for several hours to get a simple I2C circuit setup with the TM4C123GXL board and an MCP23017 IO Expander. I've looked at many forum posts about I2C problems with this board, but none have helped. Currently I'm using code from http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/235977.aspx for the I2C setup and address scanning (it loops through addresses from 0 to 127 and tests if they acknowledge):
void I2CSetup(void) { //enable I2C module 0 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); //enable GPIO peripheral that contains I2C 0 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //reset module ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0); // Configure the pin muxing for I2C0 functions on port B2 and B3. ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL); ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA); // Select the I2C function for these pins. ROM_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); // Enable and initialize the I2C0 master module. Use the system clock for // the I2C0 module. The last parameter sets the I2C data transfer rate. // If false the data rate is set to 100kbps and if true the data rate will // be set to 400kbps. ROM_I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false); //clear I2C FIFOs HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000; }
unsigned long I2CBusScan(unsigned long ulI2CBase) { unsigned char ucProbeAdress; unsigned long ucerrorstate; // // Check the arguments. // ASSERT(I2CMasterBaseValid(ulI2CBase)); // // Wait until master module is done transferring. // while(ROM_I2CMasterBusy(ulI2CBase)) { }; // // I2C Addresses are 7-bit values // probe the address range of 0 to 127 to find I2C slave devices on the bus // for (ucProbeAdress = 0; ucProbeAdress < 127; ucProbeAdress++) { // // Tell the master module what address it will place on the bus when // writing to the slave. // ROM_I2CMasterSlaveAddrSet(ulI2CBase, ucProbeAdress, false); ROM_SysCtlDelay(50000); // // Place the command to be sent in the data register. // ROM_I2CMasterDataPut(ulI2CBase, 0x00); // // Initiate send of data from the master. // ROM_I2CMasterControl(ulI2CBase, I2C_MASTER_CMD_BURST_SEND_START); // // Make some delay // ROM_SysCtlDelay(500000); // // Read the I2C Master Control/Status (I2CMCS) Register to a local // variable // ucerrorstate = ROM_I2CMasterErr(ulI2CBase); // // Examining the content I2C Master Control/Status (I2CMCS) Register // to see if the ADRACK-Bit (Acknowledge Address) is TRUE (1) // ( 1: The transmitted address was not acknowledged by the slave) // if(ucerrorstate & I2C_MASTER_ERR_ADDR_ACK) { // // device at selected address did not acknowledge --> there's no device // with this address present on the I2C bus // // // Print a message to Stdio // //UARTprintf("Address not found: 0x%2x - %3d\n",ucProbeAdress,ucProbeAdress); // // Make some delay // //ROM_SysCtlDelay(1500000); } // // ( 0: The transmitted address was acknowledged by the slave) // else { // // device at selected address acknowledged --> there is a device // with this address present on the I2C bus // // // Print a message to Stdio // UARTprintf("Address found: 0x%2x - %3d\n",ucProbeAdress,ucProbeAdress); // // Make some delay // ROM_SysCtlDelay(1500000); } } // // End transfer of data from the master. // ROM_I2CMasterControl(ulI2CBase, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); // // Print a message to Stdio // UARTprintf("I2C Bus-Scan done...\n"); // // Return 1 if there is no error. // return 1; }
For some reason, the program reports that there is a device at every address from 0 to 127 (ie ROM_I2CMasterErr always returns 0), even though I only have one. I have 4k7 pull-up resistors on SCL and SDA and several 0.1uF bypass caps. The reset pin is also connected to 5V (active-low). Any ideas what could be wrong?