⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_i2c.lst

📁 完成数据的采集
💻 LST
📖 第 1 页 / 共 4 页
字号:
    468            {
    469              /* Enable dual addressing mode */
    470              I2Cx->OAR2 |= OAR2_ENDUAL_Set;
    471            }
    472            else
    473            {
    474              /* Disable dual addressing mode */
    475              I2Cx->OAR2 &= OAR2_ENDUAL_Reset;
    476            }
    477          }
    478          
    479          /*******************************************************************************
    480          * Function Name  : I2C_GeneralCallCmd
    481          * Description    : Enables or disables the specified I2C general call feature.
    482          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    483          *                  - NewState: new state of the I2C General call.
    484          *                    This parameter can be: ENABLE or DISABLE.
    485          * Output         : None
    486          * Return         : None
    487          *******************************************************************************/
    488          void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
    489          {
    490            /* Check the parameters */
    491            assert_param(IS_FUNCTIONAL_STATE(NewState));
    492          
    493            if (NewState != DISABLE)
    494            {
    495              /* Enable generall call */
    496              I2Cx->CR1 |= CR1_ENGC_Set;
    497            }
    498            else
    499            {
    500              /* Disable generall call */
    501              I2Cx->CR1 &= CR1_ENGC_Reset;
    502            }
    503          }
    504          
    505          /*******************************************************************************
    506          * Function Name  : I2C_ITConfig
    507          * Description    : Enables or disables the specified I2C interrupts.
    508          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    509          *                  - I2C_IT: specifies the I2C interrupts sources to be enabled
    510          *                    or disabled. 
    511          *                    This parameter can be any combination of the following values:
    512          *                       - I2C_IT_BUF: Buffer interrupt mask
    513          *                       - I2C_IT_EVT: Event interrupt mask
    514          *                       - I2C_IT_ERR: Error interrupt mask
    515          *                  - NewState: new state of the specified I2C interrupts.
    516          *                    This parameter can be: ENABLE or DISABLE.
    517          * Output         : None
    518          * Return         : None
    519          *******************************************************************************/
    520          void I2C_ITConfig(I2C_TypeDef* I2Cx, u16 I2C_IT, FunctionalState NewState)
    521          {
    522            /* Check the parameters */
    523            assert_param(IS_FUNCTIONAL_STATE(NewState));
    524            assert_param(IS_I2C_CONFIG_IT(I2C_IT));
    525            
    526            if (NewState != DISABLE)
    527            {
    528              /* Enable the selected I2C interrupts */
    529              I2Cx->CR2 |= I2C_IT;
    530            }
    531            else
    532            {
    533              /* Disable the selected I2C interrupts */
    534              I2Cx->CR2 &= (u16)~I2C_IT;
    535            }
    536          }
    537          
    538          /*******************************************************************************
    539          * Function Name  : I2C_SendData
    540          * Description    : Sends a data byte through the I2Cx peripheral.
    541          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    542          *                  - Data: Byte to be transmitted..
    543          * Output         : None
    544          * Return         : None
    545          *******************************************************************************/
    546          void I2C_SendData(I2C_TypeDef* I2Cx, u8 Data)
    547          {
    548            /* Write in the DR register the data to be sent */
    549            I2Cx->DR = Data;
    550          }
    551          
    552          /*******************************************************************************
    553          * Function Name  : I2C_ReceiveData
    554          * Description    : Returns the most recent received data by the I2Cx peripheral.
    555          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    556          * Output         : None
    557          * Return         : The value of the received data.
    558          *******************************************************************************/
    559          u8 I2C_ReceiveData(I2C_TypeDef* I2Cx)
    560          {
    561            /* Return the data in the DR register */
    562            return (u8)I2Cx->DR;
    563          }
    564          
    565          /*******************************************************************************
    566          * Function Name  : I2C_Send7bitAddress
    567          * Description    : Transmits the address byte to select the slave device.
    568          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    569          *                  - Address: specifies the slave address which will be transmitted
    570          *                  - I2C_Direction: specifies whether the I2C device will be a
    571          *                    Transmitter or a Receiver. 
    572          *                    This parameter can be one of the following values
    573          *                       - I2C_Direction_Transmitter: Transmitter mode
    574          *                       - I2C_Direction_Receiver: Receiver mode
    575          * Output         : None
    576          * Return         : None.
    577          *******************************************************************************/
    578          void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, u8 Address, u8 I2C_Direction)
    579          {
    580            /* Check the parameters */
    581            assert_param(IS_I2C_DIRECTION(I2C_Direction));
    582          
    583            /* Test on the direction to set/reset the read/write bit */
    584            if (I2C_Direction != I2C_Direction_Transmitter)
    585            {
    586              /* Set the address ADD0 bit0 for read */
    587              Address |= OAR1_ADD0_Set;
    588            }
    589            else
    590            {
    591              /* Reset the address bit0 for write */
    592              Address &= OAR1_ADD0_Reset;
    593            }
    594            /* Send the address */
    595            I2Cx->DR = Address;
    596          }
    597          
    598          /*******************************************************************************
    599          * Function Name  : I2C_ReadRegister
    600          * Description    : Reads the specified I2C register and returns its value.
    601          * Input1         : - I2C_Register: specifies the register to read.
    602          *                    This parameter can be one of the following values:
    603          *                       - I2C_Register_CR1:  CR1 register.
    604          *                       - I2C_Register_CR2:   CR2 register.
    605          *                       - I2C_Register_OAR1:  OAR1 register.
    606          *                       - I2C_Register_OAR2:  OAR2 register.
    607          *                       - I2C_Register_DR:    DR register.
    608          *                       - I2C_Register_SR1:   SR1 register.
    609          *                       - I2C_Register_SR2:   SR2 register.
    610          *                       - I2C_Register_CCR:   CCR register.
    611          *                       - I2C_Register_TRISE: TRISE register.
    612          * Output         : None
    613          * Return         : The value of the read register.
    614          *******************************************************************************/
    615          u16 I2C_ReadRegister(I2C_TypeDef* I2Cx, u8 I2C_Register)
    616          {
    617            /* Check the parameters */
    618            assert_param(IS_I2C_REGISTER(I2C_Register));
    619          
    620            /* Return the selected register value */
    621            return (*(u16 *)(*((u32 *)&I2Cx) + I2C_Register));
    622          }
    623          
    624          /*******************************************************************************
    625          * Function Name  : I2C_SoftwareResetCmd
    626          * Description    : Enables or disables the specified I2C software reset.
    627          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    628          *                  - NewState: new state of the I2C software reset.
    629          *                    This parameter can be: ENABLE or DISABLE.
    630          * Output         : None
    631          * Return         : None
    632          *******************************************************************************/
    633          void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
    634          {
    635            /* Check the parameters */
    636            assert_param(IS_FUNCTIONAL_STATE(NewState));
    637          
    638            if (NewState != DISABLE)
    639            {
    640              /* Peripheral under reset */
    641              I2Cx->CR1 |= CR1_SWRST_Set;
    642            }
    643            else
    644            {
    645              /* Peripheral not under reset */
    646              I2Cx->CR1 &= CR1_SWRST_Reset;
    647            }
    648          }
    649          
    650          /*******************************************************************************
    651          * Function Name  : I2C_SMBusAlertConfig
    652          * Description    : Drives the SMBusAlert pin high or low for the specified I2C.
    653          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    654          *                  - I2C_SMBusAlert: specifies SMBAlert pin level. 
    655          *                    This parameter can be one of the following values:
    656          *                       - I2C_SMBusAlert_Low: SMBAlert pin driven low
    657          *                       - I2C_SMBusAlert_High: SMBAlert pin driven high
    658          * Output         : None
    659          * Return         : None
    660          *******************************************************************************/
    661          void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, u16 I2C_SMBusAlert)
    662          {
    663            /* Check the parameters */
    664            assert_param(IS_I2C_SMBUS_ALERT(I2C_SMBusAlert));
    665          
    666            if (I2C_SMBusAlert == I2C_SMBusAlert_Low)
    667            {
    668              /* Drive the SMBusAlert pin Low */
    669              I2Cx->CR1 |= I2C_SMBusAlert_Low;
    670            }
    671            else
    672            {
    673              /* Drive the SMBusAlert pin High  */
    674              I2Cx->CR1 &= I2C_SMBusAlert_High;
    675            }
    676          }
    677          
    678          /*******************************************************************************
    679          * Function Name  : I2C_TransmitPEC
    680          * Description    : Enables or disables the specified I2C PEC transfer.
    681          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    682          *                  - NewState: new state of the I2C PEC transmission.
    683          *                    This parameter can be: ENABLE or DISABLE.
    684          * Output         : None
    685          * Return         : None
    686          *******************************************************************************/
    687          void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
    688          {
    689            /* Check the parameters */
    690            assert_param(IS_FUNCTIONAL_STATE(NewState));
    691          
    692            if (NewState != DISABLE)
    693            {
    694              /* Enable the selected I2C PEC transmission */
    695              I2Cx->CR1 |= CR1_PEC_Set;
    696            }
    697            else
    698            {
    699              /* Disable the selected I2C PEC transmission */
    700              I2Cx->CR1 &= CR1_PEC_Reset;
    701            }
    702          }
    703          
    704          /*******************************************************************************
    705          * Function Name  : I2C_PECPositionConfig
    706          * Description    : Selects the specified I2C PEC position.
    707          * Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
    708          *                  - I2C_PECPosition: specifies the PEC position. 
    709          *                    This parameter can be one of the following values:
    710          *                       - I2C_PECPosition_Next: PEC bit indicates that current
    711          *                         byte is PEC
    712          *                       - I2C_PECPosition_Current: PEC bit indicates that the
    713          *                         next byte is PEC
    714          * Output         : None

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -