AnsweredAssumed Answered

STM32F3 (stm32f303vct6) + i2c + CMSIS

Question asked by raf.anna on Aug 18, 2014
Latest reply on Aug 24, 2014 by raf.anna
I'm trying to connect this port to i2c standard PCF8574 I/O expander.

And I can't get it to work.
My GPIO init code:
01.RCC->APB1ENR |= ( RCC_APB1ENR_I2C1EN | RCC_APB1ENR_I2C2EN );
02.RCC->AHBENR |= ( RCC_AHBENR_GPIOAEN );
03. 
04.  if ( hi2c == I2C2 ) {
05. 
06.      GPIOA->MODER |= ( GPIO_MODER_MODER9_1 | GPIO_MODER_MODER10_1 );
07.      GPIOA->OTYPER |= ( GPIO_OTYPER_OT_9 | GPIO_OTYPER_OT_10 );
08.      GPIOA->OSPEEDR &= ~( GPIO_OSPEEDER_OSPEEDR9 | GPIO_OSPEEDER_OSPEEDR10 );
09.      GPIOA->AFR[1] |= ( (GPIO_AFRH_AFRH1 & 0x0100) | (GPIO_AFRH_AFRH2 & 0x0100) );
10.  }
11.  if ( hi2c == I2C1 ) {
12.      GPIOA->MODER |= ( GPIO_MODER_MODER14_1 | GPIO_MODER_MODER15_1 );
13.      GPIOA->OTYPER |= ( GPIO_OTYPER_OT_14 | GPIO_OTYPER_OT_15 );
14.      GPIOA->OSPEEDR &= ~( GPIO_OSPEEDER_OSPEEDR14 | GPIO_OSPEEDER_OSPEEDR15 );
15.      GPIOA->AFR[1] |= ( (GPIO_AFRH_AFRH6 & 0x0100) | (GPIO_AFRH_AFRH7 & 0x0100) );
16.  }
My I2C Init code:
01.// clear PE
02.  hi2c->CR1 &= ~I2C_CR1_PE;
03.  hi2c->CR1 = 0x00;
04. 
05.  // ANFOFF =1 _ Analog noise filter disabled;
06.  // DNF =0 _ Digital filter disabled;
07.  hi2c->CR1 = 0x1000;
08.  // SCLL =45
09.  // SCLH =29
10.  // SDADEL =0;
11.  // SCLDEL =1;
12.  // PRESC =0;
13.  hi2c->TIMINGR = 0x101D2D;
14.  // NOSTRETCH =1 _ Clock stretching disabled
15.  hi2c->CR1 |= I2C_CR1_NOSTRETCH;
16. 
17.  // set PE
18.  hi2c->CR1 |= I2C_CR1_PE;
My MasterRead code:
01.// addressing mode _ 0: The master operates in 7-bit addressing mode
02.  hi2c->CR2 &= ~I2C_CR2_ADD10;
03.  // slave address to be sent _
04.  hi2c->CR2 |= (address << 1);
05.  // Transfer direction _ 1: Master requests a read transfer.
06.  hi2c->CR2 |= I2C_CR2_RD_WRN;
07.  // the number of bytes to be transferred _ NBYTES 23-16b
08.  hi2c->CR2 |= dataSize << 16;
09. 
10.  while( (hi2c->ISR & I2C_ISR_BUSY) == I2C_ISR_BUSY );
11.  hi2c->CR2 |= I2C_CR2_START;
12. 
13.  // 1: Automatic end mode: a STOP condition is automatically sent when NBYTES data are transferred.
14.  // 0: software end mode: TC flag is set when NBYTES data are transferred, stretching SCL low.
15.  hi2c->CR2 |= I2C_CR2_AUTOEND;
16. 
17.  while ( dataSize ) {
18.      // I2Cx_ISR.RXNE =1?
19.      while( (hi2c->ISR & I2C_ISR_RXNE) != I2C_ISR_RXNE );
20.      //YES
21.      *data = hi2c->RXDR;
22.      data++;
23.      dataSize--;
24.  }
25. 
26.  //hi2c->CR2 |= I2C_CR2_STOP;
27.  while( (hi2c->ISR & I2C_ISR_STOPF) != I2C_ISR_STOPF );

And it all stops on
while( (hi2c->ISR & I2C_ISR_RXNE) != I2C_ISR_RXNE );
line.
On osciloscope I don't see any START... etc.

I can't figure out what am I doing wrong...

Outcomes