BH1750FVI STM32F103 HAL库 硬件IIC例程

  • d4_803171
    了解作者
  • 1.6MB
    文件大小
  • 文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-10 10:17
    上传日期
BH1750FVI STM32F103 HAL库 硬件IIC例程 直接串口打印输出
BH1750FVI_Example.7z
内容介绍
/** ****************************************************************************** * @file stm32f1xx_hal_i2c.c * @author MCD Application Team * @brief I2C HAL module driver. * This file provides firmware functions to manage the following * functionalities of the Inter Integrated Circuit (I2C) peripheral: * + Initialization and de-initialization functions * + IO operation functions * + Peripheral State, Mode and Error functions * @verbatim ============================================================================== ##### How to use this driver ##### ============================================================================== [..] The I2C HAL driver can be used as follows: (#) Declare a I2C_HandleTypeDef handle structure, for example: I2C_HandleTypeDef hi2c; (#)Initialize the I2C low level resources by implementing the HAL_I2C_MspInit() API: (##) Enable the I2Cx interface clock (##) I2C pins configuration (+++) Enable the clock for the I2C GPIOs (+++) Configure I2C pins as alternate function open-drain (##) NVIC configuration if you need to use interrupt process (+++) Configure the I2Cx interrupt priority (+++) Enable the NVIC I2C IRQ Channel (##) DMA Configuration if you need to use DMA process (+++) Declare a DMA_HandleTypeDef handle structure for the transmit or receive channel (+++) Enable the DMAx interface clock using (+++) Configure the DMA handle parameters (+++) Configure the DMA Tx or Rx channel (+++) Associate the initialized DMA handle to the hi2c DMA Tx or Rx handle (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx or Rx channel (#) Configure the Communication Speed, Duty cycle, Addressing mode, Own Address1, Dual Addressing mode, Own Address2, General call and Nostretch mode in the hi2c Init structure. (#) Initialize the I2C registers by calling the HAL_I2C_Init(), configures also the low level Hardware (GPIO, CLOCK, NVIC...etc) by calling the customized HAL_I2C_MspInit(&hi2c) API. (#) To check if target device is ready for communication, use the function HAL_I2C_IsDeviceReady() (#) For I2C IO and IO MEM operations, three operation modes are available within this driver : *** Polling mode IO operation *** ================================= [..] (+) Transmit in master mode an amount of data in blocking mode using HAL_I2C_Master_Transmit() (+) Receive in master mode an amount of data in blocking mode using HAL_I2C_Master_Receive() (+) Transmit in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Transmit() (+) Receive in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Receive() *** Polling mode IO MEM operation *** ===================================== [..] (+) Write an amount of data in blocking mode to a specific memory address using HAL_I2C_Mem_Write() (+) Read an amount of data in blocking mode from a specific memory address using HAL_I2C_Mem_Read() *** Interrupt mode IO operation *** =================================== [..] (+) Transmit in master mode an amount of data in non blocking mode using HAL_I2C_Master_Transmit_IT() (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback (+) Receive in master mode an amount of data in non blocking mode using HAL_I2C_Master_Receive_IT() (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback (+) Transmit in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Transmit_IT() (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback (+) Receive in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Receive_IT() (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2C_ErrorCallback (+) Abort a master I2C process communication with Interrupt using HAL_I2C_Master_Abort_IT() (+) End of abort process, HAL_I2C_AbortCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_AbortCpltCallback() *** Interrupt mode IO sequential operation *** ============================================== [..] (@) These interfaces allow to manage a sequential transfer with a repeated start condition when a direction change during transfer [..] (+) A specific option field manage the different steps of a sequential transfer (+) Option field values are defined through @ref I2C_XFEROPTIONS and are listed below: (++) I2C_FIRST_AND_LAST_FRAME: No sequential usage, functionnal is same as associated interfaces in no sequential mode (++) I2C_FIRST_FRAME: Sequential usage, this option allow to manage a sequence with start condition, address and data to transfer without a final stop condition (++) I2C_NEXT_FRAME: Sequential usage, this option allow to manage a sequence with a restart condition, address and with new data to transfer if the direction change or manage only the new data to transfer if no direction change and without a final stop condition in both cases (++) I2C_LAST_FRAME: Sequential usage, this option allow to manage a sequance with a restart condition, address and with new data to transfer if the direction change or manage only the new data to transfer if no direction change and with a final stop condition in both cases (+) Differents sequential I2C interfaces are listed below: (++) Sequential transmit in master I2C mode an amount of data in non-blocking mode using HAL_I2C_Master_Sequential_Transmit_IT() (+++) At transmission end of current frame transfer, HAL_I2C_MasterTxCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback() (++) Sequential receive in master I2C mode an amount of data in non-blocking mode using HAL_I2C_Master_Sequential_Receive_IT() (+++) At reception end of current frame transfer, HAL_I2C_MasterRxCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback() (++) Abort a master I2C process communication with Interrupt using HAL_I2C_Master_Abort_IT() (+++) End of abort process, HAL_I2C_AbortCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_AbortCpltCallback() (++) Enable/disable the Address listen mode in slave I2C mode using HAL_I2C_EnableListen_IT() HAL_I2C_DisableListen_IT() (+++) When address slave I2C match, HAL_I2C_AddrCallback() is executed and user can add his own code to check the Address Match Code and the transmission direction request by master (Write/Read). (+++) At Listen mode end HAL_I2C_ListenCp
评论
    相关推荐
    • STM32 程序
      STM32一些自己写过的程序并应用过可以使用的,包括直流电机驱动,温度显示,oled显示,adc实验,PWM输出,定时器中断,全部都写在了main函数中,不过写的有一点乱。(pwm实验可以看我的博客)
    • STM32
      STM32 该存储库用于容纳我的学习项目,以便使用STM32开发板进行嵌入式系统编程。
    • stm32f103
      stm32f103c8t6资料,包括源码,原理图等等
    • STM32
      STM32
    • stm32 sim 7600
      stm32 ota sim 7600 stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600stm32 ota sim 7600...
    • STM32 SPWM
      利用stm32的定时器产生spwm波形,进行调解,希望能对大家有所帮助。
    • stm32 pack
      keil5 中使用的 STM32包 其中包括 STM32F0 STM32F1 STM32F3 STM32L0 STM32L1
    • stm32cubemx
      stm32cubemx st的代码生成器,安装后可以进行图形化的代码生成,项目生成!
    • STM32CubeMX
      ST(意法半导体)公司为方便STM32的使用和学习,以及HAL库的推广,自行研发的可以通过配置,自动生成初始化代码的工具软件
    • STM32 JoyStickMouse
      今天终于把 STM32 的例程 JoyStickMouse 跑起来了,上传一份备忘。 注意要根据 stm32f10x_conf.h 中的注释去掉一些没用到的文件