AnsweredAssumed Answered

stm32F746 and I2C

Question asked by franzi.edo on Dec 7, 2015
Latest reply on Dec 10, 2015 by karpavicius.linas
Hi,
Just need some help with the I2C peripheral of the 32f7. I would like to read 2 bytes from an imager Aptina. The i2c sequence is composed of 1 write cycle followed by 2 read cycles. After the write, the stop has not to be sent and a new start sequence has to take place: in a short, the sequence should be this one:

Start
Send the address
write the register number (1 byte)
Start
Send the address
Read the register content (2 byte)
Stop


Here is my test code that of course, it does not work. Any idea of how to implement this sequence? Any simple code example?
Thank you
  Regards, Edo

void     i2c2_init(void) {

     RCC->APB1ENR |= RCC_APB1ENR_I2C2EN;

// Initialize the I2C Master, default speed 100-KHz 0x4 0 9 1 27 32

     I2C2->TIMINGR = (4<<28)          // Timing prescaler
                      | (9<<20)          // Data setup time
                      | (1<<16)          // Data hold time
                      | (27<<8)          // SCL high period
                      | (32<<0);          // SCL Low period

     I2C2->CR1       = (1<<12);          // Analog filter off
}

void     i2c2_read(uint8_t address, uint8_t *buffer) {
     uint16_t     i;

// Write: Send the register number

     I2C2->CR2 = (1<<16)               // 1 bytes to write
                  | (address<<0);          // The slave address

     I2C2->CR2 |= (1<<13);               // START

     while (!(I2C2->ISR & I2C_ISR_TXE));
     I2C2->TXDR = 0x23;                    // Register 23

// Read: Read the register 23 content

     I2C2->CR2 = (1<<25)               // Automatic end mode
                 | (2<<16)               // 2 bytes to read
                 | (1<<10)               // Read transfer
                 | (address<<0);          // The slave address

     I2C2->CR2 |= (1<<13);               // START

     for (i = 0; i < size; i++) {
          while (!(I2C2->ISR & I2C_ISR_RXNE));

// !!!!!! never reach this point

          *buffer++ = I2C2->RXDR;
     }

// Wait until the stop condition was automatically sent

     while (!(I2C2->ISR & I2C_ISR_STOPF));
     I2C2->ISR &= ~I2C_ISR_STOPF;
}




Outcomes