I2C
[STM32F30x_StdPeriph_Driver]

I2C driver modules. More...

Classes

struct  I2C_InitTypeDef
 I2C Init structure definition. More...

Modules

 I2C_Exported_Constants
 I2C_Private_Functions

Defines

#define CR1_CLEAR_MASK   ((uint32_t)0x00CFE0FF)
#define CR2_CLEAR_MASK   ((uint32_t)0x07FF7FFF)
#define TIMING_CLEAR_MASK   ((uint32_t)0xF0FFFFFF)
#define ERROR_IT_MASK   ((uint32_t)0x00003F00)
#define TC_IT_MASK   ((uint32_t)0x000000C0)

Functions

void I2C_DeInit (I2C_TypeDef *I2Cx)
 Deinitializes the I2Cx peripheral registers to their default reset values.
void I2C_Init (I2C_TypeDef *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
 Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
void I2C_StructInit (I2C_InitTypeDef *I2C_InitStruct)
 Fills each I2C_InitStruct member with its default value.
void I2C_Cmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the specified I2C peripheral.
void I2C_SoftwareResetCmd (I2C_TypeDef *I2Cx)
 Enables or disables the specified I2C software reset.
void I2C_ITConfig (I2C_TypeDef *I2Cx, uint32_t I2C_IT, FunctionalState NewState)
 Enables or disables the specified I2C interrupts.
void I2C_StretchClockCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C Clock stretching.
void I2C_StopModeCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C wakeup from stop mode.
void I2C_DualAddressCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C own address 2.
void I2C_OwnAddress2Config (I2C_TypeDef *I2Cx, uint16_t Address, uint8_t Mask)
 Configures the I2C slave own address 2 and mask.
void I2C_GeneralCallCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C general call mode.
void I2C_SlaveByteControlCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C slave byte control.
void I2C_SlaveAddressConfig (I2C_TypeDef *I2Cx, uint16_t Address)
 Configures the slave address to be transmitted after start generation.
void I2C_10BitAddressingModeCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C 10-bit addressing mode for the master.
void I2C_AutoEndCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C automatic end mode (stop condition is automatically sent when nbytes data are transferred).
void I2C_ReloadCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C nbytes reload mode.
void I2C_NumberOfBytesConfig (I2C_TypeDef *I2Cx, uint8_t Number_Bytes)
 Configures the number of bytes to be transmitted/received.
void I2C_MasterRequestConfig (I2C_TypeDef *I2Cx, uint16_t I2C_Direction)
 Configures the type of transfer request for the master.
void I2C_GenerateSTART (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Generates I2Cx communication START condition.
void I2C_GenerateSTOP (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Generates I2Cx communication STOP condition.
void I2C_10BitAddressHeaderCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables the I2C 10-bit header only mode with read direction.
void I2C_AcknowledgeConfig (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Generates I2C communication Acknowledge.
uint8_t I2C_GetAddressMatched (I2C_TypeDef *I2Cx)
 Returns the I2C slave matched address .
uint16_t I2C_GetTransferDirection (I2C_TypeDef *I2Cx)
 Returns the I2C slave received request.
void I2C_TransferHandling (I2C_TypeDef *I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode)
 Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set).
void I2C_SMBusAlertCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C SMBus alert.
void I2C_ClockTimeoutCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C Clock Timeout (SCL Timeout detection).
void I2C_ExtendedClockTimeoutCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C Extended Clock Timeout (SCL cumulative Timeout detection).
void I2C_IdleClockTimeoutCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C Idle Clock Timeout (Bus idle SCL and SDA high detection).
void I2C_TimeoutAConfig (I2C_TypeDef *I2Cx, uint16_t Timeout)
 Configures the I2C Bus Timeout A (SCL Timeout when TIDLE = 0 or Bus idle SCL and SDA high when TIDLE = 1).
void I2C_TimeoutBConfig (I2C_TypeDef *I2Cx, uint16_t Timeout)
 Configures the I2C Bus Timeout B (SCL cumulative Timeout).
void I2C_CalculatePEC (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C PEC calculation.
void I2C_PECRequestCmd (I2C_TypeDef *I2Cx, FunctionalState NewState)
 Enables or disables I2C PEC transmission/reception request.
uint8_t I2C_GetPEC (I2C_TypeDef *I2Cx)
 Returns the I2C PEC.
uint32_t I2C_ReadRegister (I2C_TypeDef *I2Cx, uint8_t I2C_Register)
 Reads the specified I2C register and returns its value.
void I2C_SendData (I2C_TypeDef *I2Cx, uint8_t Data)
 Sends a data byte through the I2Cx peripheral.
uint8_t I2C_ReceiveData (I2C_TypeDef *I2Cx)
 Returns the most recent received data by the I2Cx peripheral.
void I2C_DMACmd (I2C_TypeDef *I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState)
 Enables or disables the I2C DMA interface.
FlagStatus I2C_GetFlagStatus (I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
 Checks whether the specified I2C flag is set or not.
void I2C_ClearFlag (I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
 Clears the I2Cx's pending flags.
ITStatus I2C_GetITStatus (I2C_TypeDef *I2Cx, uint32_t I2C_IT)
 Checks whether the specified I2C interrupt has occurred or not.
void I2C_ClearITPendingBit (I2C_TypeDef *I2Cx, uint32_t I2C_IT)
 Clears the I2Cx's interrupt pending bits.

Detailed Description

I2C driver modules.


Function Documentation

void I2C_10BitAddressHeaderCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C 10-bit header only mode with read direction.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C 10-bit header only mode. This parameter can be: ENABLE or DISABLE.
Note:
This mode can be used only when switching from master transmitter mode to master receiver mode.
Return values:
None 

Definition at line 774 of file stm32f30x_i2c.c.

00775 {
00776   /* Check the parameters */
00777   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00778   assert_param(IS_FUNCTIONAL_STATE(NewState));
00779   
00780   if (NewState != DISABLE)
00781   {
00782     /* Enable 10-bit header only mode */
00783     I2Cx->CR2 |= I2C_CR2_HEAD10R;
00784   }
00785   else
00786   {
00787     /* Disable 10-bit header only mode */
00788     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_HEAD10R);
00789   }
00790 }    

void I2C_10BitAddressingModeCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C 10-bit addressing mode for the master.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C 10-bit addressing mode. This parameter can be: ENABLE or DISABLE.
Note:
This function should be called before generating start condition.
Return values:
None 

Definition at line 553 of file stm32f30x_i2c.c.

00554 {
00555   /* Check the parameters */
00556   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00557   assert_param(IS_FUNCTIONAL_STATE(NewState));
00558   
00559   if (NewState != DISABLE)
00560   {
00561     /* Enable 10-bit addressing mode */
00562     I2Cx->CR2 |= I2C_CR2_ADD10;
00563   }
00564   else
00565   {
00566     /* Disable 10-bit addressing mode */
00567     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_ADD10);
00568   }
00569 } 

void I2C_AcknowledgeConfig ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Generates I2C communication Acknowledge.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the Acknowledge. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 799 of file stm32f30x_i2c.c.

00800 {
00801   /* Check the parameters */
00802   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00803   assert_param(IS_FUNCTIONAL_STATE(NewState));
00804   
00805   if (NewState != DISABLE)
00806   {
00807     /* Enable ACK generation */
00808     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_NACK);    
00809   }
00810   else
00811   {
00812     /* Enable NACK generation */
00813     I2Cx->CR2 |= I2C_CR2_NACK;
00814   }
00815 }

void I2C_AutoEndCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C automatic end mode (stop condition is automatically sent when nbytes data are transferred).

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C automatic end mode. This parameter can be: ENABLE or DISABLE.
Note:
This function has effect if Reload mode is disabled.
Return values:
None 

Definition at line 618 of file stm32f30x_i2c.c.

00619 {
00620   /* Check the parameters */
00621   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00622   assert_param(IS_FUNCTIONAL_STATE(NewState));
00623   
00624   if (NewState != DISABLE)
00625   {
00626     /* Enable Auto end mode */
00627     I2Cx->CR2 |= I2C_CR2_AUTOEND;
00628   }
00629   else
00630   {
00631     /* Disable Auto end mode */
00632     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_AUTOEND);
00633   }
00634 } 

void I2C_CalculatePEC ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C PEC calculation.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx PEC calculation. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 1107 of file stm32f30x_i2c.c.

01108 {
01109   /* Check the parameters */
01110   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01111   assert_param(IS_FUNCTIONAL_STATE(NewState));
01112   
01113   if (NewState != DISABLE)
01114   {
01115     /* Enable PEC calculation */
01116     I2Cx->CR1 |= I2C_CR1_PECEN;   
01117   }
01118   else
01119   {
01120     /* Disable PEC calculation */    
01121     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PECEN); 
01122   }
01123 }

void I2C_ClearFlag ( I2C_TypeDef *  I2Cx,
uint32_t  I2C_FLAG 
)

Clears the I2Cx's pending flags.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_FLAG,: specifies the flag to clear. This parameter can be any combination of the following values:

  • I2C_FLAG_ADDR: Address matched (slave mode)
  • I2C_FLAG_NACKF: NACK received flag
  • I2C_FLAG_STOPF: STOP detection flag
  • I2C_FLAG_BERR: Bus error
  • I2C_FLAG_ARLO: Arbitration lost
  • I2C_FLAG_OVR: Overrun/Underrun
  • I2C_FLAG_PECERR: PEC error in reception
  • I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag
  • I2C_FLAG_ALERT: SMBus Alert
Return values:
The new state of I2C_FLAG (SET or RESET).

Definition at line 1465 of file stm32f30x_i2c.c.

01466 { 
01467   /* Check the parameters */
01468   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01469   assert_param(IS_I2C_CLEAR_FLAG(I2C_FLAG));
01470 
01471   /* Clear the selected flag */
01472   I2Cx->ICR = I2C_FLAG;
01473   }

void I2C_ClearITPendingBit ( I2C_TypeDef *  I2Cx,
uint32_t  I2C_IT 
)

Clears the I2Cx's interrupt pending bits.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_IT,: specifies the interrupt pending bit to clear. This parameter can be any combination of the following values:

  • I2C_IT_ADDR: Address matched (slave mode)
  • I2C_IT_NACKF: NACK received flag
  • I2C_IT_STOPF: STOP detection flag
  • I2C_IT_BERR: Bus error
  • I2C_IT_ARLO: Arbitration lost
  • I2C_IT_OVR: Overrun/Underrun
  • I2C_IT_PECERR: PEC error in reception
  • I2C_IT_TIMEOUT: Timeout or Tlow detection flag
  • I2C_IT_ALERT: SMBus Alert
Return values:
The new state of I2C_IT (SET or RESET).

Definition at line 1559 of file stm32f30x_i2c.c.

01560 {
01561   /* Check the parameters */
01562   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01563   assert_param(IS_I2C_CLEAR_IT(I2C_IT));
01564 
01565   /* Clear the selected flag */
01566   I2Cx->ICR = I2C_IT;
01567 }

void I2C_ClockTimeoutCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C Clock Timeout (SCL Timeout detection).

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx clock Timeout. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 976 of file stm32f30x_i2c.c.

00977 {
00978   /* Check the parameters */
00979   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00980   assert_param(IS_FUNCTIONAL_STATE(NewState));
00981   
00982   if (NewState != DISABLE)
00983   {
00984     /* Enable Clock Timeout */
00985     I2Cx->TIMEOUTR |= I2C_TIMEOUTR_TIMOUTEN;   
00986   }
00987   else
00988   {
00989     /* Disable Clock Timeout */    
00990     I2Cx->TIMEOUTR &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIMOUTEN); 
00991   }
00992 }

void I2C_Cmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the specified I2C peripheral.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx peripheral. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 279 of file stm32f30x_i2c.c.

00280 {
00281   /* Check the parameters */
00282   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00283   assert_param(IS_FUNCTIONAL_STATE(NewState));
00284   if (NewState != DISABLE)
00285   {
00286     /* Enable the selected I2C peripheral */
00287     I2Cx->CR1 |= I2C_CR1_PE;
00288   }
00289   else
00290   {
00291     /* Disable the selected I2C peripheral */
00292     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PE);
00293   }
00294 }

void I2C_DeInit ( I2C_TypeDef *  I2Cx  ) 

Deinitializes the I2Cx peripheral registers to their default reset values.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Return values:
None 

Definition at line 145 of file stm32f30x_i2c.c.

00146 {
00147   /* Check the parameters */
00148   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00149 
00150   if (I2Cx == I2C1)
00151   {
00152     /* Enable I2C1 reset state */
00153     RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
00154     /* Release I2C1 from reset state */
00155     RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
00156   }
00157   else
00158   {
00159     /* Enable I2C2 reset state */
00160     RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
00161     /* Release I2C2 from reset state */
00162     RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
00163   }
00164 }

void I2C_DMACmd ( I2C_TypeDef *  I2Cx,
uint32_t  I2C_DMAReq,
FunctionalState  NewState 
)

Enables or disables the I2C DMA interface.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_DMAReq,: specifies the I2C DMA transfer request to be enabled or disabled. This parameter can be any combination of the following values:

  • I2C_DMAReq_Tx: Tx DMA transfer request
  • I2C_DMAReq_Rx: Rx DMA transfer request
NewState,: new state of the selected I2C DMA transfer request. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 1301 of file stm32f30x_i2c.c.

01302 {
01303   /* Check the parameters */
01304   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01305   assert_param(IS_FUNCTIONAL_STATE(NewState));
01306   assert_param(IS_I2C_DMA_REQ(I2C_DMAReq));
01307 
01308   if (NewState != DISABLE)
01309   {
01310     /* Enable the selected I2C DMA requests */
01311     I2Cx->CR1 |= I2C_DMAReq;
01312   }
01313   else
01314   {
01315     /* Disable the selected I2C DMA requests */
01316     I2Cx->CR1 &= (uint32_t)~I2C_DMAReq;
01317   }
01318 }

void I2C_DualAddressCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C own address 2.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C own address 2. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 410 of file stm32f30x_i2c.c.

00411 {
00412   /* Check the parameters */
00413   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00414   assert_param(IS_FUNCTIONAL_STATE(NewState));
00415   
00416   if (NewState != DISABLE)
00417   {
00418     /* Enable own address 2 */
00419     I2Cx->OAR2 |= I2C_OAR2_OA2EN;
00420   }
00421   else
00422   {
00423     /* Disable own address 2 */
00424     I2Cx->OAR2 &= (uint32_t)~((uint32_t)I2C_OAR2_OA2EN);
00425   }
00426 }    

void I2C_ExtendedClockTimeoutCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C Extended Clock Timeout (SCL cumulative Timeout detection).

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx Extended clock Timeout. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 1001 of file stm32f30x_i2c.c.

01002 {
01003   /* Check the parameters */
01004   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01005   assert_param(IS_FUNCTIONAL_STATE(NewState));
01006   
01007   if (NewState != DISABLE)
01008   {
01009     /* Enable Clock Timeout */
01010     I2Cx->TIMEOUTR |= I2C_TIMEOUTR_TEXTEN;   
01011   }
01012   else
01013   {
01014     /* Disable Clock Timeout */    
01015     I2Cx->TIMEOUTR &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TEXTEN); 
01016   }
01017 }

void I2C_GeneralCallCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C general call mode.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C general call mode. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 474 of file stm32f30x_i2c.c.

00475 {
00476   /* Check the parameters */
00477   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00478   assert_param(IS_FUNCTIONAL_STATE(NewState));
00479   
00480   if (NewState != DISABLE)
00481   {
00482     /* Enable general call mode */
00483     I2Cx->CR1 |= I2C_CR1_GCEN;
00484   }
00485   else
00486   {
00487     /* Disable general call mode */
00488     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_GCEN);
00489   }
00490 } 

void I2C_GenerateSTART ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Generates I2Cx communication START condition.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C START condition generation. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 722 of file stm32f30x_i2c.c.

00723 {
00724   /* Check the parameters */
00725   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00726   assert_param(IS_FUNCTIONAL_STATE(NewState));
00727   
00728   if (NewState != DISABLE)
00729   {
00730     /* Generate a START condition */
00731     I2Cx->CR2 |= I2C_CR2_START;
00732   }
00733   else
00734   {
00735     /* Disable the START condition generation */
00736     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_START);
00737   }
00738 }  

void I2C_GenerateSTOP ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Generates I2Cx communication STOP condition.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C STOP condition generation. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 747 of file stm32f30x_i2c.c.

00748 {
00749   /* Check the parameters */
00750   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00751   assert_param(IS_FUNCTIONAL_STATE(NewState));
00752   
00753   if (NewState != DISABLE)
00754   {
00755     /* Generate a STOP condition */
00756     I2Cx->CR2 |= I2C_CR2_STOP;
00757   }
00758   else
00759   {
00760     /* Disable the STOP condition generation */
00761     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_STOP);
00762   }
00763 }  

uint8_t I2C_GetAddressMatched ( I2C_TypeDef *  I2Cx  ) 

Returns the I2C slave matched address .

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Return values:
The value of the slave matched address .

Definition at line 822 of file stm32f30x_i2c.c.

00823 {
00824   /* Check the parameters */
00825   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00826   
00827   /* Return the slave matched address in the SR1 register */
00828   return (uint8_t)(((uint32_t)I2Cx->ISR & I2C_ISR_ADDCODE) >> 16) ;
00829 }

FlagStatus I2C_GetFlagStatus ( I2C_TypeDef *  I2Cx,
uint32_t  I2C_FLAG 
)

Checks whether the specified I2C flag is set or not.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_FLAG,: specifies the flag to check. This parameter can be one of the following values:

  • I2C_FLAG_TXE: Transmit data register empty
  • I2C_FLAG_TXIS: Transmit interrupt status
  • I2C_FLAG_RXNE: Receive data register not empty
  • I2C_FLAG_ADDR: Address matched (slave mode)
  • I2C_FLAG_NACKF: NACK received flag
  • I2C_FLAG_STOPF: STOP detection flag
  • I2C_FLAG_TC: Transfer complete (master mode)
  • I2C_FLAG_TCR: Transfer complete reload
  • I2C_FLAG_BERR: Bus error
  • I2C_FLAG_ARLO: Arbitration lost
  • I2C_FLAG_OVR: Overrun/Underrun
  • I2C_FLAG_PECERR: PEC error in reception
  • I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag
  • I2C_FLAG_ALERT: SMBus Alert
  • I2C_FLAG_BUSY: Bus busy
Return values:
The new state of I2C_FLAG (SET or RESET).

Definition at line 1421 of file stm32f30x_i2c.c.

01422 {
01423   uint32_t tmpreg = 0;
01424   FlagStatus bitstatus = RESET;
01425   
01426   /* Check the parameters */
01427   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01428   assert_param(IS_I2C_GET_FLAG(I2C_FLAG));
01429   
01430   /* Get the ISR register value */
01431   tmpreg = I2Cx->ISR;
01432   
01433   /* Get flag status */
01434   tmpreg &= I2C_FLAG;
01435   
01436   if(tmpreg != 0)
01437   {
01438     /* I2C_FLAG is set */
01439     bitstatus = SET;
01440   }
01441   else
01442   {
01443     /* I2C_FLAG is reset */
01444     bitstatus = RESET;
01445   }
01446   return bitstatus;
01447 }  

ITStatus I2C_GetITStatus ( I2C_TypeDef *  I2Cx,
uint32_t  I2C_IT 
)

Checks whether the specified I2C interrupt has occurred or not.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_IT,: specifies the interrupt source to check. This parameter can be one of the following values:

  • I2C_IT_TXIS: Transmit interrupt status
  • I2C_IT_RXNE: Receive data register not empty
  • I2C_IT_ADDR: Address matched (slave mode)
  • I2C_IT_NACKF: NACK received flag
  • I2C_IT_STOPF: STOP detection flag
  • I2C_IT_TC: Transfer complete (master mode)
  • I2C_IT_TCR: Transfer complete reload
  • I2C_IT_BERR: Bus error
  • I2C_IT_ARLO: Arbitration lost
  • I2C_IT_OVR: Overrun/Underrun
  • I2C_IT_PECERR: PEC error in reception
  • I2C_IT_TIMEOUT: Timeout or Tlow detection flag
  • I2C_IT_ALERT: SMBus Alert
Return values:
The new state of I2C_IT (SET or RESET).

Definition at line 1495 of file stm32f30x_i2c.c.

01496 {
01497   uint32_t tmpreg = 0;
01498   ITStatus bitstatus = RESET;
01499   uint32_t enablestatus = 0;
01500 
01501   /* Check the parameters */
01502   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01503   assert_param(IS_I2C_GET_IT(I2C_IT));
01504 
01505   /* Check if the interrupt source is enabled or not */
01506   /* If Error interrupt */
01507   if((uint32_t)(I2C_IT & ERROR_IT_MASK))
01508   {
01509     enablestatus = (uint32_t)((I2C_CR1_ERRIE) & (I2Cx->CR1));
01510   }
01511   /* If TC interrupt */
01512   else if((uint32_t)(I2C_IT & TC_IT_MASK))
01513   {
01514     enablestatus = (uint32_t)((I2C_CR1_TCIE) & (I2Cx->CR1));
01515   }
01516   else
01517   {
01518     enablestatus = (uint32_t)((I2C_IT) & (I2Cx->CR1));
01519   }
01520   
01521   /* Get the ISR register value */
01522   tmpreg = I2Cx->ISR;
01523 
01524   /* Get flag status */
01525   tmpreg &= I2C_IT;
01526 
01527   /* Check the status of the specified I2C flag */
01528   if((tmpreg != RESET) && enablestatus)
01529   {
01530     /* I2C_IT is set */
01531     bitstatus = SET;
01532   }
01533   else
01534   {
01535     /* I2C_IT is reset */
01536     bitstatus = RESET;
01537   }
01538 
01539   /* Return the I2C_IT status */
01540   return bitstatus;
01541 }

uint8_t I2C_GetPEC ( I2C_TypeDef *  I2Cx  ) 

Returns the I2C PEC.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Return values:
The value of the PEC .

Definition at line 1155 of file stm32f30x_i2c.c.

01156 {
01157   /* Check the parameters */
01158   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01159   
01160   /* Return the slave matched address in the SR1 register */
01161   return (uint8_t)((uint32_t)I2Cx->PECR & I2C_PECR_PEC);
01162 }

uint16_t I2C_GetTransferDirection ( I2C_TypeDef *  I2Cx  ) 

Returns the I2C slave received request.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Return values:
The value of the received request.

Definition at line 836 of file stm32f30x_i2c.c.

00837 {
00838   uint32_t tmpreg = 0;
00839   uint16_t direction = 0;
00840   
00841   /* Check the parameters */
00842   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00843   
00844   /* Return the slave matched address in the SR1 register */
00845   tmpreg = (uint32_t)(I2Cx->ISR & I2C_ISR_DIR);
00846   
00847   /* If write transfer is requested */
00848   if (tmpreg == 0)
00849   {
00850     /* write transfer is requested */
00851     direction = I2C_Direction_Transmitter;
00852   }
00853   else
00854   {
00855     /* Read transfer is requested */
00856     direction = I2C_Direction_Receiver;
00857   }  
00858   return direction;
00859 }

void I2C_IdleClockTimeoutCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C Idle Clock Timeout (Bus idle SCL and SDA high detection).

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx Idle clock Timeout. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 1027 of file stm32f30x_i2c.c.

01028 {
01029   /* Check the parameters */
01030   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01031   assert_param(IS_FUNCTIONAL_STATE(NewState));
01032   
01033   if (NewState != DISABLE)
01034   {
01035     /* Enable Clock Timeout */
01036     I2Cx->TIMEOUTR |= I2C_TIMEOUTR_TIDLE;   
01037   }
01038   else
01039   {
01040     /* Disable Clock Timeout */    
01041     I2Cx->TIMEOUTR &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIDLE); 
01042   }
01043 }

void I2C_Init ( I2C_TypeDef *  I2Cx,
I2C_InitTypeDef I2C_InitStruct 
)

Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_InitStruct,: pointer to a I2C_InitTypeDef structure that contains the configuration information for the specified I2C peripheral.
Return values:
None 

Definition at line 174 of file stm32f30x_i2c.c.

00175 {
00176   uint32_t tmpreg = 0;
00177 
00178   /* Check the parameters */
00179   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00180   assert_param(IS_I2C_ANALOG_FILTER(I2C_InitStruct->I2C_AnalogFilter));
00181   assert_param(IS_I2C_DIGITAL_FILTER(I2C_InitStruct->I2C_DigitalFilter));
00182   assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
00183   assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
00184   assert_param(IS_I2C_ACK(I2C_InitStruct->I2C_Ack));
00185   assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));
00186 
00187   /* Disable I2Cx Peripheral */
00188   I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PE);
00189 
00190   /*---------------------------- I2Cx FILTERS Configuration ------------------*/
00191   /* Get the I2Cx CR1 value */
00192   tmpreg = I2Cx->CR1;
00193   /* Clear I2Cx CR1 register */
00194   tmpreg &= CR1_CLEAR_MASK;
00195   /* Configure I2Cx: analog and digital filter */
00196   /* Set ANFOFF bit according to I2C_AnalogFilter value */
00197   /* Set DFN bits according to I2C_DigitalFilter value */
00198   tmpreg |= (uint32_t)I2C_InitStruct->I2C_AnalogFilter |(I2C_InitStruct->I2C_DigitalFilter << 8);
00199   
00200   /* Write to I2Cx CR1 */
00201   I2Cx->CR1 = tmpreg;
00202 
00203   /*---------------------------- I2Cx TIMING Configuration -------------------*/
00204   /* Configure I2Cx: Timing */
00205   /* Set TIMINGR bits according to I2C_Timing */
00206   /* Write to I2Cx TIMING */
00207   I2Cx->TIMINGR = I2C_InitStruct->I2C_Timing & TIMING_CLEAR_MASK;
00208 
00209   /* Enable I2Cx Peripheral */
00210   I2Cx->CR1 |= I2C_CR1_PE;
00211 
00212   /*---------------------------- I2Cx OAR1 Configuration ---------------------*/
00213   /* Clear tmpreg local variable */
00214   tmpreg = 0;
00215   /* Clear OAR1 register */
00216   I2Cx->OAR1 = (uint32_t)tmpreg;
00217   /* Clear OAR2 register */
00218   I2Cx->OAR2 = (uint32_t)tmpreg;
00219   /* Configure I2Cx: Own Address1 and acknowledged address */
00220   /* Set OA1MODE bit according to I2C_AcknowledgedAddress value */
00221   /* Set OA1 bits according to I2C_OwnAddress1 value */
00222   tmpreg = (uint32_t)((uint32_t)I2C_InitStruct->I2C_AcknowledgedAddress | \
00223                       (uint32_t)I2C_InitStruct->I2C_OwnAddress1);
00224   /* Write to I2Cx OAR1 */
00225   I2Cx->OAR1 = tmpreg;
00226   /* Enable Own Address1 acknowledgement */
00227   I2Cx->OAR1 |= I2C_OAR1_OA1EN;
00228 
00229   /*---------------------------- I2Cx MODE Configuration ---------------------*/
00230   /* Configure I2Cx: mode */
00231   /* Set SMBDEN and SMBHEN bits according to I2C_Mode value */
00232   tmpreg = I2C_InitStruct->I2C_Mode;
00233   /* Write to I2Cx CR1 */
00234   I2Cx->CR1 |= tmpreg;
00235 
00236   /*---------------------------- I2Cx ACK Configuration ----------------------*/
00237   /* Get the I2Cx CR2 value */
00238   tmpreg = I2Cx->CR2;
00239   /* Clear I2Cx CR2 register */
00240   tmpreg &= CR2_CLEAR_MASK;
00241   /* Configure I2Cx: acknowledgement */
00242   /* Set NACK bit according to I2C_Ack value */
00243   tmpreg |= I2C_InitStruct->I2C_Ack;
00244   /* Write to I2Cx CR2 */
00245   I2Cx->CR2 = tmpreg;
00246 }

void I2C_ITConfig ( I2C_TypeDef *  I2Cx,
uint32_t  I2C_IT,
FunctionalState  NewState 
)

Enables or disables the specified I2C interrupts.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_IT,: specifies the I2C interrupts sources to be enabled or disabled. This parameter can be any combination of the following values:

  • I2C_IT_ERRI: Error interrupt mask
  • I2C_IT_TCI: Transfer Complete interrupt mask
  • I2C_IT_STOPI: Stop Detection interrupt mask
  • I2C_IT_NACKI: Not Acknowledge received interrupt mask
  • I2C_IT_ADDRI: Address Match interrupt mask
  • I2C_IT_RXI: RX interrupt mask
  • I2C_IT_TXI: TX interrupt mask
NewState,: new state of the specified I2C interrupts. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 334 of file stm32f30x_i2c.c.

00335 {
00336   /* Check the parameters */
00337   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00338   assert_param(IS_FUNCTIONAL_STATE(NewState));
00339   assert_param(IS_I2C_CONFIG_IT(I2C_IT));
00340   
00341   if (NewState != DISABLE)
00342   {
00343     /* Enable the selected I2C interrupts */
00344     I2Cx->CR1 |= I2C_IT;
00345   }
00346   else
00347   {
00348     /* Disable the selected I2C interrupts */
00349     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_IT);
00350   }
00351 }

void I2C_MasterRequestConfig ( I2C_TypeDef *  I2Cx,
uint16_t  I2C_Direction 
)

Configures the type of transfer request for the master.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_Direction,: specifies the transfer request direction to be programmed. This parameter can be one of the following values:

  • I2C_Direction_Transmitter: Master request a write transfer
  • I2C_Direction_Receiver: Master request a read transfer
Return values:
None 

Definition at line 696 of file stm32f30x_i2c.c.

00697 {
00698 /* Check the parameters */
00699   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00700   assert_param(IS_I2C_DIRECTION(I2C_Direction));
00701   
00702   /* Test on the direction to set/reset the read/write bit */
00703   if (I2C_Direction == I2C_Direction_Transmitter)
00704   {
00705     /* Request a write Transfer */
00706     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_RD_WRN);
00707   }
00708   else
00709   {
00710     /* Request a read Transfer */
00711     I2Cx->CR2 |= I2C_CR2_RD_WRN;
00712   }
00713 }  

void I2C_NumberOfBytesConfig ( I2C_TypeDef *  I2Cx,
uint8_t  Number_Bytes 
)

Configures the number of bytes to be transmitted/received.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Number_Bytes,: specifies the number of bytes to be programmed.
Return values:
None 

Definition at line 667 of file stm32f30x_i2c.c.

00668 {
00669   uint32_t tmpreg = 0;
00670 
00671   /* Check the parameters */
00672   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00673 
00674   /* Get the old register value */
00675   tmpreg = I2Cx->CR2;
00676 
00677   /* Reset I2Cx Nbytes bit [7:0] */
00678   tmpreg &= (uint32_t)~((uint32_t)I2C_CR2_NBYTES);
00679 
00680   /* Set I2Cx Nbytes */
00681   tmpreg |= (uint32_t)(((uint32_t)Number_Bytes << 16 ) & I2C_CR2_NBYTES);
00682 
00683   /* Store the new register value */
00684   I2Cx->CR2 = tmpreg;
00685 }  

void I2C_OwnAddress2Config ( I2C_TypeDef *  I2Cx,
uint16_t  Address,
uint8_t  Mask 
)

Configures the I2C slave own address 2 and mask.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Address,: specifies the slave address to be programmed.
Mask,: specifies own address 2 mask to be programmed. This parameter can be one of the following values:

  • I2C_OA2_NoMask: no mask.
  • I2C_OA2_Mask01: OA2[1] is masked and don't care.
  • I2C_OA2_Mask02: OA2[2:1] are masked and don't care.
  • I2C_OA2_Mask03: OA2[3:1] are masked and don't care.
  • I2C_OA2_Mask04: OA2[4:1] are masked and don't care.
  • I2C_OA2_Mask05: OA2[5:1] are masked and don't care.
  • I2C_OA2_Mask06: OA2[6:1] are masked and don't care.
  • I2C_OA2_Mask07: OA2[7:1] are masked and don't care.
Return values:
None 

Definition at line 444 of file stm32f30x_i2c.c.

00445 {
00446   uint32_t tmpreg = 0;
00447 
00448   /* Check the parameters */
00449   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00450   assert_param(IS_I2C_OWN_ADDRESS2(Address));
00451   assert_param(IS_I2C_OWN_ADDRESS2_MASK(Mask));
00452   
00453   /* Get the old register value */
00454   tmpreg = I2Cx->OAR2;
00455 
00456   /* Reset I2Cx OA2 bit [7:1] and OA2MSK bit [1:0]  */
00457   tmpreg &= (uint32_t)~((uint32_t)(I2C_OAR2_OA2 | I2C_OAR2_OA2MSK));
00458 
00459   /* Set I2Cx SADD */
00460   tmpreg |= (uint32_t)(((uint32_t)Address & I2C_OAR2_OA2) | \
00461             (((uint32_t)Mask << 8) & I2C_OAR2_OA2MSK)) ;
00462 
00463   /* Store the new register value */
00464   I2Cx->OAR2 = tmpreg;
00465 }

void I2C_PECRequestCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C PEC transmission/reception request.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx PEC request. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 1132 of file stm32f30x_i2c.c.

01133 {
01134   /* Check the parameters */
01135   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01136   assert_param(IS_FUNCTIONAL_STATE(NewState));
01137   
01138   if (NewState != DISABLE)
01139   {
01140     /* Enable PEC transmission/reception request */
01141     I2Cx->CR1 |= I2C_CR2_PECBYTE;   
01142   }
01143   else
01144   {
01145     /* Disable PEC transmission/reception request */    
01146     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR2_PECBYTE); 
01147   }
01148 }

uint32_t I2C_ReadRegister ( I2C_TypeDef *  I2Cx,
uint8_t  I2C_Register 
)

Reads the specified I2C register and returns its value.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
I2C_Register,: specifies the register to read. This parameter can be one of the following values:

  • I2C_Register_CR1: CR1 register.
  • I2C_Register_CR2: CR2 register.
  • I2C_Register_OAR1: OAR1 register.
  • I2C_Register_OAR2: OAR2 register.
  • I2C_Register_TIMINGR: TIMING register.
  • I2C_Register_TIMEOUTR: TIMEOUTR register.
  • I2C_Register_ISR: ISR register.
  • I2C_Register_ICR: ICR register.
  • I2C_Register_PECR: PECR register.
  • I2C_Register_RXDR: RXDR register.
  • I2C_Register_TXDR: TXDR register.
Return values:
The value of the read register.

Definition at line 1201 of file stm32f30x_i2c.c.

01202 {
01203   __IO uint32_t tmp = 0;
01204 
01205   /* Check the parameters */
01206   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01207   assert_param(IS_I2C_REGISTER(I2C_Register));
01208 
01209   tmp = (uint32_t)I2Cx;
01210   tmp += I2C_Register;
01211 
01212   /* Return the selected register value */
01213   return (*(__IO uint32_t *) tmp);
01214 }

uint8_t I2C_ReceiveData ( I2C_TypeDef *  I2Cx  ) 

Returns the most recent received data by the I2Cx peripheral.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Return values:
The value of the received data.

Definition at line 1258 of file stm32f30x_i2c.c.

01259 {
01260   /* Check the parameters */
01261   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01262   
01263   /* Return the data in the DR register */
01264   return (uint8_t)I2Cx->RXDR;
01265 }  

void I2C_ReloadCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C nbytes reload mode.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the nbytes reload mode. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 643 of file stm32f30x_i2c.c.

00644 {
00645   /* Check the parameters */
00646   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00647   assert_param(IS_FUNCTIONAL_STATE(NewState));
00648   
00649   if (NewState != DISABLE)
00650   {
00651     /* Enable Auto Reload mode */
00652     I2Cx->CR2 |= I2C_CR2_RELOAD;
00653   }
00654   else
00655   {
00656     /* Disable Auto Reload mode */
00657     I2Cx->CR2 &= (uint32_t)~((uint32_t)I2C_CR2_RELOAD);
00658   }
00659 }

void I2C_SendData ( I2C_TypeDef *  I2Cx,
uint8_t  Data 
)

Sends a data byte through the I2Cx peripheral.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Data,: Byte to be transmitted..
Return values:
None 

Definition at line 1244 of file stm32f30x_i2c.c.

01245 {
01246   /* Check the parameters */
01247   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01248   
01249   /* Write in the DR register the data to be sent */
01250   I2Cx->TXDR = (uint8_t)Data;
01251 }

void I2C_SlaveAddressConfig ( I2C_TypeDef *  I2Cx,
uint16_t  Address 
)

Configures the slave address to be transmitted after start generation.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Address,: specifies the slave address to be programmed.
Note:
This function should be called before generating start condition.
Return values:
None 

Definition at line 524 of file stm32f30x_i2c.c.

00525 {
00526   uint32_t tmpreg = 0;
00527 
00528   /* Check the parameters */
00529   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00530   assert_param(IS_I2C_SLAVE_ADDRESS(Address));
00531                
00532   /* Get the old register value */
00533   tmpreg = I2Cx->CR2;
00534 
00535   /* Reset I2Cx SADD bit [9:0] */
00536   tmpreg &= (uint32_t)~((uint32_t)I2C_CR2_SADD);
00537 
00538   /* Set I2Cx SADD */
00539   tmpreg |= (uint32_t)((uint32_t)Address & I2C_CR2_SADD);
00540 
00541   /* Store the new register value */
00542   I2Cx->CR2 = tmpreg;
00543 }

void I2C_SlaveByteControlCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C slave byte control.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2C slave byte control. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 499 of file stm32f30x_i2c.c.

00500 {
00501   /* Check the parameters */
00502   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00503   assert_param(IS_FUNCTIONAL_STATE(NewState));
00504   
00505   if (NewState != DISABLE)
00506   {
00507     /* Enable slave byte control */
00508     I2Cx->CR1 |= I2C_CR1_SBC;
00509   }
00510   else
00511   {
00512     /* Disable slave byte control */
00513     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_SBC);
00514   }
00515 }

void I2C_SMBusAlertCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C SMBus alert.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx SMBus alert. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 951 of file stm32f30x_i2c.c.

00952 {
00953   /* Check the parameters */
00954   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00955   assert_param(IS_FUNCTIONAL_STATE(NewState));
00956   
00957   if (NewState != DISABLE)
00958   {
00959     /* Enable SMBus alert */
00960     I2Cx->CR1 |= I2C_CR1_ALERTEN;   
00961   }
00962   else
00963   {
00964     /* Disable SMBus alert */    
00965     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_ALERTEN); 
00966   }
00967 }

void I2C_SoftwareResetCmd ( I2C_TypeDef *  I2Cx  ) 

Enables or disables the specified I2C software reset.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Return values:
None 

Definition at line 302 of file stm32f30x_i2c.c.

00303 {
00304   /* Check the parameters */
00305   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00306 
00307   /* Disable peripheral */
00308   I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_PE);
00309 
00310   /* Perform a dummy read to delay the disable of peripheral for minimum
00311      3 APB clock cycles to perform the software reset functionality */
00312   *(__IO uint32_t *)(uint32_t)I2Cx; 
00313 
00314   /* Enable peripheral */
00315   I2Cx->CR1 |= I2C_CR1_PE;
00316 }

void I2C_StopModeCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables I2C wakeup from stop mode.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx stop mode. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 385 of file stm32f30x_i2c.c.

00386 {
00387   /* Check the parameters */
00388   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00389   assert_param(IS_FUNCTIONAL_STATE(NewState));
00390   
00391   if (NewState != DISABLE)
00392   {
00393     /* Enable wakeup from stop mode */
00394     I2Cx->CR1 |= I2C_CR1_WUPEN;   
00395   }
00396   else
00397   {
00398     /* Disable wakeup from stop mode */    
00399     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_WUPEN); 
00400   }
00401 }

void I2C_StretchClockCmd ( I2C_TypeDef *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the I2C Clock stretching.

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
NewState,: new state of the I2Cx Clock stretching. This parameter can be: ENABLE or DISABLE.
Return values:
None 

Definition at line 360 of file stm32f30x_i2c.c.

00361 {
00362   /* Check the parameters */
00363   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00364   assert_param(IS_FUNCTIONAL_STATE(NewState));
00365   
00366   if (NewState != DISABLE)
00367   {
00368     /* Enable clock stretching */
00369     I2Cx->CR1 &= (uint32_t)~((uint32_t)I2C_CR1_NOSTRETCH);    
00370   }
00371   else
00372   {
00373     /* Disable clock stretching  */
00374     I2Cx->CR1 |= I2C_CR1_NOSTRETCH;
00375   }
00376 }

void I2C_StructInit ( I2C_InitTypeDef I2C_InitStruct  ) 

Fills each I2C_InitStruct member with its default value.

Parameters:
I2C_InitStruct,: pointer to an I2C_InitTypeDef structure which will be initialized.
Return values:
None 

Definition at line 253 of file stm32f30x_i2c.c.

00254 {
00255   /*---------------- Reset I2C init structure parameters values --------------*/
00256   /* Initialize the I2C_Timing member */
00257   I2C_InitStruct->I2C_Timing = 0;
00258   /* Initialize the I2C_AnalogFilter member */
00259   I2C_InitStruct->I2C_AnalogFilter = I2C_AnalogFilter_Enable;
00260   /* Initialize the I2C_DigitalFilter member */
00261   I2C_InitStruct->I2C_DigitalFilter = 0;
00262   /* Initialize the I2C_Mode member */
00263   I2C_InitStruct->I2C_Mode = I2C_Mode_I2C;
00264   /* Initialize the I2C_OwnAddress1 member */
00265   I2C_InitStruct->I2C_OwnAddress1 = 0;
00266   /* Initialize the I2C_Ack member */
00267   I2C_InitStruct->I2C_Ack = I2C_Ack_Disable;
00268   /* Initialize the I2C_AcknowledgedAddress member */
00269   I2C_InitStruct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
00270 }

void I2C_TimeoutAConfig ( I2C_TypeDef *  I2Cx,
uint16_t  Timeout 
)

Configures the I2C Bus Timeout A (SCL Timeout when TIDLE = 0 or Bus idle SCL and SDA high when TIDLE = 1).

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Timeout,: specifies the TimeoutA to be programmed.
Return values:
None 

Definition at line 1052 of file stm32f30x_i2c.c.

01053 {
01054   uint32_t tmpreg = 0;
01055 
01056   /* Check the parameters */
01057   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01058   assert_param(IS_I2C_TIMEOUT(Timeout));
01059     
01060   /* Get the old register value */
01061   tmpreg = I2Cx->TIMEOUTR;
01062 
01063   /* Reset I2Cx TIMEOUTA bit [11:0] */
01064   tmpreg &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIMEOUTA);
01065 
01066   /* Set I2Cx TIMEOUTA */
01067   tmpreg |= (uint32_t)((uint32_t)Timeout & I2C_TIMEOUTR_TIMEOUTA) ;
01068 
01069   /* Store the new register value */
01070   I2Cx->TIMEOUTR = tmpreg;
01071 }

void I2C_TimeoutBConfig ( I2C_TypeDef *  I2Cx,
uint16_t  Timeout 
)

Configures the I2C Bus Timeout B (SCL cumulative Timeout).

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Timeout,: specifies the TimeoutB to be programmed.
Return values:
None 

Definition at line 1079 of file stm32f30x_i2c.c.

01080 {
01081   uint32_t tmpreg = 0;
01082 
01083   /* Check the parameters */
01084   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
01085   assert_param(IS_I2C_TIMEOUT(Timeout));
01086 
01087   /* Get the old register value */
01088   tmpreg = I2Cx->TIMEOUTR;
01089 
01090   /* Reset I2Cx TIMEOUTB bit [11:0] */
01091   tmpreg &= (uint32_t)~((uint32_t)I2C_TIMEOUTR_TIMEOUTB);
01092 
01093   /* Set I2Cx TIMEOUTB */
01094   tmpreg |= (uint32_t)(((uint32_t)Timeout << 16) & I2C_TIMEOUTR_TIMEOUTB) ;
01095 
01096   /* Store the new register value */
01097   I2Cx->TIMEOUTR = tmpreg;
01098 }

void I2C_TransferHandling ( I2C_TypeDef *  I2Cx,
uint16_t  Address,
uint8_t  Number_Bytes,
uint32_t  ReloadEndMode,
uint32_t  StartStopMode 
)

Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set).

Parameters:
I2Cx,: where x can be 1 or 2 to select the I2C peripheral.
Address,: specifies the slave address to be programmed.
Number_Bytes,: specifies the number of bytes to be programmed. This parameter must be a value between 0 and 255.
ReloadEndMode,: new state of the I2C START condition generation. This parameter can be one of the following values:

  • I2C_Reload_Mode: Enable Reload mode .
  • I2C_AutoEnd_Mode: Enable Automatic end mode.
  • I2C_SoftEnd_Mode: Enable Software end mode.
StartStopMode,: new state of the I2C START condition generation. This parameter can be one of the following values:

  • I2C_No_StartStop: Don't Generate stop and start condition.
  • I2C_Generate_Stop: Generate stop condition (Number_Bytes should be set to 0).
  • I2C_Generate_Start_Read: Generate Restart for read request.
  • I2C_Generate_Start_Write: Generate Restart for write request.
Return values:
None 

Definition at line 880 of file stm32f30x_i2c.c.

00881 {
00882   uint32_t tmpreg = 0;
00883   
00884   /* Check the parameters */
00885   assert_param(IS_I2C_ALL_PERIPH(I2Cx));
00886   assert_param(IS_I2C_SLAVE_ADDRESS(Address));  
00887   assert_param(IS_RELOAD_END_MODE(ReloadEndMode));
00888   assert_param(IS_START_STOP_MODE(StartStopMode));
00889     
00890   /* Get the CR2 register value */
00891   tmpreg = I2Cx->CR2;
00892   
00893   /* clear tmpreg specific bits */
00894   tmpreg &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP));
00895   
00896   /* update tmpreg */
00897   tmpreg |= (uint32_t)(((uint32_t)Address & I2C_CR2_SADD) | (((uint32_t)Number_Bytes << 16 ) & I2C_CR2_NBYTES) | \
00898             (uint32_t)ReloadEndMode | (uint32_t)StartStopMode);
00899   
00900   /* update CR2 register */
00901   I2Cx->CR2 = tmpreg;  
00902 }  

 All Classes Files Functions Variables Enumerations Enumerator Defines

Generated on 12 Dec 2012 for f3dox by  doxygen 1.6.1