#include "PmodHYGRO.h" #include "PmodAQS.h" #include "sleep.h" #include "xil_cache.h" #include "xil_printf.h" #include "xparameters.h" #ifdef __MICROBLAZE__ #define TIMER_FREQ_HZ XPAR_CPU_M_AXI_DP_FREQ_HZ #else #define TIMER_FREQ_HZ 100000000 #endif PmodHYGRO myDevice; PmodAQS myDevice2; void DemoInitialize(); void DemoRun(); void DemoCleanup(); void EnableCaches(); void DisableCaches(); int main() { DemoInitialize(); DemoRun(); DemoCleanup(); return 0; } void DemoInitialize() { EnableCaches(); xil_printf("Init Started\n\r"); HYGRO_begin( &myDevice, XPAR_PMODHYGRO_0_AXI_LITE_IIC_BASEADDR, 0x40, // Chip address of PmodHYGRO IIC XPAR_PMODHYGRO_0_AXI_LITE_TMR_BASEADDR, XPAR_PMODHYGRO_0_DEVICE_ID, TIMER_FREQ_HZ // Clock frequency of AXI bus, used to convert timer data ); AQS_begin(&myDevice2, XPAR_PMODAQS_0_AXI_LITE_IIC_BASEADDR, 0x5B); // Chip address of PmodAQS IIC xil_printf("Init Done\n\r"); } void DemoCleanup() { DisableCaches(); } void DemoRun() { float temp_degc, hum_perrh; while (1) { temp_degc = HYGRO_getTemperature(&myDevice); //temp_degf = HYGRO_tempC2F(temp_degc); hum_perrh = HYGRO_getHumidity(&myDevice); xil_printf( "Temperature: %d.%02d deg C Humidity: %d.%02d RH\n\r", (int) temp_degc, ((int) (temp_degc * 100)) % 100, (int) hum_perrh, ((int) (hum_perrh * 100)) % 100 ); // %f does not work with xil_printf // instead, converting float to a pair of ints to display %.2f. // 1 sample per second maximum, as per 9.2.1 in HDC1080 reference manual u8 buf[5]; u16 eCO2; u16 TVOC; AQS_GetData(&myDevice2, buf); eCO2 = ((u16)buf[0] << 8) | ((u16)buf[1]); TVOC = ((u16)buf[2] << 8) | ((u16)buf[3]); xil_printf("The CO2 = %d ppm\n\r",eCO2); xil_printf("The VOC = %d ppb\n\r",TVOC); sleep(1); } } void EnableCaches() { #ifdef __MICROBLAZE__ #ifdef XPAR_MICROBLAZE_USE_ICACHE Xil_ICacheEnable(); #endif #ifdef XPAR_MICROBLAZE_USE_DCACHE Xil_DCacheEnable(); #endif #endif } void DisableCaches() { #ifdef __MICROBLAZE__ #ifdef XPAR_MICROBLAZE_USE_ICACHE Xil_ICacheDisable(); #endif #ifdef XPAR_MICROBLAZE_USE_DCACHE Xil_DCacheDisable(); #endif #endif }