亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? stm32l1xx_i2c.c

?? VS1003_MP3_SPI_SDHC_FAT32
?? C
?? 第 1 頁(yè) / 共 4 頁(yè)
字號(hào):
/**
  ******************************************************************************
  * @file    stm32l1xx_i2c.c
  * @author  MCD Application Team
  * @version V1.1.0
  * @date    24-January-2012
  * @brief   This file provides firmware functions to manage the following 
  *          functionalities of the Inter-integrated circuit (I2C)
  *           + Initialization and Configuration
  *           + Data transfers
  *           + PEC management
  *           + DMA transfers management
  *           + Interrupts, events and flags management 
  *           
  *  @verbatim
  *    
  * ============================================================================
  *                    ##### How to use this driver #####
  * ============================================================================
   [..]
   (#) Enable peripheral clock using RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2Cx, ENABLE)
       function for I2C1 or I2C2.
   (#) Enable SDA, SCL  and SMBA (when used) GPIO clocks using 
       RCC_AHBPeriphClockCmd() function. 
   (#) Peripherals alternate function: 
       (++) Connect the pin to the desired peripherals' Alternate 
            Function (AF) using GPIO_PinAFConfig() function.
       (++) Configure the desired pin in alternate function by:
            GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
       (++) Select the type, pull-up/pull-down and output speed via 
            GPIO_PuPd, GPIO_OType and GPIO_Speed members
       (++) Call GPIO_Init() function.
   (#) Program the Mode, duty cycle , Own address, Ack, Speed and Acknowledged
       Address using the I2C_Init() function.
   (#) Optionally you can enable/configure the following parameters without
       re-initialization (i.e there is no need to call again I2C_Init() function):
       (++) Enable the acknowledge feature using I2C_AcknowledgeConfig() function.
       (++) Enable the dual addressing mode using I2C_DualAddressCmd() function.
       (++) Enable the general call using the I2C_GeneralCallCmd() function.
       (++) Enable the clock stretching using I2C_StretchClockCmd() function.
       (++) Enable the fast mode duty cycle using the I2C_FastModeDutyCycleConfig()
            function.
       (++) Enable the PEC Calculation using I2C_CalculatePEC() function.
       (++) For SMBus Mode: 
            (+++) Enable the Address Resolution Protocol (ARP) using I2C_ARPCmd() function.
            (+++) Configure the SMBusAlert pin using I2C_SMBusAlertConfig() function.
   (#) Enable the NVIC and the corresponding interrupt using the function
       I2C_ITConfig() if you need to use interrupt mode.
   (#) When using the DMA mode 
      (++) Configure the DMA using DMA_Init() function.
      (++) Active the needed channel Request using I2C_DMACmd() or
           I2C_DMALastTransferCmd() function.
   (#) Enable the I2C using the I2C_Cmd() function.
   (#) Enable the DMA using the DMA_Cmd() function when using DMA mode in the 
       transfers. 
    @endverbatim
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * FOR MORE INFORMATION PLEASE READ CAREFULLY THE LICENSE AGREEMENT FILE
  * LOCATED IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
  *
  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32l1xx_i2c.h"
#include "stm32l1xx_rcc.h"


/** @addtogroup STM32L1xx_StdPeriph_Driver
  * @{
  */

/** @defgroup I2C 
  * @brief I2C driver modules
  * @{
  */ 

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/

#define CR1_CLEAR_MASK          ((uint16_t)0xFBF5)      /*<! I2C registers Masks */
#define FLAG_MASK               ((uint32_t)0x00FFFFFF)  /*<! I2C FLAG mask */
#define ITEN_MASK               ((uint32_t)0x07000000)  /*<! I2C Interrupt Enable mask */

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup I2C_Private_Functions
  * @{
  */

/** @defgroup I2C_Group1 Initialization and Configuration functions
 *  @brief   Initialization and Configuration functions 
 *
@verbatim
 ===============================================================================
            ##### Initialization and Configuration functions #####
 ===============================================================================

@endverbatim
  * @{
  */

/**
  * @brief  Deinitializes the I2Cx peripheral registers to their default reset values.
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @retval None
  */
void I2C_DeInit(I2C_TypeDef* I2Cx)
{
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));

  if (I2Cx == I2C1)
  {
    /* Enable I2C1 reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
    /* Release I2C1 from reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
  }
  else
  {
    /* Enable I2C2 reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
    /* Release I2C2 from reset state */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
  }
}

/**
  * @brief  Initializes the I2Cx peripheral according to the specified 
  *         parameters in the I2C_InitStruct.
  * @note   To use the I2C at 400 KHz (in fast mode), the PCLK1 frequency 
  *         (I2C peripheral input clock) must be a multiple of 10 MHz.  
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @param  I2C_InitStruct: pointer to a I2C_InitTypeDef structure that
  *   contains the configuration information for the specified I2C peripheral.
  * @retval None
  */
void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct)
{
  uint16_t tmpreg = 0, freqrange = 0;
  uint16_t result = 0x04;
  uint32_t pclk1 = 8000000;
  RCC_ClocksTypeDef  rcc_clocks;
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_I2C_CLOCK_SPEED(I2C_InitStruct->I2C_ClockSpeed));
  assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
  assert_param(IS_I2C_DUTY_CYCLE(I2C_InitStruct->I2C_DutyCycle));
  assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
  assert_param(IS_I2C_ACK_STATE(I2C_InitStruct->I2C_Ack));
  assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));

/*---------------------------- I2Cx CR2 Configuration ------------------------*/
  /* Get the I2Cx CR2 value */
  tmpreg = I2Cx->CR2;
  /* Clear frequency FREQ[5:0] bits */
  tmpreg &= (uint16_t)~((uint16_t)I2C_CR2_FREQ);
  /* Get pclk1 frequency value */
  RCC_GetClocksFreq(&rcc_clocks);
  pclk1 = rcc_clocks.PCLK1_Frequency;
  /* Set frequency bits depending on pclk1 value */
  freqrange = (uint16_t)(pclk1 / 1000000);
  tmpreg |= freqrange;
  /* Write to I2Cx CR2 */
  I2Cx->CR2 = tmpreg;

/*---------------------------- I2Cx CCR Configuration ------------------------*/
  /* Disable the selected I2C peripheral to configure TRISE */
  I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_PE);
  /* Reset tmpreg value */
  /* Clear F/S, DUTY and CCR[11:0] bits */
  tmpreg = 0;

  /* Configure speed in standard mode */
  if (I2C_InitStruct->I2C_ClockSpeed <= 100000)
  {
    /* Standard mode speed calculate */
    result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed << 1));
    /* Test if CCR value is under 0x4*/
    if (result < 0x04)
    {
      /* Set minimum allowed value */
      result = 0x04;  
    }
    /* Set speed value for standard mode */
    tmpreg |= result;	  
    /* Set Maximum Rise Time for standard mode */
    I2Cx->TRISE = freqrange + 1; 
  }
  /* Configure speed in fast mode */
  /* To use the I2C at 400 KHz (in fast mode), the PCLK1 frequency (I2C peripheral
     input clock) must be a multiple of 10 MHz */
  else /*(I2C_InitStruct->I2C_ClockSpeed <= 400000)*/
  {
    if (I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_2)
    {
      /* Fast mode speed calculate: Tlow/Thigh = 2 */
      result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 3));
    }
    else /*I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_16_9*/
    {
      /* Fast mode speed calculate: Tlow/Thigh = 16/9 */
      result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 25));
      /* Set DUTY bit */
      result |= I2C_DutyCycle_16_9;
    }

    /* Test if CCR value is under 0x1*/
    if ((result & I2C_CCR_CCR) == 0)
    {
      /* Set minimum allowed value */
      result |= (uint16_t)0x0001;  
    }
    /* Set speed value and set F/S bit for fast mode */
    tmpreg |= (uint16_t)(result | I2C_CCR_FS);
    /* Set Maximum Rise Time for fast mode */
    I2Cx->TRISE = (uint16_t)(((freqrange * (uint16_t)300) / (uint16_t)1000) + (uint16_t)1);  
  }

  /* Write to I2Cx CCR */
  I2Cx->CCR = tmpreg;
  /* Enable the selected I2C peripheral */
  I2Cx->CR1 |= I2C_CR1_PE;

/*---------------------------- I2Cx CR1 Configuration ------------------------*/
  /* Get the I2Cx CR1 value */
  tmpreg = I2Cx->CR1;
  /* Clear ACK, SMBTYPE and  SMBUS bits */
  tmpreg &= CR1_CLEAR_MASK;
  /* Configure I2Cx: mode and acknowledgement */
  /* Set SMBTYPE and SMBUS bits according to I2C_Mode value */
  /* Set ACK bit according to I2C_Ack value */
  tmpreg |= (uint16_t)((uint32_t)I2C_InitStruct->I2C_Mode | I2C_InitStruct->I2C_Ack);
  /* Write to I2Cx CR1 */
  I2Cx->CR1 = tmpreg;

/*---------------------------- I2Cx OAR1 Configuration -----------------------*/
  /* Set I2Cx Own Address1 and acknowledged address */
  I2Cx->OAR1 = (I2C_InitStruct->I2C_AcknowledgedAddress | I2C_InitStruct->I2C_OwnAddress1);
}

/**
  * @brief  Fills each I2C_InitStruct member with its default value.
  * @param  I2C_InitStruct: pointer to an I2C_InitTypeDef structure which will be initialized.
  * @retval None
  */
void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct)
{
/*---------------- Reset I2C init structure parameters values ----------------*/
  /* initialize the I2C_ClockSpeed member */
  I2C_InitStruct->I2C_ClockSpeed = 5000;
  /* Initialize the I2C_Mode member */
  I2C_InitStruct->I2C_Mode = I2C_Mode_I2C;
  /* Initialize the I2C_DutyCycle member */
  I2C_InitStruct->I2C_DutyCycle = I2C_DutyCycle_2;
  /* Initialize the I2C_OwnAddress1 member */
  I2C_InitStruct->I2C_OwnAddress1 = 0;
  /* Initialize the I2C_Ack member */
  I2C_InitStruct->I2C_Ack = I2C_Ack_Disable;
  /* Initialize the I2C_AcknowledgedAddress member */
  I2C_InitStruct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
}

/**
  * @brief  Enables or disables the specified I2C peripheral.
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @param  NewState: new state of the I2Cx peripheral. 
  *   This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));
  if (NewState != DISABLE)
  {
    /* Enable the selected I2C peripheral */
    I2Cx->CR1 |= I2C_CR1_PE;
  }
  else
  {
    /* Disable the selected I2C peripheral */
    I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_PE);
  }
}

/**
  * @brief  Generates I2Cx communication START condition.
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @param  NewState: new state of the I2C START condition generation.
  *   This parameter can be: ENABLE or DISABLE.
  * @retval None.
  */
void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));
  if (NewState != DISABLE)
  {
    /* Generate a START condition */
    I2Cx->CR1 |= I2C_CR1_START;
  }
  else
  {
    /* Disable the START condition generation */
    I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_START);
  }
}

/**
  * @brief  Generates I2Cx communication STOP condition.
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @param  NewState: new state of the I2C STOP condition generation.
  *   This parameter can be: ENABLE or DISABLE.
  * @retval None.
  */
void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));
  if (NewState != DISABLE)
  {
    /* Generate a STOP condition */
    I2Cx->CR1 |= I2C_CR1_STOP;

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
天堂一区二区在线| 日本欧美大码aⅴ在线播放| 国产精品18久久久久久久久| 国产亚洲精品免费| 色哟哟在线观看一区二区三区| 亚洲午夜av在线| 欧美mv日韩mv国产网站| 99精品国产视频| 九九视频精品免费| 亚洲黄一区二区三区| 欧美刺激脚交jootjob| 日韩一区二区三区在线观看| 色婷婷狠狠综合| 欧美伊人久久久久久久久影院| 国产剧情一区在线| 国产白丝精品91爽爽久久| 日韩va欧美va亚洲va久久| 日韩高清在线观看| 国产一区视频网站| 免费黄网站欧美| 亚洲一区二区不卡免费| 中文字幕一区二区三中文字幕| 91精品久久久久久蜜臀| 色菇凉天天综合网| 99久久精品国产导航| 日本高清免费不卡视频| 精品欧美一区二区久久| 国产精品人成在线观看免费| 精品国产一区久久| 日韩一区二区三| 欧美激情资源网| 欧美—级在线免费片| 亚洲欧美经典视频| 国产精品美女久久久久久| 亚洲综合男人的天堂| 久久99精品国产麻豆不卡| 成人动漫av在线| 99视频在线精品| www.欧美色图| 欧美一区三区二区| 欧美成人aa大片| 亚洲图片激情小说| 亚洲免费毛片网站| 精彩视频一区二区三区| 91美女片黄在线观看| 欧美中文字幕一区二区三区 | 欧美日韩成人一区二区| 91在线观看视频| 日韩一级免费观看| 亚洲主播在线播放| 成人黄色a**站在线观看| 日韩三级免费观看| 亚洲一区二区欧美日韩| 国产成人午夜高潮毛片| 91在线视频官网| 久久综合色之久久综合| 国产精品麻豆一区二区| 国内精品不卡在线| 波多野结衣在线一区| 日韩欧美一区电影| 国产亚洲精品7777| 奇米在线7777在线精品 | 色狠狠综合天天综合综合| 久久蜜桃av一区精品变态类天堂| 久久久99久久精品欧美| 免费在线观看视频一区| 欧美日韩高清一区二区| 一区二区三区91| 久久福利资源站| av中文一区二区三区| 久久嫩草精品久久久精品一| 麻豆精品在线观看| 99久久国产综合精品女不卡| 国产亚洲欧洲一区高清在线观看| 青青草91视频| 欧美大片一区二区| 精品一区二区三区免费视频| 欧美一区二区三区的| 日本不卡在线视频| 精品国内二区三区| 激情综合五月天| 久久人人97超碰com| 国产a级毛片一区| 久久久99精品免费观看| 不卡视频免费播放| 亚洲蜜桃精久久久久久久| 91麻豆swag| 午夜精品一区二区三区电影天堂| 国产成人99久久亚洲综合精品| 久久久久久久综合狠狠综合| 风间由美一区二区av101| 中文字幕不卡一区| 日本高清免费不卡视频| 亚洲图片欧美综合| 精品久久久久久久一区二区蜜臀| 国产一二三精品| 欧美国产亚洲另类动漫| 一本色道久久综合狠狠躁的推荐| 亚洲综合小说图片| 精品久久久久久综合日本欧美| 国产成a人亚洲精品| 夜夜精品视频一区二区| 日韩欧美一二三| 91亚洲精品一区二区乱码| 亚洲福利国产精品| 亚洲精品一区二区三区蜜桃下载| 国产a区久久久| 日韩精品欧美精品| 中日韩免费视频中文字幕| 欧美三级一区二区| 亚洲国产日韩精品| 日韩精品一区二区在线| 97se狠狠狠综合亚洲狠狠| 日韩国产成人精品| 亚洲私人影院在线观看| 精品国产伦一区二区三区观看方式 | 91原创在线视频| 日韩高清中文字幕一区| 成人欧美一区二区三区白人| 制服丝袜成人动漫| 91亚洲资源网| 国产成人精品www牛牛影视| 亚洲r级在线视频| 欧美日韩一区二区三区高清| 国产一区二区三区观看| 日韩国产欧美三级| 亚洲视频在线一区| 国产日韩亚洲欧美综合| 成人av在线影院| 开心九九激情九九欧美日韩精美视频电影| 国产精品国产馆在线真实露脸| 99久久精品免费精品国产| 激情图区综合网| 青娱乐精品视频| 亚洲一卡二卡三卡四卡| 国产精品久久久久精k8| 久久免费的精品国产v∧| 日韩精品自拍偷拍| 日韩三级伦理片妻子的秘密按摩| 色8久久人人97超碰香蕉987| 成人免费视频一区二区| 亚洲黄色小视频| 亚洲国产精品二十页| 久久久精品影视| 久久亚洲综合色| 精品免费日韩av| 精品福利一区二区三区免费视频| 欧美巨大另类极品videosbest | 亚洲视频 欧洲视频| 国产人成亚洲第一网站在线播放| 日韩欧美一区电影| 亚洲精品在线电影| 久久亚区不卡日本| 国产亚洲欧美在线| 中文字幕亚洲综合久久菠萝蜜| 中文在线一区二区 | 午夜精品福利一区二区三区av| 亚洲私人影院在线观看| 亚洲精品伦理在线| 亚洲一本大道在线| 亚洲成人动漫一区| 爽好久久久欧美精品| 久久精品理论片| 国产乱淫av一区二区三区| 国产露脸91国语对白| av激情综合网| 欧美在线三级电影| 日韩一区和二区| 久久久午夜精品| 亚洲日本在线观看| 午夜电影网亚洲视频| 精品一区二区三区免费毛片爱| 激情综合网av| 91蝌蚪porny| 91麻豆精品国产| 亚洲第一电影网| 蜜桃免费网站一区二区三区| 国产精品伊人色| 97久久超碰国产精品电影| 国产精品女主播在线观看| 中文字幕一区在线| 亚洲九九爱视频| 免费观看在线综合| 成人av在线播放网站| 欧美日韩高清一区二区| 国产午夜三级一区二区三| 夜夜嗨av一区二区三区四季av| 亚洲国产成人va在线观看天堂| 精品一区二区三区久久| 盗摄精品av一区二区三区| 欧美日韩国产三级| 国产日本一区二区| 亚洲成av人片| av在线这里只有精品| 91精品国产黑色紧身裤美女| 国产精品久久久久久久久久免费看| 亚洲午夜久久久久久久久电影网 | 久久亚洲一区二区三区明星换脸| 综合在线观看色| 麻豆久久久久久|