#include <stdint.h>
#include "HDC1080.h"
#include "delay.h"
#include "iic.h"
#include "stm32f10x.h"
#include "headfile.h"
void HDC1080_Write_Buffer(uint8_t addr, uint8_t *buffer, uint8_t len)
{
IIC_Start();
IIC_Send_Byte(HDC1080_Device_Adderss);
IIC_Wait_Ack();
IIC_Send_Byte(addr);
IIC_Wait_Ack();
while ( len-- )
{
IIC_Send_Byte(*buffer);
IIC_Wait_Ack();
buffer++;
}
IIC_Stop();
}
/*******************************************************************************
* @brief HDC1080_Read_Buffer between triger and read there is no wait.
* @param uint8_t addr is point register
* @param uint8_t *buffer is the need to read data point
* @param uint8_t len is the read data length
* @retval void
*******************************************************************************/
void HDC1080_Read_Buffer(uint8_t addr, uint8_t *buffer, uint8_t len)
{
uint8_t temp = 0;
IIC_Start();
IIC_Send_Byte(HDC1080_Device_Adderss);
IIC_Wait_Ack();
IIC_Send_Byte(addr);
IIC_Wait_Ack();
IIC_Stop();
while(IIC_SCL)
{
delay_us(20);
temp++;
if ( temp >= 100 )
{
break;
}
}
IIC_Start();
IIC_Send_Byte(HDC1080_Device_Adderss|0x01); //read
IIC_Wait_Ack();
while ( len-- )
{
*buffer = IIC_Read_Byte(0);
buffer++;
if ( len == 0 )
IIC_NAck();
else
IIC_Ack();
}
IIC_Stop();
}
/*******************************************************************************
* @brief HDC1080_Read_MBuffer becareful between triger and read there is a wait.
* @param uint8_t addr is point register
* @param uint8_t *buffer is the need to read data point
* @param uint8_t len is the read data length
* @retval void
*******************************************************************************/
void HDC1080_Read_MBuffer(uint8_t addr, uint8_t *buffer, uint8_t len)
{
uint8_t temp = 0;
IIC_Start();
IIC_Send_Byte(HDC1080_Device_Adderss);
IIC_Wait_Ack();
IIC_Send_Byte(0X00);
IIC_Wait_Ack();
IIC_Stop();
while(IIC_SCL)
{
delay_ms(20);
temp++;
if ( temp >= 100 )
{
break;
}
}
delay_ms(10); // after triger should wait at least 6.5ms
IIC_Start();
IIC_Send_Byte(HDC1080_Device_Adderss|0x01); //read
IIC_Wait_Ack();
while ( len-- )
{
*buffer = IIC_Read_Byte(0);
buffer++;
if ( len == 0 )
IIC_NAck();
else
IIC_Ack();
}
IIC_Stop();
}
/*******************************************************************************
* @brief HDC1080_Soft_Reset
* @param void
* @retval void
*******************************************************************************/
void HDC1080_Soft_Reset(void)
{
uint8_t temp[2];
temp[0] = 0x80;
temp[1] = 0x00;
HDC1080_Write_Buffer(HDC1080_Read_Config, temp, 2);
delay_ms(20);//there should be waiting for more than 15 ms.
}
/*******************************************************************************
* @brief HDC1080_Setting
* @param void
* @retval void
*******************************************************************************/
void HDC1080_Setting(void)
{
uint16_t tempcom = 0;
uint8_t temp[2];
tempcom |= 1<<HDC1080_Mode ;//???????????'??
// ?�????�???14bit
temp[0] = (uint8_t)(tempcom >> 8);
temp[1] = (uint8_t)tempcom;
HDC1080_Write_Buffer(0x02, temp, 2);
}
/*******************************************************************************
* @brief HDC1080_Init
* @param void
* @retval void
*******************************************************************************/
void HDC1080_Init(void)
{
uint8_t temp = 0;
IIC_Init();
HDC1080_Soft_Reset();
HDC1080_Setting();
while( IIC_SCL )
{
delay_us(20);;
temp++;
if ( temp >= 100 )
{
break;
}
}
}
/*******************************************************************************
* @brief HDC1080_Read_Temper
* @param void
* @retval int16_t tempr value
*******************************************************************************/
int16_t HDC1080_Read_Temper(void)
{
uint8_t buffer[2];
HDC1080_Read_MBuffer(0x00, buffer, 2);
//return ((buffer[0]<<8)|buffer[1]);
return (int16_t)((((buffer[0]<<8)|buffer[1])/65536.0)*165-40);
//return (int16_t)(((((buffer[0]<<8)|buffer[1])/65536.0)*165-40)*100);
}
/*******************************************************************************
* @brief HDC1080_Read_Humidity
* @param void
* @retval int16_t Humidity value
*******************************************************************************/
int16_t HDC1080_Read_Humidi(void)
{
uint8_t buffer[2];
HDC1080_Read_MBuffer(HDC1080_Read_Humidity, buffer, 2);
return (buffer[0]<<8)|buffer[1];
//return (int16_t)((((buffer[0]<<8)|buffer[1])/65536.0)*10000);
}
/*******************************************************************************
* @brief HDC1080_Read_Configuration
* @param void
* @retval Config value
*******************************************************************************/
uint16_t HDC1080_Read_Conf(void)
{
uint8_t buffer[2];
HDC1080_Read_Buffer(HDC1080_Read_Config, buffer, 2);
return ((buffer[0]<<8)|buffer[1]);
}
/*******************************************************************************
* @brief HDC1080_Read_ManufacturerID
* @param void
* @retval ManufacturerID
*******************************************************************************/
uint16_t HDC1080_Read_ManufacturerID(void)
{
uint8_t buffer[2];
HDC1080_Read_Buffer(0xfe, buffer, 2);
return ((buffer[0]<<8)|buffer[1]);
}
/*******************************************************************************
* @brief HDC1080_Read_DeviceID
* @param void
* @retval DeviceID
*******************************************************************************/
uint16_t HDC1080_Read_DeviceID(void)
{
uint8_t buffer[2];
HDC1080_Read_Buffer(0xff, buffer, 2);
return ((buffer[0]<<8)|buffer[1]);
}
STM32-I2C-HDC1080.zip
需积分: 14 188 浏览量
2019-07-31
21:30:24
上传
评论 3
收藏 4KB ZIP 举报
<Sunny>
- 粉丝: 22
- 资源: 7
最新资源
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈