cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with STR750 I2C interface and software library

rjohnweber
Associate II
Posted on September 24, 2008 at 02:48

Problem with STR750 I2C interface and software library

3 REPLIES 3
rjohnweber
Associate II
Posted on September 24, 2008 at 02:30

Hi There,

I'm trying to get the I2C interface working on the STR750. I've been able to send a 7-bit address AND see an acknowledgment on an oscilloscope.

I'm using the STR750 library and the following code to write several bytes. This is largely the same as the default I2C EEPROM example:

Code:

void i2c_master_byte_write(u8* pBuffer, u8 WriteAddr)

{

/* Send STRAT condition */

I2C_GenerateSTART(ENABLE);

/* Test on EV5 and clear it */

while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));

/* Send EEPROM address for write */

I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_MODE_TRANSMITTER);

/* Test on EV6 and clear it */

while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECTED));

/* Clear EV6 by setting again the PE bit */

I2C_Cmd(ENABLE);

/* Send the EEPROM's internal address to write to */

I2C_SendData(WriteAddr);

/* Test on EV8 and clear it */

while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));

/* Send the byte to be written */

I2C_SendData(*pBuffer);

/* Test on EV8 and clear it */

while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));

/* Send STOP condition */

I2C_GenerateSTOP(ENABLE);

}

The problem is that the code hangs in

while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECTED));

This is where it is supposed to make sure that the 7-bit address has been sent and acknowledged (EV6).

The problem that I can see in IAR Workbench is that the ADD10 bit is 1 and the ENDAD bit is 0. To me, this seems to say that the library is trying to send a 10 bit address when I know it should not be (because I'm calling I2C_Send7BitAddress). But, I can find no provisions in the datasheet or reference manual for setting the I2C controller to 10-bit addressing.

So, here's what I'm guessing is the case - the I2C calls in the library are flawed in that they don't take into account that the ADD10 bit is going to be set to 1 for ANY start transaction. If one were trying to talk to a 10-bit slave there would be code to check for this, write the next byte of address, and then look for ENDAD after that. If one is to write code for a 7-bit slave, one has to wait for the ADD10 bit to be set, ignore it, write the PE bit, and then check for ENDAD to be set to 1.

Has anyone seen this particular behavior?

John

rjohnweber
Associate II
Posted on September 24, 2008 at 02:45

OK. Nevermind. The issue is that I was using an I2C address that just happened to be the I2C 10-bit header. So, for all of you folks out there new to I2C as I am, don't use 0x11110xx0 for the 7-bit address. The STR750 will think it's the header byte of a 10-bit address cycle.

Wasted way too many cycles on this problem.

rjohnweber
Associate II
Posted on September 24, 2008 at 02:48

Yes, and according the the I2C spec, you should NOT use any address that looks like 0xFx. These are reserved even for 7-bit addressing. Just FYI so someone here doesn't waste a lot of time as I did.