hi sir/madam,
i working i2c protocol by using two port pins.after writing data ack is not getting please help me.when write mode first send start condition and then slave address and then write bit is 0 after that ack is not getting what is the problem? i couldn't understand can u please any information. please help sir
from satish.
Have you got anything connected to the other end of the bus?
Is your i2c peripheral even powered up? Is it configured? Is your clock signal to the device within spec. for that device, etc. etc. etc. ?
in read mode only getting FF only .
can please refer the below code
void i2c_start_cond(void) { SDA = 1; SCL_delay(); SCL = 1; // SCL_delay(); I2CDELAY(I2CSPEED >> 2); SDA = 0; } void i2c_stop_cond(void) { SCL = 0; SCL_delay(); SDA = 0; SCL_delay(); SCL = 1; // SCL_delay(); I2CDELAY(I2CSPEED >> 2); SDA = 1; }
/* Write a bit to I2C bus */ void i2c_write_bit(unsigned bit) { SCL_delay(); SCL = 0; if (bit) SDA = 1; else SDA = 0; // SCL_delay(); I2CDELAY(I2CSPEED >> 2); SCL = 1; SCL_delay(); SCL = 0; }
/* Read a bit from I2C bus */ unsigned i2c_read_bit(void) { unsigned bit; SCL_delay(); SCL = 1; bit = SDA; SCL_delay(); I2CDELAY(I2CSPEED >> 2); SCL = 0; return bit; } /* Read a bit from I2C bus */ unsigned i2c_read_ack_bit(void) { unsigned char byte1; unsigned bit; SCL_delay(); SCL = 1; bit = SDA; SCL_delay(); SCL = 0; return bit; }
/* Write a byte to I2C bus. Return 0 if ack by the slave */ unsigned i2c_write_byte(int send_start, int send_stop, unsigned char byte) { unsigned bit; unsigned nack; if (send_start) { i2c_start_cond(); } for (bit = 0; bit < 8; bit++) { i2c_write_bit(byte & 0x80); byte <<= 1; } nack = i2c_read_ack_bit(); if (send_stop) { i2c_stop_cond(); } return nack; }
/* Read a byte from I2C bus */ unsigned char i2c_read_byte(int nak, int send_stop) { unsigned char byte = 0; unsigned bit; pd3_4 = 0; for (bit = 0; bit < 8; bit++) { byte <<= 1; byte |= i2c_read_bit(); } pd3_4 = 1; i2c_write_bit(nak); if (send_stop) { i2c_stop_cond(); } return byte; }
"i working i2c protocol by using two port pins."
Come to think of it ... are the two port pins connected to anything ... maybe some sort of processor?
I'm blinded by the lack of information!
no these pins only for i2c.
i am able communicate eprom.but i can't able to communicate rtc (DS1307), can please help me.
"no these pins only for i2c."
Welcome to the Keil comedy show.
... the messiest code this month.
if you want help, post CLEAR code and do not forget to verify in preview that it is CLEAR before you post.
I doubt anyone has an inkling to try to figure out the mess you posted.
you also missed "Place source code source code between ......" above the posting window
Erik