This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

example programm for reading from 24C64 EEPROM

 http://www.sg-advertising.com/tailieu/datasheet/vidieukhien/8051%20interfacing%20I2c%20BUS.pdf

based on above application example I wrote program for

reading from 24C64 IIC EEPROM - ( I tested it with piccolo control stick )

I hope it is helpful for those who need it

===============I2C routines===============================

#define CLRSCL  GpioDataRegs.GPACLEAR.bit.GPIO17 = 1
#define SETSCL  GpioDataRegs.GPASET.bit.GPIO17 = 1 
#define CLRSDA GpioDataRegs.GPACLEAR.bit.GPIO16 = 1
#define SETSDA  GpioDataRegs.GPASET.bit.GPIO16 = 1 
#define SDAOUT GpioCtrlRegs.GPADIR.bit.GPIO16 = 1
#define SDAIN   GpioCtrlRegs.GPADIR.bit.GPIO16 = 0

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File


Uint16 SLV_ADDR = 0x5;

void init_I2C(void){
 EALLOW;
 GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 0;  //GPIO
 GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1;  //pullup res. disable
 SDAOUT;
  
 GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 0; //GPIO
 GpioCtrlRegs.GPAPUD.bit.GPIO17 = 1;  //pullup res. disable
 GpioCtrlRegs.GPADIR.bit.GPIO17 = 1; //SCL out
 EDIS;
 SETSDA;
 SETSCL;
 }
//**********SHFTO*************
void shifto(Uint16 data , Uint16 number){
Uint16 i, k;
 k=data;
 EALLOW;
 SDAOUT;
 EDIS;
 CLRSCL;
 for (i=0;i<number;i++){
 CLRSCL;
 asm (" RPT #60 || NOP");
 if (k & 0x1)
  SETSDA; 
 else
  CLRSDA; 
 k=k>>1;
 asm (" RPT #60 || NOP");
 SETSCL; 
 asm (" RPT #60 || NOP");
 }
 }

//*****SLAVE ACKNOWLEDGE*******
Uint16 slave_ack(void){
Uint16 i=0;
 asm (" RPT #90 || NOP");
 CLRSCL;
 asm (" RPT #60 || NOP");
 EALLOW;
 SDAIN;
 EDIS;
 asm (" RPT #90 || NOP");
 SETSCL;
 asm (" RPT #120 || NOP");
 i=GpioDataRegs.GPADAT.bit.GPIO16;
 CLRSCL;
 asm (" RPT #30 || NOP");
 return(i);
 }

//**********START BIT*********
void start_bit(void){
 EALLOW;
 SDAOUT;
 EDIS;
 SETSDA;  
 SETSCL;
 asm (" RPT #60 || NOP");
 SETSDA;
 asm (" RPT #60 || NOP");
 CLRSDA;
 asm (" RPT #60 || NOP");
 CLRSCL;
 asm (" RPT #60 || NOP");
 }

//**********STOP BIT**********
void stop_bit(void){
 EALLOW;
 SDAOUT;
 EDIS;
 CLRSDA;
 asm (" RPT #60 || NOP");
 SETSCL;
 asm (" RPT #60 || NOP");
 SETSDA;
 asm (" RPT #60 || NOP");
 }

//*******NO ACKNOWLEDGE********
void no_ack(void){
 EALLOW;
 SDAIN;
 EDIS;
 asm (" RPT #60 || NOP");
 SETSCL;
 asm (" RPT #60 || NOP");
 CLRSCL;
 asm (" RPT #60 || NOP");
 }
//*******SELECTIVE READ********
Uint16 select_rd(Uint16 adres){
Uint16 j=0,i,k=0;
     start_bit();
          
     shifto(SLV_ADDR,8); 
           j = slave_ack();

     shifto(0x0,8); 
          
           j = slave_ack();

     shifto(adres&0xff,8); 
     j = slave_ack();
      
     start_bit(); 

     shifto(0x80|SLV_ADDR,8); 
     j = slave_ack();

           for (i=0;i<8;i++){
     EALLOW;
     SDAIN;
     EDIS;
     SETSCL;
     asm (" RPT #60 || NOP");
     k=k>>1;
     if (GpioDataRegs.GPADAT.bit.GPIO16) k=k|0x8000;
     else k=k&0x7fff;
     CLRSCL;
     asm (" RPT #60 || NOP");
     }
     k=(k>>8)&0xff;
     no_ack();
     stop_bit();
     return(k);
     }
==================================

in the main(); simply code this

   init_I2C();

    parameter1= select_rd(0)+256*select_rd(0x1);

it reads a 16 bit word from the first adress