Hi,
I have not an answer to your question neither a solution but a similar problem.
My implementation looks equal:
void IIC_Init(void)
{
// clear control and status register
IIC1C = 0;
IIC1S = 0;
IIC1C_IICEN = 1; // Enable I2C;
IIC1C_TXAK = 1; // not generate ACK by master after transfer;
IIC1C_MST = 1; // Master mode actually; Generates a start signal
IIC1C_TX = 1; // Master is transmitting
IIC1F = 0x40; // mult = 1, ICR = 0;
}
and my read looks like:
byte IIC_readFirst_byte(byte addr)
{
byte temp;
temp = addr << 1;
if(!IIC1C_MST)
IIC1C_MST = 1;
IIC1C_TXAK = 0; // RX/TX = 1; MS/SL = 1; TXAK = 0;
IIC1C |= 0x30; // And generate START condition;
IIC1D = temp; // Address the slave and set up for master transmit;
while(!IIC1S_IICIF); // wait for byte transfer to complete
IIC1S_IICIF = 0;
while(IIC1S_RXAK); // check for RXAK;
//-----Slave ACK occurred------------
IIC1C_RSTA = 1; // set up repeated start;
IIC1D = 1; // read flag 1?
while(!IIC1S_IICIF); // wait for byte transfer to complete
IIC1S_IICIF = 0;
while (IIC1S_RXAK); // check for RXAK;
//-----Slave ACK occurred------------
IIC1C_TX = 0; // set up to receive;
// dummy read
RD_data = IIC1D;
while(!IIC1S_IICIF); // wait for byte transfer to complete
IIC1S_IICIF = 0;
IIC1C_TXAK = 0; // want to read more;
return RD_data;
}
I do the reading then in an other function call because the data I want to receive
needs some time to be ready for transfer.
I do not get some "usable" data out of the I^2 bus and I do not know why.
I send the address of the slave out on the bus and afterwards I send the 1 for the
slave to write now, but I have found 2 astonishing surprises:
1. After I send the address of the slave the SDA line moves up after ack of the slave
has arrived! Is this normal???
2. When I do not do the step by step debugging I can see on the oszi that after
sending out the address of the slave, the restart routin is called and then not the 1
that I send afterwards is on the bus no, it is a 0xff! I have no glue where this comes from.
Do you know what is going on on the bus?
I do not really understand the information of the jpeg you have send with.
Maybe finding togehter a solution for both problems?
Greetings,
xmas