cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F051 I2C variable length slave read

Barber.Mark
Associate III
Posted on September 18, 2015 at 03:49

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;

            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

            while((I2C1->ISR&I2C_ISR_RXNE)==0);

            i2c_buff[0]=I2C1->RXDR;

            while((I2C1->ISR&I2C_ISR_RXNE)==0);

            i2c_buff[1]=I2C1->RXDR;

           

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!

Mark

#i2c-stm32
1 REPLY 1
sasha
Associate III
Posted on February 10, 2017 at 06:53

Hi Mark - did you ever find a solution to this?  I've got the same problem...