void I2CA_Init(void); Uint16 I2CA_WriteData(Uint16 slave_add, Uint16 add, Uint16 data); void init_LCD(); #define I2C_LCD 0x3E #define I2C_RGB 0x60 #define I2C_NUMBYTES 2 void InitI2CGpio() { EALLOW; // // Enable internal pull-up for the selected pins // Pull-ups can be enabled or disabled disabled by the user. // This will enable the pullups for the specified pins. // Comment out other unwanted lines. // GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // Enable pull-up for GPIO32 (SDAA) GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0; // Enable pull-up for GPIO33 (SCLA) // // Set qualification for selected pins to asynch only // This will select asynch (no qualification) for the selected pins. // Comment out other unwanted lines. // GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3; // Asynch input GPIO32 (SDAA) GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3; // Asynch input GPIO33 (SCLA) // // Configure SCI pins using GPIO regs // This specifies which of the possible GPIO pins will be I2C functional // pins. Comment out other unwanted lines. // GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1; // Configure GPIO32 to SDAA GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1; // Configure GPIO33 to SCLA EDIS; } void I2CA_Init(void) { // Initialize I2C I2caRegs.I2CSAR = I2C_LCD; // Slave address - EEPROM control code #if (CPU_FRQ_150MHZ) // Default - For 150MHz SYSCLKOUT I2caRegs.I2CPSC.all = 14; // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz) #endif #if (CPU_FRQ_100MHZ) // For 100 MHz SYSCLKOUT I2caRegs.I2CPSC.all = 9; // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz) #endif I2caRegs.I2CCLKL = 45; // NOTE: must be non zero I2caRegs.I2CCLKH = 45; // NOTE: must be non zero // I2caRegs.I2CIER.all = 0x24; // 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(Uint16 slave_add, Uint16 add, Uint16 data) { // 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 = slave_add; // 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 = 2; // Setup data to send I2caRegs.I2CDXR = add; I2caRegs.I2CDXR = data; // Send start as master transmitter I2caRegs.I2CMDR.all = 0x6E20; return I2C_SUCCESS; } void init_LCD()//70.5ms total { //init 3 times, function set int i; for(i=0;i<3;i++) { Error=I2CA_WriteData(I2C_LCD,0x80,0x28); DELAY_US(15000); } //display control Error=I2CA_WriteData(I2C_LCD,0x80,0x0C); DELAY_US(10000); //clear display Error=I2CA_WriteData(I2C_LCD,0x80,0x01); DELAY_US(12000); //entry mode set Error=I2CA_WriteData(I2C_LCD,0x80,0x06); DELAY_US(500); //set RGB reg mode 1, output, mode2 Error=I2CA_WriteData(I2C_RGB,0x00,0x00); DELAY_US(500); Error=I2CA_WriteData(I2C_RGB,0x08,0xFF); DELAY_US(500); Error=I2CA_WriteData(I2C_RGB,0x01,0x20); DELAY_US(500); //set RGB white Error=I2CA_WriteData(I2C_RGB,0x04,0x80); DELAY_US(500); Error=I2CA_WriteData(I2C_RGB,0x03,0x80); DELAY_US(500); Error=I2CA_WriteData(I2C_RGB,0x02,0x80); DELAY_US(500); }