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