I2C interface for 9S12DP256

Started by September 27, 2004
Hello !

I'm trying to start I2C bus on 9S12DP256, with ImageCraft Compiler ICC12,
P&E BDM, NoIce debugger, quartz 12 Mhz.

Now without any success.
-:(((

I analysed the soft provided in Application Note AN2318, Which run under
interruptions.
It doesn't run in my system.

So I tried to run I2C protocol without interruption, because I can follow
what append under NoIce...

Now I can recognize if my extern I2C component (E2Prom) is present
(correctly addressed).
I look I2C signals with oscilloscope,
I can see ACK send by the I2C component, but I don't see datas send from
it.) Somebody can help me ?

With all my thanks. Joel Following the code I wrote for reading datas from I2C E2Prom
//********************************************************************
char I2C_ReadTab (char ad_i2c, char ad_start, char *t, char nb_elem) { char
i, ok;

// 1) Writing I2C address, prepare for write reading address
ad_i2c &= 0xfe; // prepare ad I2C component for Write
IBSR = 0x12;
IBCR = (IBEN | MS_SL_ | TX_RX_);
IBDR = ad_i2c; // send I2C address
ok = I2C_WaitFree (); // wait for I2C interface free + ACK
if (ok) // ACK received
{ IBDR = ad_start; // send reading address
ok = I2C_WaitFree (); // ok <- 1 if ACK
}
else
{ I2C_Stop ();
}

// 2) Writing I2C address, prepare for read datas if (ok)
{ ad_i2c |= 0x01; // prepare ad I2C component for Read
IBCR = (IBEN | MS_SL_ | TX_RX_ | RSTA);
IBDR = ad_i2c;
ok = I2C_WaitFree (); // ok <- 1 if ACK
}

// 3) Rread of nb-1 bytes with ACK from Master if (ok)
{ IBCR = (IBEN | MS_SL_); // Master, reption, ACK par master
for (i=0; i<nb_elem-1; i++)
{ I2C_WaitFree ();
*t = IBDR;
t++;
}
}

// 4) Read of last byte with NOACK from Master
IBCR = (IBEN | MS_SL_ | TXAK_); // master recept, no ACK
I2C_WaitFree ();
*t = IBDR;

// 5) Free I2C bus
I2C_WaitFree ();
I2C_Stop ();

return ok;
}
//********************************************************************
#define I2C_WAIT 100 // if no wait... Doesn't run... ???

void I2C_Stop (void)
{ char c;
// Enable I2C, NO interruption, SLAVE (--> send STOP)
IBCR = (IBEN);
for (c = 0; c < I2C_WAIT; c++)
;
}

//********************************************************************
// Wait for free bus (end of transmission) // Return 1 if ACK received, else
0 char I2C_WaitFree (void) { char fin, ok; volatile char status;

fin = 0;
ok = 0;
do
{ status = IBSR;
if (status & IBAL) fin = 1; // lost arbitration
if (status & TCF) fin = 1; // transmit complete
if (!(status & RXAK)) ok = 1; // test AKCnowledge
IBSR = 0x12; // clear flags of Status
} while (!fin );

// little wait loop
// 100 needed... 50 doesn't run... (Quartz 12 Mhz)
for (fin = 0; fin < I2C_WAIT; fin++)
;

return ok;
}