cancel
Showing results for 
Search instead for 
Did you mean: 

I2C in ST10f276

dvir
Associate II
Posted on July 05, 2007 at 17:38

I2C in ST10f276

8 REPLIES 8
dvir
Associate II
Posted on May 25, 2006 at 13:40

Hello,

i'm trying to operate the I2C protocol but the only thing i can see in the logic analyzer is the start bit. this is my code:

I2CCR = 0x00;

I2COAR2 = 0x00A0; // set Fcpu = 64MHz

I2CCR = 0x0020;

I2CCR = 0x0020;

I2CCCR1 = 0x00F0; // set standard I2C

I2CCCR2 = 0x0001; // Fi2c = 64Khz

I2CCR |= 0x0008;

I2CDR = 0x55;

I2CCR |= 0x0002;

the u-controller freq. is 64Mhz and i set the I2C freq to 64Khz. CAN2 is disabled.

got any idea what's wrong?

thanks in advance,

Dvir

najoua
Associate II
Posted on May 26, 2006 at 06:13

Hello Dvir,

You are configuring the I2C in Fast mode(FM/SM =1). The SCL frequency = 64Mhz /(3x CC(11:0) + 9) & CC(11:0) = 0xF0

So, SCL frequency = 88Khz which doesn't correspond to Fast mode(< 100 Khz).

So, the CCR1 and CCR2 registers values should be changed.

There are somethings missing in your code:

- The ACK bit must be set in the CR register (Enable Acknowledge).

- After sending the START condition, a wait until the SB bit is set in I2CSR1 register is necessary. Then, this bit should be reset by software.

- Normally, the first write in DR register corresponds to the slave address sent by the Master. After this write, a wait until ENDAD bit is set in I2CSR2 register is also necessary. Then, this bit should be reset by software.

The status bits (in SR1 and SR2 registers) are set by hardware and reset by software. For more details, please refer to the Transfer Squencing and different events, in the ST10F276 user's manual(pages 370, 371).

Let's take an example:

----------------------

You want to write the data 0x10 in the address 0x00 of an I2C 8 bit eeprom. The eeprom address is 0xA0.

Fcpu = 64Mhz & SCL frequency = 50Khz (Standard mode).

#define I2C_PE ((unsigned char)0x20)

#define I2C_START ((unsigned char)0x08)

#define I2C_ACK ((unsigned char)0x04)

#define I2C_STOP ((unsigned char)0x02)

#define I2C_ITE ((unsigned char)0x01)

#define I2C_BTF ((unsigned char)0x08)

#define I2C_SB ((unsigned char)0x01)

#define I2C_ENDAD ((unsigned char)0x20)

void routine_I2C(void)

{

OAR2 = 0xA0;

CR |= I2C_PE;

CR |= I2C_PE;

CR |= I2C_ACK;

/* So for 50KHz at 64MHz */

CCR1 = 0x7C;

CCR2 = 0x04;

/* The master generates the START condition*/

CR |= I2C_START;

/* Check if START condition is generated */

while (!(SR1 & I2C_SB));

Temp = SR1; /* Clear SB bit */

/* The master sends the eeprom address */

DR = 0xA0;

/* The address transmission check is done with a pooling waiting

loop for the ENDAD flag.*/

while(!(SR2 & I2C_ENDAD));

/* Clear ENDAD bit */

Temp = SR2;

CR |= I2C_PE;

/* The master sends the eeprom address of the byte to be written*/

DR = 0x00;

/* Transmission check is done with a polling waiting loop for the BTF

flag of SR1 register.*/

while(!(SR1 & I2C_BTF));

/* The master sends the data byte to be written at 0x00 address */

DR = 0x10;

/* Transmission check is done with a polling waiting loop for the BTF

flag of SR1 register.*/

while(!(SR1 & I2C_BTF));

/* The master generates the STOP condition*/

CR |= I2C_STOP;

}

I hope this helps you.

Please let me know how it goes and if you have further questions.

Best regards,

Najoua.

dvir
Associate II
Posted on May 28, 2006 at 12:06

Hello Najoua,

thanks for your help, but i'm afraid i didn't make any progress.

The commands till the address sending are executed properly(start bit is generated), but when i try to write to the I2CDR register nothing happens: the I2CDR acts as if it is write protected and i can't see any transmission on the line either.

thanks in advance,

Dvir

najoua
Associate II
Posted on May 29, 2006 at 07:40

Hello Dvir,

Could you please tell me:

- what is the device you are using as Slave?

- what is the hardware on SCL and SDA pins? Given that, when the I2C cell is enabled, SCL and SDA are automatically configured as bidirectional open drain, two pull up resistors between VDD and the two lines must be added. A value of 4.7 K is recommended.

I hope this helps you,

Regards,

Najoua.

[ This message was edited by: Najoua on 29-05-2006 11:12 ]

dvir
Associate II
Posted on May 29, 2006 at 09:28

Hello Najoua,

my slave device is ST m41T56 Timekeeper SRAM, but i don't think this is the problem since i disconnected the slave and monitored the ST10 I2C ports and i did not see the address bits after the start bit.

I'm using the STart276 Evaluation kit of FS as my board.

thanks again,

Dvir

najoua
Associate II
Posted on May 29, 2006 at 10:09

Hello Dvir,

To be able to use the I2C peripheral on the ST10F276 board provided by FS FORTH, the two jumpers J7 and J8 must be removed. Could you please verify this point?

Regards,

Najoua.

dvir
Associate II
Posted on May 29, 2006 at 12:53

Hi Najoua,

removing J7, J8 solved the problem (in the manual SF refered to J2, J3).

Thanks and best regards,

Dvir 8-)

mkmonnin
Associate
Posted on July 05, 2007 at 17:38

Could you please provide a programming example for a sequential read on the ST10F276 I2C?

Thanks,

mkmonnin