/*********************************************************************************
@file HDC1080.c @brief Humidity and Temperature sensor 驱动模块
@details I2C接口
@details Copyright 2016, Testo, Ltd., Shenzhen
@author pli @date 2016.02.16
@version 00.00
编译条件:
芯片型号..- MSP430i2041
编译器版本- IAR for ARM - Ver6.4
优化级别..- High balanced
修改记录:
初版00.00
*******************************************************************************/
//#include
//#include "io430.h"
//#include "main.h"
#include "HDC1080.h"
#include "I2C.h"
#include "timing_delay.h"
//#include
/*******************************************************************************
* @brief HDC1080_Write_Buffer
* @param uint8_t addr is point register
* @param uint8_t *buffer is the need to write data point
* @param uint8_t len is the write data length
* @retval void
*******************************************************************************/
void HDC1080_Write_Buffer(uint8_t addr, uint8_t *buffer, uint8_t len)
{
I2C_Start();
I2C_Send_Byte(HDC1080_Device_Adderss);
I2C_Wait_Ack();
I2C_Send_Byte(addr);
I2C_Wait_Ack();
while ( len-- )
{
I2C_Send_Byte(*buffer);
I2C_Wait_Ack();
buffer++;
}
I2C_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;
while( pin_SCL_READ())
{
Delay_us(1);
temp++;
if ( temp >= 100 )
{
break;
}
}
I2C_Start();
I2C_Send_Byte(HDC1080_Device_Adderss|0x01); //read
I2C_Wait_Ack();
while ( len-- )
{
*buffer = I2C_Recv_Byte();
buffer++;
if ( len == 0 )
I2C_Send_NoAck();
else
I2C_Send_Ack();
}
I2C_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;
while( pin_SCL_READ())
{
Delay_us(1);
temp++;
if ( temp >= 100 )
{
break;
}
}
//Delay_ms(10); // after triger should wait at least 6.5ms
Delay_ms(10); // after triger should wait at least 6.5ms
I2C_Start();
I2C_Send_Byte(HDC1080_Device_Adderss|0x01); //read
I2C_Wait_Ack();
while ( len-- )
{
*buffer = I2C_Recv_Byte();
buffer++;
if ( len == 0 )
I2C_Send_NoAck();
else
I2C_Send_Ack();