资源简介
气压传感器BMP180驱动程序,IIC协议,STM32f103,主频72M,直接可用。
代码片段和文件信息
#include “BMP180.h“
#include “delay.h“
//PA6--SCL PA7--SDA
//I2C总线初始化
//配置SDA信号线为输入模式
u8 BMP_communication_sta = 1;
void BMP180_SDA_Input_Mode()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = BMP180_SDA;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(BMP180_I2C_PORT &GPIO_InitStructure);
}
//配置SDA信号线为输出模式
void BMP180_SDA_Output_Mode()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = BMP180_SDA;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(BMP180_I2C_PORT &GPIO_InitStructure);
}
void BMP180_SDA_Output( uint16_t val )
{
if ( val ) {
GPIO_SetBits(BMP180_I2C_PORTBMP180_SDA);
} else {
GPIO_ResetBits(BMP180_I2C_PORTBMP180_SDA);
}
}
//
uint8_t BMP180_SDA_Input()
{
return GPIO_ReadInputDataBit(BMP180_I2C_PORT BMP180_SDA);
}
//
void BMP180_SCL_Output( uint16_t val )
{
if ( val ) {
GPIO_SetBits(BMP180_I2C_PORTBMP180_SCL);
} else {
GPIO_ResetBits(BMP180_I2C_PORTBMP180_SCL);
}
}
//延时程序
void BMP180_delay1(unsigned int n)
{
unsigned int i;
for ( i=0;i }
//I2C总线启动
void BMP180_I2CStart(void)
{
BMP180_SDA_Output(1);BMP180_delay1(500);
BMP180_SCL_Output(1);BMP180_delay1(500);
BMP180_SDA_Output(0);BMP180_delay1(500);
BMP180_SCL_Output(0);BMP180_delay1(500);
}
//I2C总线停止
void BMP180_I2CStop(void)
{
BMP180_SCL_Output(0); BMP180_delay1(500);
BMP180_SDA_Output(0); BMP180_delay1(500);
BMP180_SCL_Output(1); BMP180_delay1(500);
BMP180_SDA_Output(1); BMP180_delay1(500);
}
//等待应答
unsigned char BMP180_I2CWaitAck(void)
{
unsigned short cErrTime = 5;
BMP180_SDA_Input_Mode();
BMP180_delay1(500);
BMP180_SCL_Output(1);
BMP180_delay1(500);
while(BMP180_SDA_Input())
{
cErrTime--;
BMP180_delay1(500);
if (0 == cErrTime)
{
BMP180_SDA_Output_Mode();
BMP_communication_sta = 0;
BMP180_I2CStop();
return 0;
}
}
BMP180_SDA_Output_Mode();
BMP180_SCL_Output(0);
BMP180_delay1(500);
return 1;
}
//发送应答位
void BMP180_I2CSendAck(void)
{
BMP180_SDA_Output(0);
BMP180_delay1(500);
BMP180_delay1(500);
BMP180_SCL_Output(1);
BMP180_delay1(500);
BMP180_SCL_Output(0);
BMP180_delay1(500);
}
//
void BMP180_I2CSendNotAck(void)
{
BMP180_SDA_Output(1);
BMP180_delay1(500);
BMP180_SCL_Output(1);
BMP180_delay1(500);
BMP180_SCL_Output(0);
BMP180_delay1(500);
}
//通过I2C总线发送一个字节数据
void BMP180_I2CSendByte(unsigned char cSendByte)
{
unsigned char i = 8;
while (i--)
{
BMP180_SCL_Output(0);
BMP180_delay1(500);
BMP180_SDA_Output(cSendByte & 0x80);
BMP180_delay1(500);
cSendByte += cSendByte;
BMP180_delay1(500);
BMP180_SCL_Output(1);
BMP180_delay1(500);
}
BMP180_SCL_Output(0);
BMP180_delay1(500);
}
//从I2C总线接收一个字节数据
unsigned char BMP180_I2CReceiveByte(void)
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8079 2018-05-05 12:39 BMP180\BMP180.c
文件 512 2018-05-05 12:38 BMP180\BMP180.h
目录 0 2018-09-16 16:40 BMP180
----------- --------- ---------- ----- ----
8591 3
- 上一篇:iOS逆向技术视频教程
- 下一篇:CPLEX 学术版安装指南
相关资源
- tcs3472颜色识别程序
- 气压计IIC模式驱动SPL06.rar
- stm32通过IIC读取HMC5883L来计算方向角
- 0.91OLED显示屏_C51系列_IIC_例程
- STM32+IIC+PCF8574T+1602A
- 电容屏USB转IIC代码.zip
- verilog编程fpga通过IIC读取mpu6050数据
- STM32 IIC 状态机 DMA 控制MPU60x0和burst读
- STM32和SHT3X 高精度温湿度传感器驱动
- 四线(IIC)OLED驱动STM32驱动程序
- stm32f407ZET驱动IIC 0.96寸OLED
- 基于stm32显示oled,用的是iic通信,可
- STM32F030F4P6串口通讯,modbus协议,IIC
- STM32F407 软件模拟IIC通信程序
- sony imx290 driver
- msp430F5529驱动 IIC OLED
- stm32 tsm12触摸芯片的触摸驱动软件ii
- TM1651 显程.rar
- STM32f103+SHT30代码.rar
- STM32CUBE配置硬件IIC协议驱动MPU6050,采
- STM32F407-OLED四线IIC.zip
- stm32f103_ bma250hal 库驱动
- Esp8266 进阶之路31乐鑫esp8266 SDK编程使
- stm32F407 库函数的麦轮手动车 PS2手柄
- IIC总线 Verilog FGPA模块实现 注释详尽
- 51单片机 LCD1602液晶 sht31 IIC接口
- MSP430F149单片机模拟IIC和DS18B20通信进行
- QMC5883L驱动文件
- stm8单片机对电量计的iic读取程序
- 51单片机模拟I2C从机
评论
共有 条评论