资源简介
电子-STM32硬件I2CMaster接口函数V1.01.zip,单片机/嵌入式STM32-F0/F1/F2
代码片段和文件信息
/**
*****************************************************************************
* I2C控制函数
*
* (C) Copyright 2000-2020 ***
* All Rights Reserved
*****************************************************************************
*
* @File : hal_i2c.c
* @By : 陈桂东
* @Version : V1.0
* @Date : 2019 / 05 / 23
*
*****************************************************************************
*
* Update
*
* @Version : V1.*
* @By : ***
* @Date : 20** / ** / **
* @Brief : ***
*
*****************************************************************************
**/
#include “hal_i2c.h“
/* ============================== Hard I2C Master Mode ============================== */
/******************************************************************************
定义变量
******************************************************************************/
#define I2C_DEVICE I2C1
#define I2C_ADDRESS 0x32
/* I2C TIMING Register define when I2C clock source is SYSCLK */
/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 32 MHz */
//#define I2C_TIMING 0x10A13E56 /* 100 kHz with analog Filter ON Rise Time 400ns Fall Time 100ns */
#define I2C_TIMING 0x00B1112E /* 400 kHz with analog Filter ON Rise Time 250ns Fall Time 100ns */
/* I2C TIMING Register define when I2C clock source is SYSCLK */
/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 16 MHz */
//#define I2C_TIMING 0x00303D5B /* 100 kHz with analog Filter ON Rise Time 0ns Fall Time 0ns */
//#define I2C_TIMING 0x0010061A /* 400 kHz with analog Filter ON Rise Time 0ns Fall Time 0ns */
//#define I2C_TIMING 0x00A03D53 /* 100 kHz with analog Filter ON Rise Time 400ns Fall Time 100ns */
//#define I2C_TIMING 0x00500615 /* 400 kHz with analog Filter ON Rise Time 250ns Fall Time 100ns */
uint32_t I2CMTimeout = I2CM_LONG_TIMEOUT;
uint16_t I2CMDataNum;
/**
*****************************************************************************
* @Name : I2C Master接口初始化
*
* @Brief : 硬件I2C方式
*
* @Input : none
*
* @Output : none
*
* @Return : none
*****************************************************************************
**/
void HAL_I2CHardMasterInit(void)
{
uint32_t i2c_temp = 0;
//I2C时钟源选择
RCC->CCIPR &= ~RCC_CCIPR_I2C1SEL;
RCC->CCIPR |= RCC_CCIPR_I2C1SEL_0; //System clock selected as I2C1 clock
RCC->IOPENR |= RCC_IOPENR_GPIOBEN;
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;
//
//管脚复用
//
GPIOB->AFR[0] &= ~(GPIO_AFRL_AFSEL6 | GPIO_AFRL_AFSEL7);
GPIOB->AFR[0] |= 0x01<<(4 * 6
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 21003 2019-07-09 14:04 hal_i2c.c
文件 4004 2019-07-08 17:04 hal_i2c.h
评论
共有 条评论