summaryrefslogtreecommitdiff
path: root/usb-bmp280
diff options
context:
space:
mode:
authorBernhard Tittelbach <bernhard@tittelbach.org>2016-06-12 06:59:34 +0200
committerBernhard Tittelbach <bernhard@tittelbach.org>2016-06-12 06:59:34 +0200
commit7caffb47d6fc9426b2f65ad6bdd6197b324fb68a (patch)
tree6a41d218320bc1b92ccc6377f00caabe4b940cc6 /usb-bmp280
parentbetter lufa detect and reset (diff)
basic bmp280 lib (mostly adafruit reimplementation) and example
Diffstat (limited to 'usb-bmp280')
-rw-r--r--usb-bmp280/Makefile51
-rw-r--r--usb-bmp280/usb-bmp280.c120
2 files changed, 171 insertions, 0 deletions
diff --git a/usb-bmp280/Makefile b/usb-bmp280/Makefile
new file mode 100644
index 0000000..5bfc049
--- /dev/null
+++ b/usb-bmp280/Makefile
@@ -0,0 +1,51 @@
+##
+## spreadspace avr utils
+##
+##
+## Copyright (C) 2013-2016 Christian Pointner <equinox@spreadspace.org>
+## 2016 Bernhard Tittelbach <bernhard@tittelbach.org>
+##
+## This file is part of spreadspace avr utils.
+##
+## spreadspace avr utils 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 3 of the License, or
+## any later version.
+##
+## spreadspace avr utils 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 spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+##
+
+NAME := usb-bmp280
+BOARD_TYPE := arduinoProMicro
+OBJ := $(NAME).o
+LIBS := util led lufa-descriptor-usbserial usbio bmp280
+EXTERNAL_LIBS := lufa
+SPREADAVR_PATH := ..
+
+LUFA_PATH := $(SPREADAVR_PATH)/contrib/lufa-LUFA-151115
+LUFA_OPTS = -D USB_DEVICE_ONLY
+LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
+LUFA_OPTS += -D ORDERED_EP_CONFIG
+LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
+LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
+LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
+LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
+LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT
+
+LUFA_OPTS += -D USB_MANUFACTURER="L\"xro\""
+LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-bmp280 example\""
+
+LUFA_COMPONENTS := USB USBCLASS
+
+include $(SPREADAVR_PATH)/include.mk
+
+LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm
+AVRDUDE_PORT := $(shell $(SPREADAVR_PATH)/tools/detect_newest_acm)
+#AVRDUDE_PORT := $(shell $(SPREADAVR_PATH)/tools/detect_lufa_cdc 1)
+RESET_FUNC := $(SPREADAVR_PATH)/tools/reset_sparkfun
diff --git a/usb-bmp280/usb-bmp280.c b/usb-bmp280/usb-bmp280.c
new file mode 100644
index 0000000..0c19545
--- /dev/null
+++ b/usb-bmp280/usb-bmp280.c
@@ -0,0 +1,120 @@
+/*
+ * spreadspace avr utils - usb-bmp180 example
+ *
+ *
+ * Copyright (C) 2016 Bernhard Tittelbach <bernhard@tittelbach.org>
+ * basically this is refactored and enhanced code from:
+ * https://github.com/sparkfun/BMP180_Breakout_Arduino_Library
+ * Please buy the sparkfun people Beer when you see them!!!!
+ *
+ * This file is part of spreadspace avr utils.
+ *
+ * spreadspace avr utils 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 3 of the License, or
+ * any later version.
+ *
+ * spreadspace avr utils 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 spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <avr/io.h>
+#include <avr/wdt.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <stdio.h>
+
+#include <LUFA/Drivers/Peripheral/SPI.h>
+
+#include "util.h"
+#include "led.h"
+#include "usbio.h"
+#include "bmp280.h"
+
+#define ALTITUDE 353.0 // Altitude of Graz in Austria
+
+#define PIN_CS_S0 PD1
+#define REG_CS_S0 PIND
+#define PIN_CS_S1 PD0
+#define REG_CS_S1 PIND
+
+#define OP_SETBIT |=
+#define OP_CLEARBIT &= ~
+#define OP_CHECK &
+#define PIN_SW(PORTDDRREG, PIN, OP) PORTDDRREG OP (1 << PIN)
+
+#define PINREG(x) x
+#define DDRREG(x) *(&x+1)
+#define PORTREG(x) *(&x+2)
+
+#define HIGHv OP_SETBIT
+#define LOWv OP_CLEARBIT
+
+#define CS_SENSOR_0(LOWHIGH) (PIN_SW(PORTREG(REG_CS_S0),PIN_CS_S0,LOWHIGH))
+#define CS_SENSOR_1(LOWHIGH) (PIN_SW(PORTREG(REG_CS_S1),PIN_CS_S1,LOWHIGH))
+#define CS_SENSOR(x,LOWHIGH) CS_SENSOR_##x(LOWHIGH)
+
+void printCoeffs(bmp280_sensor *sensor)
+{
+ printf("Coeffients\r\n");
+ printf("T1: %d, T2: %d, T3: %d\r\n", sensor->dig_T1, sensor->dig_T2, sensor->dig_T3);
+ printf("P1: %d, P2: %d, P3: %d, P4: %d, P5: %d, P6: %d, P7: %d, P8: %d, P9: %d\r\n",sensor->dig_P1,sensor->dig_P2,sensor->dig_P3,sensor->dig_P4,sensor->dig_P5,sensor->dig_P6,sensor->dig_P7,sensor->dig_P8,sensor->dig_P9);
+ printf("H1: %d, H2: %d, H3: %d, H4: %d, H5: %d, H6: %d\r\n",sensor->dig_H1,sensor->dig_H2,sensor->dig_H3
+ ,sensor->dig_H4,sensor->dig_H5,sensor->dig_H6);
+}
+
+int main(void)
+{
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ cpu_init();
+ led_init();
+ usbio_init();
+ sei();
+
+ bmp280_sensor sensor0;
+ bmp280_sensor sensor1;
+
+ CS_SENSOR(0,HIGHv);
+ CS_SENSOR(1,HIGHv);
+ SPI_Init(BMP280_LUFA_SPIO_OPTIONS);
+ bmp280_init(&sensor0, &PORTREG(REG_CS_S0), PIN_CS_S0);
+ bmp280_init(&sensor1, &PORTREG(REG_CS_S1), PIN_CS_S1);
+
+ printf("BMP280 initialized");
+
+ for(;;) {
+
+ printf("\r\n== Sensor 0 ==\r\n");
+ printCoeffs(&sensor0);
+ float temp = bmp280_readTemp(&sensor0);
+ float pressure = bmp280_readPressure(&sensor0);
+ printf("\r\nPressure: %.2f Pa @ %.2f degC\r\n", pressure, temp);
+
+ printf("\r\n== Sensor 1 ==\r\n");
+ printCoeffs(&sensor1);
+ temp = bmp280_readTemp(&sensor1);
+ pressure = bmp280_readPressure(&sensor1);
+ printf("\r\nPressure: %.2f Pa @ %.2f degC\r\n", pressure, temp);
+
+ usbio_task();
+
+ int16_t BytesReceived = usbio_bytes_received();
+ while(BytesReceived > 0) {
+ int ReceivedByte = fgetc(stdin);
+ if(ReceivedByte != EOF) {
+ if (ReceivedByte == '!')
+ reset2bootloader();
+ }
+ BytesReceived--;
+ }
+
+ _delay_ms(2000); // Pause for 5 seconds.
+ }
+}