Other Parts Discussed in Thread: PCF8574
Hello all, I'm having issues with the tivaware commands for I2c. I need to send two bytes of info to the I2C slave (MCP23017 16 bit IO expander) mounted on a small PCA. I have verified the PCA works properly with an Arduino and example code.
According to SPMA073, I2C_MASTER_CMD_BURST_SEND_START is supposed to send the start bit, slave address, cleared write bit, and the additional byte command in I2CMDR entered with I2CDataPut. The second byte of data can then be sent with I2C_MASTER_CMD_BURST_SEND_FINISH. This would suggest that basically the start bit, slave address, write bit, and two bytes are sent in this way.
My problem is that I2C_MASTER_CMD_BURST_SEND_START does not appear to be sending the byte entered in I2CMDR. Please see my code below, and the attached scope shot of the I2C send on the bus. If I have incorrect code, or have a misunderstanding of how the process should work, please let me know. Thanks for all responses.
#include <__cross_studio_io.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include "inc/hw_i2c.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "driverlib/i2c.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" #include "driverlib/timer.h" #include "driverlib/gpio.h" #include "driverlib/uart.h" #include "driverlib/pin_map.h" #include "driverlib/debug.h" #include "driverlib/rom.h" #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif uint8_t opcode = 0x27; //MCP23017 with A0 through A2 set as High //initialize I2C module 5 void InitI2C5(void) { //enable I2C module 0 SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C5); SysCtlPeripheralReset(SYSCTL_PERIPH_I2C5); SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C5); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C5)); // Enable and initialize the I2C5 master module. Use the system clock for // the I2C5 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. I2CMasterInitExpClk(I2C5_BASE, SysCtlClockGet(), false); //enable GPIO peripheral that contains I2C 5 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Configure the pin muxing for I2C5 functions on port B6 and B7. GPIOPinConfigure(GPIO_PB6_I2C5SCL); GPIOPinConfigure(GPIO_PB7_I2C5SDA); // Select the I2C function for these pins. GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_6); GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_7); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlDelay(1); // // Configure LED pins as outputs. // GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6); } void main(void) { // Set the clocking to run directly from the external crystal/oscillator. SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); //initialize I2C module 5 InitI2C5(); //Turn I2C power on. GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5); while(1) { //Turn Red LED on. //GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, GPIO_PIN_6); SysCtlDelay(5000000); // Wait until MCU is done transferring. while(I2CMasterBusBusy(I2C5_BASE)) {} // Tell the master module what address it will place on the bus when // communicating with the slave. I2CMasterSlaveAddrSet(I2C5_BASE, opcode, false); //------------------------------------------------------------------- //Configure MCP23017 IODIRB output pins //put data to be sent into FIFO I2CMasterDataPut(I2C5_BASE, 0x13); //Initiate send of data from the MCU I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START); // Wait until MCU is done transferring. while(I2CMasterBusBusy(I2C5_BASE)) {} //Check for errors if (I2CMasterErr(I2C5_BASE) != I2C_MASTER_ERR_NONE) { //Turn Red LED on. GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5); } //put data to be sent into FIFO I2CMasterDataPut(I2C5_BASE, 0x55); //Initiate send of data from the MCU I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); // Wait until MCU is done transferring. while(I2CMasterBusBusy(I2C5_BASE)) {} //Check for errors if (I2CMasterErr(I2C5_BASE) != I2C_MASTER_ERR_NONE) { //Turn Red LED on. GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5); } //------------------------------------------------------------------- //Turn Red LED off. //GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0); SysCtlDelay(5000000); } }