AnsweredAssumed Answered

STM32F3 I2C communication flow

Question asked by MaRiSiPāLa on Aug 3, 2013
hi every one,
I'm new to STM microcontrollers and i've recently bought an STM32F3 Discovery board.
now i'm going to use it to communicate with the in built compass sensor through its I2C interface. using its I2C firmware library, i've currently configured (hopefully) the I2C1 peripheral, and wondering what functions to be used to send and receive data.
this is as far i could code and hope someone can point me what functions to be called in order to write data to and read data from the sensor. (in steps)

#include "main.h"
// #include "stm32f3_discovery.h"
#include "stm32f30x.h"


void RCC_Config(void)
{
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);               
}


void GPIO_Config(void)
{
     GPIO_InitTypeDef GPIO_InitStructure;
     
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_4);  //B6 -I2C1_SCL
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_4);  //B7 -I2C1_SDA
     
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;     
     GPIO_Init(GPIOB, &GPIO_InitStructure);
     
}


void I2C1_Config(void)
{
     I2C_InitTypeDef I2C_InitStructure;
     
     I2C_InitStructure.I2C_Timing = 0;
     I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable;
     I2C_InitStructure.I2C_DigitalFilter = 0;
     I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
     I2C_InitStructure.I2C_OwnAddress1 = 0;
     I2C_InitStructure.I2C_Ack = I2C_Ack_Disable;
     
     I2C_Init(I2C1, &I2C_InitStructure);
     I2C_Cmd(I2C1, ENABLE);
}


int main(void)
{
     RCC_Config();
 
  GPIO_Config();
 
  I2C1_Config();
  
  while(1)
     {
          
     }
     
}

Thanks in advance :)

Outcomes