AnsweredAssumed Answered

STM32F0308-DISCOVERY I2C Configuration

Question asked by Lesueur.Rick on Feb 12, 2014
Latest reply on Feb 12, 2014 by Lesueur.Rick
My original post *poof* gone..

I am attempting to use I2C2, however Oscilliscope does not see any activity on either SCL or SDA. Using STM32F0308-Discovery. Obviously timing parameter is wrong, have tried many as I seem to be missing documentation, not sure that is only issue here. I have been wrestling with this issue for 2+ weeks and have exhausted all other options, Any assistance would be greatly appreciated. Note I am using GPIO PF6/PF7 as I2C2, as this part does not support I2C1 for these pins,  I2C1 is unused. Both pins are high at power up with external pull up resistors.  Have start delay of 50ms after reset and  prior to initializing I2C2.

void print7SegDisplay(void) {
  uint16_t i =0;
  uint16_t testdata = 0x7D;
  // Configures the slave address to be transmitted after start generation.
  I2C_SlaveAddressConfig(I2C2, 0x70);
  I2C_MasterRequestConfig(I2C2, I2C_Direction_Transmitter);
  I2C_GenerateSTART(I2C2, ENABLE);
  I2C_NumberOfBytesConfig(I2C2, 9); // number of bytes to send
  I2C_SendData(I2C2, 0x21);  // turn on Oscillator
  I2C_SendData(I2C2, 0x81);  // turn on Display
  for (i=0; i<8; i++) {
    I2C_SendData(I2C2, testdata);
    I2C_SendData(I2C2, testdata >> 8);    
  I2C_GenerateSTOP(I2C2, ENABLE); 

void I2C_Configure(void)
  // I2C2 Configuration STM32F0308-DISCOVERY on GPIO PF6 & PF7 
  // Note does not use I2C1 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ; //SCL 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource6, GPIO_AF_1); 
  GPIO_Init(GPIOF, &GPIO_InitStructure); 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ; //SDA
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource7, GPIO_AF_1); 
  GPIO_Init(GPIOF, &GPIO_InitStructure); 
  // I2C_InitTypeDef  I2C_InitStructure;

  I2C_InitTypeDef I2C_InitStructure; 
  I2C_InitStructure.I2C_Timing              = 0x00;
  I2C_InitStructure.I2C_AnalogFilter        = I2C_AnalogFilter_Disable;
  I2C_InitStructure.I2C_DigitalFilter       = 0x00;
  I2C_InitStructure.I2C_Mode                = I2C_Mode_I2C; 
  I2C_InitStructure.I2C_OwnAddress1         = 0x00;
  I2C_InitStructure.I2C_Ack                 = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_Cmd(I2C2, ENABLE);//I2C Peripheral Enable 
  I2C_Init(I2C2, &I2C_InitStructure);//Apply I2C configuration after enabling it