Other Parts Discussed in Thread: PCF8574
Tool/software: Code Composer Studio
Hi, I'm trying to communicate an TMS-F28377S with a LCD display (PCF8574). I'm not getting to use i2C communicate
I'm use the code example "Example_2837xDI2C_eeprom.c">
I want sent a data to bus, but I couldn't identify on the code where I should put a data
in while(1), this code send data to bus, and a can see on the oscilloscope.
But I don't no where change a *msg variable
while(1){
// I2CA_WriteData(&I2cMsgOut1);
DELAY_US(1000);
}
me code:
//########################################################################### // // FILE: Example_2837xDI2C_eeprom.c // // TITLE: I2C EEPROM Example // //! \addtogroup cpu01_example_list //! <h1>I2C EEPROM Example (i2c_eeprom)</h1> //! //! This program will write 1-14 words to EEPROM and read them back. //! The data written and the EEPROM address written to are contained //! in the message structure, I2cMsgOut1. The data read back will be //! contained in the message structure I2cMsgIn1. //! //! \b External \b Connections \n //! - This program requires an external I2C EEPROM connected to //! the I2C bus at address 0x50. //! // //########################################################################### // $TI Release: F2837xD Support Library v210 $ // $Release Date: Tue Nov 1 14:46:15 CDT 2016 $ // $Copyright: Copyright (C) 2013-2016 Texas Instruments Incorporated - // http://www.ti.com/ ALL RIGHTS RESERVED $ //########################################################################### // // Included Files // #include "F28x_Project.h" // // Defines // #define I2C_SLAVE_ADDR 0x27 #define I2C_NUMBYTES 2 #define I2C_EEPROM_HIGH_ADDR 0x00 #define I2C_EEPROM_LOW_ADDR 0x30 // // Globals // struct I2CMSG I2cMsgOut1={ I2C_MSGSTAT_SEND_WITHSTOP, I2C_SLAVE_ADDR, I2C_NUMBYTES, I2C_EEPROM_HIGH_ADDR, I2C_EEPROM_LOW_ADDR, 0x12, // Msg Byte 1 0x34}; // Msg Byte 2 struct I2CMSG I2cMsgIn1={ I2C_MSGSTAT_SEND_NOSTOP, I2C_SLAVE_ADDR, I2C_NUMBYTES, I2C_EEPROM_HIGH_ADDR, I2C_EEPROM_LOW_ADDR}; struct I2CMSG *CurrentMsgPtr; Uint16 PassCount; Uint16 FailCount; // // Function Prototypes // void I2CA_Init(void); Uint16 I2CA_WriteData(struct I2CMSG *msg); // // Main // void main(void) { Uint16 i; CurrentMsgPtr = &I2cMsgOut1; // // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the F2837xD_SysCtrl.c file. // InitSysCtrl(); // // Step 2. Initialize GPIO: // This example function is found in the F2837xD_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // // For this example, only init the pins for the SCI-A port. // These functions are found in the F2837xD_Gpio.c file. // GPIO_SetupPinMux(104, GPIO_MUX_CPU1, 1); GPIO_SetupPinMux(105, GPIO_MUX_CPU1, 1); // // Step 3. Clear all __interrupts and initialize PIE vector table: // Disable CPU __interrupts // DINT; // // Initialize PIE control registers to their default state. // The default state is all PIE __interrupts disabled and flags // are cleared. // This function is found in the F2837xD_PieCtrl.c file. // InitPieCtrl(); // // Disable CPU __interrupts and clear all CPU __interrupt flags: // IER = 0x0000; IFR = 0x0000; // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the __interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in F2837xD_DefaultIsr.c. // This function is found in F2837xD_PieVect.c. // InitPieVectTable(); // // Step 4. Initialize the Device Peripherals: // I2CA_Init(); // // Step 5. User specific code // // // Clear Counters // PassCount = 0; FailCount = 0; // // Clear incoming message buffer // for (i = 0; i < I2C_MAX_BUFFER_SIZE; i++) { I2cMsgIn1.MsgBuffer[i] = 0x0000; } // // Enable __interrupts required for this example // // // Enable I2C __interrupt 1 in the PIE: Group 8 __interrupt 1 // // // Enable CPU INT8 which is connected to PIE group 8 // IER |= M_INT8; EINT; int jj = 0; char data = 0x32; while(1){ I2CA_WriteData(&I2cMsgOut1); DELAY_US(1000); jj++; } } // // I2CA_Init - Initialize I2CA settings // void I2CA_Init(void) { I2caRegs.I2CSAR.all = 0x0027; // Slave address - EEPROM control code I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk I2caRegs.I2CCLKL = 43; // Prescalers set for 100kHz bit rate I2caRegs.I2CCLKH = 43; //At a 10Mhz I2C clock //I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY __interrupts I2caRegs.I2CIER.all = 0x00; // Enable SCD & ARDY __interrupts I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset // Stop I2C when suspended I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT, return; } Uint16 I2CA_WriteData(struct I2CMSG *msg) { Uint16 i; // // Wait until the STP bit is cleared from any previous master communication. // Clearing of this bit by the module is delayed until after the SCD bit is // set. If this bit is not checked prior to initiating a new message, the // I2C could get confused. // if(I2caRegs.I2CMDR.bit.STP == 1) { return I2C_STP_NOT_READY_ERROR; } // // Setup slave address // I2caRegs.I2CSAR.all = msg->SlaveAddress; // // Check if bus busy // if(I2caRegs.I2CSTR.bit.BB == 1) { return I2C_BUS_BUSY_ERROR; } // // Setup number of bytes to send // MsgBuffer + Address // I2caRegs.I2CCNT = msg->NumOfBytes+2; // // Setup data to send // I2caRegs.I2CDXR.all = msg->MemoryHighAddr; I2caRegs.I2CDXR.all = msg->MemoryLowAddr; for (i=0; i < msg->NumOfBytes; i++) { I2caRegs.I2CDXR.all = *(msg->MsgBuffer+i); } // // Send start as master transmitter // I2caRegs.I2CMDR.all = 0x6E20; return I2C_SUCCESS; }