cancel
Showing results for 
Search instead for 
Did you mean: 

I2C send only address bytes

marcel239955
Associate
Posted on August 12, 2010 at 18:36

I2C send only address bytes

4 REPLIES 4
Posted on May 17, 2011 at 14:02

>>What do I wrong? Is there a bug?

Probably a bug in your code, the I2C buses work fine. Try providing some code examples and the chip you are communicating with.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
marcel239955
Associate
Posted on May 17, 2011 at 14:02

The ST32 communicate with the component PCA9633 (it is a LED driver)

I have my code very simplified to find the root cause:

void I2CInit(void) {

 RCC->APB1ENR |= 0x00400000;      // Pheripherie Clk für I2C1

 RCC->APB2ENR |= 0x00000008;      // Pheripherie Clock für PortB freischalten

 I2C2->CR1 |= 0x8000;       // SWRST

 I2C2->CR1 &= ~0x8000;       // SWRST

 I2C2->CR1 |= 0x0001;       // I/O Pins für I2C einschalten (PE)

 I2C2->CR2 |= 0x00000024;      // FREQ = 36MHz

 I2C2->CCR |= 0x000000B4;      // Busfrequenz = 100kHz

 I2C2->CR1 |= 0x0400;       // ACK

}

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

int main (void)  {

// Slave component: PCA9633

// PB10 = SCL

// PB11 = SDA

I2CInit();

stm32_Init ();                                  /* STM32 setup */

 for (counter = 0; counter <=255; counter++) {

  I2C2->CR1 |= 0x0100;      // I2C Send I2C start

  delay(50000);

  delay(50000);

    

  I2C2->DR = 0x02;       // PCA9633 slave address

    temp = I2C2->SR1;        // Read SR register to clear ADDR

  temp += temp;

    temp = I2C2->SR2;          // Read SR register to clear ADDR

  temp += temp;

  delay(50000);

  delay(50000);

  I2C2->DR = 0x03;       // PCA9633 control register

  delay(50000);

  delay(50000);

  I2C2->DR = counter;       // Brightness control LED0 Register

  delay(50000);

  delay(50000);

 

  I2C2->CR1 |= 0x0200;      // I2C send stop

  delay(50000);

  delay(50000);

  } 

}
mtaallah
Associate II
Posted on May 17, 2011 at 14:02

Hi born,

I have some proposal :

- Are you sure that GPIO are correctly configured ( AF Open drain).

- When communication crashs, check if flag errors(ARLO,OVR,AF,BERR) are set or no.

- Change delay by waiting until TXE flag is set ( after sending one byte wait until TXE flag is equal to 1 after that send the next byte).

I have some recommendation while using I2C IP : you should after each operation check if related flag are set or no to correctly manage the communication.

Good Bye.

drzile86
Associate II
Posted on May 17, 2011 at 14:02

Hi,

I wrote several codes using I2C bus and I2C bus works just fine. Try to use Standardd Peripheral Examples which you can download on st.com.

Cheers,

Dragan