cancel
Showing results for 
Search instead for 
Did you mean: 

how to configure i2c in stm32f446 nucleo 144

ANNU CHERIAN
Associate II
Posted on September 09, 2017 at 07:18

The original post was too long to process during our migration. Please click on the attachment to read the original post.
4 REPLIES 4
ANNU CHERIAN
Associate II
Posted on September 12, 2017 at 13:50

Why i2c data reception cannot be achieved from rtc in stm32f446. I can write data to rtc. I tried to receive data using hal driver but then also data reception doesn't occurs. 

             

HAL_I2C_Master_Receive(&hi2c2, 0xDF, data_read, 3, 1000);

Posted on September 12, 2017 at 16:18

Use 0xDE, and let the downstream code set the R/W bit

I2C2->DR |= 0XDE;   // What the heck? Just write the register, don't OR it

I2C2->DR |= 0x00; // Ok, this does what?

Register level programming requires some grasp of what is going on

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 13, 2017 at 15:11

Thank you sir for your reply . I got the code for i2c write operation  when i enabled gpio output type as open drain and when OR operation removed .But i couldn't read

data from rtc .Always data shows 0 .

void i2c_start()

{

    while(I2C2->SR2 & (1<<1));                                     // wait until I2C1 is not busy anymore

    I2C2->CR1 |= (1<<0);                                          // Peripheral enable

    I2C2->CR1 &= ~(1<<11);                                       // Disable POS

    I2C2->CR1 |= (I2C_CR1_START);                               // Send I2C1 START condition

    while(!((I2C2->SR1 & I2C_SR1_SB) && (I2C2->SR2 & 0x03)));   // wait for I2C1 EV5 (check start condition,bus busy,master mode)

    I2C2->DR = 0XDE;                                           // slave address

     while(!((I2C2->SR1 & 0X82) && (I2C2->SR2 & 0x07)));       // wait for I2C1 EV6 (check address sent,data bytes transmitted,bus busy,master mode)

}

void i2c_write()

{

    I2C2->DR = 0x00;

    while(!((I2C2->SR1 & 0x84) && (I2C2->SR2 & 0x07)));         // check data register empty,data byte transfer succeeded

}

void i2c_restart()

{

    I2C2->CR1 |= (I2C_CR1_START);                                      // Send I2C1 START condition

    while(!((I2C2->SR1 & I2C_SR1_SB) && (I2C2->SR2 & 0x03)));          // wait for I2C1 EV5 (check start condition,bus busy,master mode)

    I2C2->DR = 0XDF;                                                   // slave address

    I2C2->SR1 &= ~(1<<10);                                             // Acknowledge disable

     while(!((I2C2->SR1 & I2C_SR1_ADDR) && (I2C2->SR2 & 0x07)));        //wait for I2C1 EV6 (check address sent,data bytes transmitted,bus busy,master mode)

}

void i2c_stop()

{

    I2C2->CR1 |= (I2C_CR1_STOP);

}

void i2c_read()

{

    while((I2C1->SR1 & I2C_SR1_RXNE));

    data = I2C1->DR;

}
Posted on September 14, 2017 at 06:25

Sorry , ...

void i2c_read()

{

    while(!(I2C1->SR1 & I2C_SR1_RXNE));

    data = I2C1->DR;

}

waiting on while(!(I2C1->SR1 & I2C_SR1_RXNE));