Problems to getting IIC with EEPROM to work! -  MC9S12XDT512

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems to getting IIC with EEPROM to work! -  MC9S12XDT512

1,507 Views
nic_mcp
Contributor I
Hi @ all,

i've little problems to get my IIC bus to work.
I try to read from an EEPROM, but i only get 0xFF in my data array.
I'm using the 9S12XDT512 and a Microchip 24LC16B EEPROM.

Here is my code:

int flag; // flag for the IIC-IR
int length; // datalength to read from IIC
int i; // counter for data
byte rAdr; // byte adress (EEPROM data)
byte dummy; // dummy byte for reading data
byte data[2048] = 0; // data from IIC


void IIC_Init(void)
{
    IIC0_IBFD = 0x4C; // frequency divider register: Bus = 8Mhz =>SCL = 91 kHz
    IIC0_IBAD = 0x00; // slave address of this module
    IIC0_IBSR = 0x12; // clear the IBAL and IBIF flags
    IIC0_IBCR = 0xC0; // enables ICC with interrupts
}

/******************************************************************
************************ END IIC_Init *****************************
******************************************************************/

/******************************************************************
  Function:     void IIC_Read(unsigned char read_addr)
  Developer:    nic_mcp
  Parameters:   read_addr: address of slave;
  Returns:      Nothing
  Description:  read EEPROM data
******************************************************************/

void IIC_Read(unsigned char read_addr, int len)
{
   flag=10;
   length = len;
   i=0;
   rAdr = read_addr;
   IIC0_IBCR_MS_SL = 1; // set transmit and master mode
   IIC0_IBCR_TX_RX = 1; // and generate start condition
   IIC0_IBDR = 0xb1;  // Send Slave Adress with read mode
}

/******************************************************************
************************ END IIC_Read *****************************
******************************************************************/

/******************************************************************
  Function:     void IIC_IR()
  Developer:    nic_mcp
  Parameters:   none
  Returns:      Nothing
  Description:  called by interrupt
******************************************************************/

void IIC_IR()
{
    IIC0_IBSR = 0x12; // clear the IBAL and IBIF flags
   
    switch(flag)
    {
   
      case 10:
      {
        IIC0_IBDR = rAdr;
        flag++;
        return;
      }
      case 11:
      {
        IIC0_IBDR = rAdr;
        flag++;
        return;
      }
      case 12:
      {
        IIC0_IBCR_RSTA = 1; // set up repeated start
        IIC0_IBDR = 0xa1;
        flag++;
        IIC0_IBCR_TX_RX = 0;
        IIC0_IBCR_TXAK = 0;
        return;
      }
     
      case 13:
      {
        if (length>1)
        {
          data[i] = IIC0_IBDR; // read data from bus
          length--;
          i++;
          return;
        } else
        {
           IIC0_IBCR_TXAK = 1; // ACK disabled
           i++;
           length--;
           flag++;
           return;
        }  
      }
      case 14:
      {
        IIC0_IBCR_MS_SL = 0; // create stop condition
        flag = 0;
        return;
      }
    
    }
}

/******************************************************************
************************ END IIC_IR *******************************
******************************************************************/



/******************************************************************
  Function:     void main(void)
  Developer:    nic_mcp
  Parameters:   none
  Returns:      Nothing
  Description:  main-method
******************************************************************/


void main(void)
{
  /* put your own code here */
  EnableInterrupts;
  IIC_Init(); // initialize the IIC-modul
  IIC_Read(0x00,2048); // read EEPROM
  for(;:smileywink:
  {
   
  } /* wait forever */
  /* please make sure that you never leave this function */
 
}

/******************************************************************
************************ END main *********************************
******************************************************************/

Can somebody help me to get this working?

thx nic_mcp






Added p/n to subject.


Message Edited by NLFSJ on 2007-11-29 02:50 PM
Labels (1)
0 Kudos
1 Reply

335 Views
michael_galda
NXP Employee
NXP Employee
Hi nic_mcp,
I have attached my old project for 24C16 & DP256 for reference.
It worked fine. But you can do the things little bit easier than me.:smileywink:
I hope it helps.
More information about S12 & S08 I2C module with complete SW routines you can find in AN3291
 
 
Message Edited by t.dowe on 2009-10-21 12:15 AM
0 Kudos