From: Nathael Pajani Date: Tue, 27 Sep 2016 21:52:50 +0000 (+0200) Subject: Adding VEML6070 I2C UV sensor example application X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=1124ab501417e6c5f8c6440b7eb252692c4eeb5e;p=soft%2Flpc122x%2Fexamples Adding VEML6070 I2C UV sensor example application --- diff --git a/i2c_uv/Makefile b/i2c_uv/Makefile new file mode 100644 index 0000000..954c63f --- /dev/null +++ b/i2c_uv/Makefile @@ -0,0 +1,13 @@ +# Makefile for "base" apps +# This includes apps for the GPIO Demo Module and for the LPC1224-BO board. + +MODULE = $(shell basename $(shell cd .. && pwd && cd -)) +NAME = $(shell basename $(CURDIR)) + +.PHONY: $(NAME).bin +$(NAME).bin: + @make -C ../../.. --no-print-directory NAME=$(NAME) MODULE=$(MODULE) apps/$(MODULE)/$(NAME)/$@ + +clean mrproper: + @make -C ../../.. --no-print-directory $@ + diff --git a/i2c_uv/README b/i2c_uv/README new file mode 100644 index 0000000..3401639 --- /dev/null +++ b/i2c_uv/README @@ -0,0 +1,27 @@ +VEML6070 I2C UV sensor example + +Copyright 2016 Nathael Pajani + + +/* **************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +This example shows the support of the VEML6070 I2C UV sensor + +Periodic conversions (raw conversion value) are sent on UART0 using the +following frame format : +UV: 0x1b60 + diff --git a/i2c_uv/main.c b/i2c_uv/main.c new file mode 100644 index 0000000..490c333 --- /dev/null +++ b/i2c_uv/main.c @@ -0,0 +1,146 @@ +/**************************************************************************** + * apps/base/i2c_uv/main.c + * + * VEML6070 I2C UV sensor example + * + * Copyright 2016 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + + +#include "core/system.h" +#include "core/systick.h" +#include "core/pio.h" +#include "lib/stdio.h" +#include "drivers/i2c.h" +#include "drivers/serial.h" +#include "drivers/gpio.h" +#include "extdrv/status_led.h" + +#include "extdrv/veml6070_uv_sensor.h" + + +#define MODULE_VERSION 0x04 +#define MODULE_NAME "GPIO Demo Module" + + +#define SELECTED_FREQ FREQ_SEL_48MHz + +/***************************************************************************** */ +/* Pins configuration */ +/* pins blocks are passed to set_pins() for pins configuration. + * Unused pin blocks can be removed safely with the corresponding set_pins() call + * All pins blocks may be safelly merged in a single block for single set_pins() call.. + */ +const struct pio_config common_pins[] = { + /* UART 0 */ + { LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL }, + { LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL }, + /* I2C 0 */ + { LPC_I2C0_SCL_PIO_0_10, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) }, + { LPC_I2C0_SDA_PIO_0_11, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) }, + ARRAY_LAST_PIO, +}; + +const struct pio status_led_green = LPC_GPIO_1_4; +const struct pio status_led_red = LPC_GPIO_1_5; + + +/***************************************************************************** */ +/* UV */ + +/* The I2C UV light sensor is at addresses 0x70, 0x71 and 0x73 */ +/* Note : These are 8bits address */ +#define VEML6070_ADDR 0x70 +struct veml6070_sensor_config veml6070_sensor = { + .addr = VEML6070_ADDR, +}; + +void uv_config(int uart_num) +{ + int ret = 0; + + /* UV sensor */ + ret = veml6070_configure(&veml6070_sensor); + if (ret != 0) { + uprintf(uart_num, "UV config error: %d\n", ret); + } +} + +void uv_display(int uart_num) +{ + uint16_t uv_raw = 0; + int ret = 0; + + ret = veml6070_sensor_read(&veml6070_sensor, &uv_raw); + if (ret != 0) { + uprintf(uart_num, "UV read error: %d\n", ret); + } else { + uprintf(uart_num, "UV: 0x%04x\n", uv_raw); + } +} + + + +/***************************************************************************** */ +void system_init() +{ + /* Stop the watchdog */ + startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */ + system_brown_out_detection_config(0); /* No ADC used */ + system_set_default_power_state(); + clock_config(SELECTED_FREQ); + set_pins(common_pins); + gpio_on(); + status_led_config(&status_led_green, &status_led_red); + /* System tick timer MUST be configured and running in order to use the sleeping + * functions */ + systick_timer_on(1); /* 1ms */ + systick_start(); +} + +/* Define our fault handler. This one is not mandatory, the dummy fault handler + * will be used when it's not overridden here. + * Note : The default one does a simple infinite loop. If the watchdog is deactivated + * the system will hang. + */ +void fault_info(const char* name, uint32_t len) +{ + uprintf(UART0, name); + while (1); +} + + + +/***************************************************************************** */ +int main(void) +{ + system_init(); + uart_on(UART0, 115200, NULL); + + i2c_on(I2C0, I2C_CLK_100KHz, I2C_MASTER); + + /* Configure UV sensor */ + uv_config(UART0); + + while (1) { + chenillard(250); + uv_display(UART0); + } + return 0; +} +