I2C master rutin - lamer kerdes

Istvan Retaller istvan.retaller at evoran.hu
Wed Aug 6 16:16:55 CEST 2003


8/6/2003 9:46:05 AM, "Mészáros" "Béla" <bela.meszaros at nexus.hu> wrote:

>Sziasztok!
>
>I2C-hez írtam c-ben rutinokat, amik soros eepromot kezelnek:
....
>Gondolom a harware jó, különben a device címet sem nyugtázná. Akkor meg hol a baj?

Szia, Bela!
Elore elnezest, ha valamit felreertettem, en alapvetoen assemblyben dolgozom.
Szoval szerintem az I2C_StartCondition masodik hivasa semmit nem csinal, nincs restart. 
A void I2C_StartCondition() ugyanis SDA-t es SCL-t teszi 0-ba. De mar eleve ott van !!!
A restartban azt is kene biztosítanod, hogy akkor is legyen start, ha SDA-nak mar a kiindulo allapota is low.
Udv, RI


unsigned char I2C_EEprom_RandomRead(unsigned char Addr, unsigned char *Byte)
{
unsigned char OK = 1;
I2C_StartCondition();
if (I2C_SendByte(0xa0)!=ACK) OK=0; /* Device addr + write (dummy) */
if (I2C_SendByte(Addr)!=ACK) OK=0; /* Ack */
I2C_StartCondition;
if (I2C_SendByte(0xa1)!=ACK) OK=0; /* Device addr + read */
*Byte=I2C_ReceiveByte(NO_ACK);
I2C_StopCondition;
return OK;
}



void I2C_StartCondition()
{
I2C_SDA = LOW;
Wait_Delay(10);
I2C_SCL = LOW;
Wait_Delay(10);
}




More information about the Elektro mailing list