Part Number: TM4C123GH6PM Hello Community, i tried to run the MCP23008 I2C I/O Expander using TM4C123. I simply only copied the code from the video: TM4C123 Tutorial: I2C Communication ( https://www.youtube.com/watch?v=A7PUM9wPUAw /** * @author Carlos Alvarez (2/26/2015) * * @details Use the I2C peripheral in your Tiva-C or Stellaris Launchpad board * to drive an input output expander to control the state of 8 LEDs connected to * its GPIO port. * * See detail tutorial at: www.youtube.com/watch */ #include //#include #include #include #include "driverlib/timer.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/gpio.h" //#include "inc/hw_memmap.h" #include "inc/hw_ints.h" //I2C COMMUNICATION uint8_t leds = 0x00; uint32_t uiPeriod; void setSlaveAddress(uint8_t slaveAddress) { //MSA register consists of eight bits: 7 address bits and 1 Receive/Send bit, which determines if the next operation is Receive(1) or Transmit(0) //slaveAddress = 0b _001.0000 I2C1->MSA = (slaveAddress MSA &= ~(1 MSA |= (1 MDR = dataByte; I2C1->MCS = conditions; while( (I2C1->MCS & (1 MCS & (1 MCS & (1 MCS = (1 MCS & (1 RCGCI2C = (1 RCGCGPIO = (1 we must enable the clock on Port A //Step 3 GPIOA->AFSEL = (1 DEN = (1 ODR = (1 PCTL &= ~0xFF000000; //This line is not required //Specify which alternate function you want to use, see Table 21-5 GPIOA->PCTL = (3 MCR = (1 MTPR = 0x7; //1 byte must be sent setSlaveAddress(0x20); //last 7 bits (7-1) setRW(0); //first bit (0) //writeByte(BYTE ONE, BYTE TWO) //send IODIR register address writeByte(0x00, (1<<0)|(1<<1)); //BYTE TWO: conditions = RUN and START //send IODIR value to make GPIO pins outputs writeByte(0x00, (1<<0)|(1<<2)); //BTYE TWO: conditions = RUN, STOP while(1) { writeByte(0x09, (1<<0)|(1<<1)); writeByte(0xFF, (1<<0)|(1<<2)); for(int i = 0; i < 1000000; i++){}; uiPeriod=SysCtlClockGet(); } return 0; }
↧