/*******************************************************************************
* File Name: main.c
*
* Version: 1.0
*
* Description:
*
*
* Parameters used:
* I2CM Master
* Implementation Fixed function
* Data rate 100kbps
* SDA SCL pin config Open drain, drives low
* Pull-up resistors 2.67k each
*
*
*
********************************************************************************
* Copyright 2012, Cypress Semiconductor Corporation. All rights reserved.
* This software is owned by Cypress Semiconductor Corporation and is protected
* by and subject to worldwide patent and copyright laws and treaties.
* Therefore, you may use this software only as provided in the license agreement
* accompanying the software package from which you obtained this software.
* CYPRESS AND ITS SUPPLIERS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* WITH REGARD TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*******************************************************************************/
#include <device.h>
#include <string.h>
/* HYT221 command define */
#define HYT_MR 0
#define HYT_DR 1
/* The I2CM Slave address by default in a PSoC device is 8 */
#define I2CM_SLAVE_ADDRESS (0x28u)
/* The I2CM buffer define */
uint8 HYT221_Read_Buff[4] = {0};
uint8 HYT221_Write_Buff[4] = {0};
/* The HYT221 function define */
void HYT_MR_Initialization(void);
void HYT_DR_Operation(void);
/* The Display function define */
void Display_Result(void);
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
* main function performs following functions:
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
void main()
{
/* Start I2CMm */
I2CM_EnableInt();
I2CM_Start();
/* The LCD will display Standare info */
LCD_Char_Start();
LCD_Char_ClearDisplay();
LCD_Char_Position(0,0);
LCD_Char_PrintString("Hraw:");
LCD_Char_Position(1,0);
LCD_Char_PrintString("Traw:");
/* Enable global interrupts - required for I2CM */
CyGlobalIntEnable;
for(;;)
{
HYT_MR_Initialization();
HYT_DR_Operation();
Display_Result();
/* Delay introduced for ease of reading LCD */
CyDelay(3000u/*ms*/);
} /* End forever loop */
} /* End main */
/*******************************************************************************
* Function Name: HYT_DR_Operation
********************************************************************************
*
* Summary:
* Read HYT measurement result and put into HYT221_Read_Buff
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
void HYT_DR_Operation(void)
{
uint8 status = 0;
uint8 i;
status = I2CM_MasterSendStart(I2CM_SLAVE_ADDRESS, HYT_DR);
if(I2CM_MSTR_NO_ERROR == status) /* Check if transfer completed without errors */
for(i=0; i<4; i++)
{
if(i < 3)
{
HYT221_Read_Buff[i] = I2CM_MasterReadByte(I2CM_ACK_DATA);
}
else
{
HYT221_Read_Buff[i] = I2CM_MasterReadByte(I2CM_NAK_DATA);
}
}
else
{
LCD_Char_Position(0,6);
LCD_Char_PrintString("Bus Error");
LCD_Char_Position(1,6);
LCD_Char_PrintString("Bus Error");
}
I2CM_MasterSendStop(); /* Send Stop */
}
/*******************************************************************************
* Function Name: HYT_MR_Initialization
********************************************************************************
*
* Summary:
* Initializate HYT enable a measure cycle
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
void HYT_MR_Initialization(void)
{
uint8 status = 0;
status = I2CM_MasterSendStart(I2CM_SLAVE_ADDRESS, HYT_MR);
if(I2CM_MSTR_NO_ERROR == status) /* Check if transfer completed without errors */
{
//Delay to debug - If routine execute to here, only stop need to archive MR operation
CyDelay(1);
}
else
{
LCD_Char_Position(0,6);
LCD_Char_PrintString("Bus Error");
LCD_Char_Position(1,6);
LCD_Char_PrintString("Bus Error");
}
I2CM_MasterSendStop(); /* Send Stop */
}
/*******************************************************************************
* Function Name: Display_Result
********************************************************************************
*
* Summary:
* Update LCD with latest result
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
void Display_Result(void)
{
// value 0x141E;
LCD_Char_Position(0,6);
LCD_Char_PrintInt8(HYT221_Read_Buff[0] & 0x3f); //Mask HYT humidity the highest two status bits
LCD_Char_PrintInt8(HYT221_Read_Buff[1]);
LCD_Char_PrintString(" ");
LCD_Char_Position(1,6);
// sprintf(HYT221_Read_Buff, "0x%X", decimal_value);
// sscanf((HYT221_Read_Buff,%x,&Result);
// temp = (temp *100/16383);
// LCD_Char_Position(1,6);
// LCD_Char_PrintNumber(temp);
}
/* [] END OF FILE */