AnsweredAssumed Answered

STM32F051 I2C variable length slave read

Question asked by barber.mark on Sep 18, 2015
Latest reply on Feb 10, 2017 by marks.sasha
Hi All,

I am having an interesting I2C problem. A slave device i am reading from has a variable length response, the length of data is read from the device so i do not know how much i need to read until i start the process. As such the HAL drivers are not very useful. if you read more than you need to it seems to put the slave device into some odd mode and recovery is slow. once you start the read the data is only valid for that read cycle, so i cannot start then stop then start again. I feel that i need to use the old direct register acess method to develop my own driver. However the I2C peripheral from ST seems like its main target is the normal register type salve devices EEPROM, RTC etc.

I have the following code

            RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;      // enable I2C clock

            // reset I2C1
            RCC->APB1RSTR &=~RCC_APB1RSTR_I2C1RST;
            RCC->APB1RSTR &=~RCC_APB1RSTR_I2C1RST;

            // setup clock
            I2C1->TIMINGR |=0x1042c3c7;             // setup clocks

            // enable peripheral
            I2C1->CR1 |=I2C_CR1_PE;

            // setup start
            I2C1->CR2 |= 0x004a|I2C_CR2_RD_WRN;          // set slave address and master read mode and read
            // send start condition
            I2C1->CR2 |= I2C_CR2_START;                  // send start
            // wait for RXNE flag set

i can see on the scope that the slave address is correct and acknowledged, but nothing is read back there is no SCL clock, beyond the intial address send. Clealry i have missed somethig here. Any suggestions appreciated.

My last resort is to write my own bit banging I2C driver, this would be many steps backwards. Takes me back 20 years!