嵌入式STM32F103温湿度SHT30

本文介绍了如何在嵌入式STM32F103VE上驱动SHT30温湿度传感器,详细阐述了管脚配置连接,包括SCL连接到GPIOC8,SDA连接到GPIOE6,并提供了相应的程序代码实现。
摘要由CSDN通过智能技术生成

嵌入式STM32F103VE驱动温湿度STH30

管脚配置连接

SCL->GPIOC8
SDA->GPIOE6

程序代码

#include "stm32f10x.h"

#define BIT(x,n) ((x&(1<<n))!=0)

#define SCL_PIN GPIO_Pin_6 //SCL PC6
#define SDA_PIN GPIO_Pin_8 //SDA PE8

#define SCL_PORT GPIOC
#define SDA_PORT GPIOE

#define FAILURE 0
#define SUCCESS 1

float g_tmp,g_frh;

void SDA_Input_Mode()
{
   
	GPIO_InitTypeDef GPIO_InitStructure;

	GPIO_InitStructure.GPIO_Pin = SDA_Pin;
  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;	 

  	GPIO_Init(SDA_PORT, &GPIO_InitStructure);
}

void SDA_Output_Mode()
{
   
	GPIO_InitTypeDef GPIO_InitStructure;

	GPIO_InitStructure.GPIO_Pin = SDA_Pin;
  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  	GPIO_Init(SDA_PORT, &GPIO_InitStructure);
}

void SDA_Output( uint16_t val )
{
   
	if ( val ) {
   
		GPIO_SetBits(SDA_PORT,SDA_Pin);
	} else {
   
		GPIO_ResetBits(SDA_PORT,SDA_Pin);
	}
}


void SCL_Output( uint16_t val )
{
   
	if ( val ) {
   
		GPIO_SetBits(SCL_PORT,SCL_Pin);
	} else {
   
		GPIO_ResetBits(SCL_PORT,SCL_Pin);
	}
}


uint8_t SDA_Input()
{
   
	return GPIO_ReadInputDataBit( SDA_PORT, SDA_Pin);
}



void delay_Us(unsigned long us)
{
   	
	unsigned int i=0;
	for(i=0;i<n;i++)
	{
   
		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
		__nop();__nop();__nop();
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值