[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paparazzi-commits] [4262] Add Maxim MAX11040 SPI and VTI SCP1000 I2C
From: |
Martin Mueller |
Subject: |
[paparazzi-commits] [4262] Add Maxim MAX11040 SPI and VTI SCP1000 I2C |
Date: |
Sat, 17 Oct 2009 15:18:00 +0000 |
Revision: 4262
http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=4262
Author: mmm
Date: 2009-10-17 15:17:59 +0000 (Sat, 17 Oct 2009)
Log Message:
-----------
Add Maxim MAX11040 SPI and VTI SCP1000 I2C
Modified Paths:
--------------
paparazzi3/trunk/conf/messages.xml
paparazzi3/trunk/sw/airborne/main_ap.c
paparazzi3/trunk/sw/airborne/main_logger.c
Added Paths:
-----------
paparazzi3/trunk/conf/airframes/logger_sd_adc.xml
paparazzi3/trunk/sw/airborne/arm7/max11040_hw.c
paparazzi3/trunk/sw/airborne/arm7/max11040_hw.h
paparazzi3/trunk/sw/airborne/arm7/vic_slots.txt
paparazzi3/trunk/sw/airborne/baro_scp_i2c.c
paparazzi3/trunk/sw/airborne/baro_scp_i2c.h
paparazzi3/trunk/sw/airborne/max11040.c
paparazzi3/trunk/sw/airborne/max11040.h
Added: paparazzi3/trunk/conf/airframes/logger_sd_adc.xml
===================================================================
--- paparazzi3/trunk/conf/airframes/logger_sd_adc.xml
(rev 0)
+++ paparazzi3/trunk/conf/airframes/logger_sd_adc.xml 2009-10-17 15:17:59 UTC
(rev 4262)
@@ -0,0 +1,107 @@
+<!DOCTYPE airframe SYSTEM "airframe.dtd">
+
+<!--
+
+ Connects a microSD card to the SPI port of the Paparazzi Tiny. Keep cables
+ short, microSD card can be directly soldered to Molex cable. For now only
+ non SDHC SD cards (<= 2GB) are supported. address@hidden
+
+ microSD TinyV2 SPI J3
+ 8 nc
+ 7 DO 5 MISO
+ 6 GND 1 GND
+ 5 CLK 7 SCK
+ 4 Vcc 2 +3V3
+ 3 DI 4 MOSI
+ 2 CS 3 SSEL
+ 1 nc
+
+ Looking onto the gold plated connector side of the microSD card:
+
+ ###############
+ I 8
+ I 7
+ I 6
+ I 5
+ I 4
+ I 3
+ I 2
+ I 1
+ ###### ##
+ \ I \
+ ## ##
+
+-->
+
+<airframe name="Logger">
+
+ <section name="MICROMAG">
+
+ <define name="MM_SS_PIN" value="20"/>
+ <define name="MM_SS_IODIR" value="IO0DIR"/>
+ <define name="MM_SS_IOSET" value="IO0SET"/>
+ <define name="MM_SS_IOCLR" value="IO0CLR"/>
+
+ <define name="MM_RESET_PIN" value="29"/>
+ <define name="MM_RESET_IODIR" value="IO0DIR"/>
+ <define name="MM_RESET_IOSET" value="IO0SET"/>
+ <define name="MM_RESET_IOCLR" value="IO0CLR"/>
+
+ <define name="MM_DRDY_PINSEL" value="PINSEL1"/>
+ <define name="MM_DRDY_PINSEL_BIT" value="0"/>
+ <define name="MM_DRDY_PINSEL_VAL" value="1"/>
+ <define name="MM_DRDY_EINT" value="0"/>
+ <define name="MM_DRDY_VIC_IT" value="VIC_EINT0"/>
+
+ </section>
+
+ <makefile>
+
+CONFIG = \"tiny_2_1_1_usb.h\"
+
+include $(PAPARAZZI_SRC)/conf/autopilot/tiny.makefile
+
+FLASH_MODE=IAP
+
+ap.CFLAGS += -DBOARD_CONFIG=$(CONFIG) -DLED -DLOGGER
+ap.srcs = sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c
main_logger_adc.c
+
+#choose one
+ap.CFLAGS += -DLOG_XBEE
+#ap.CFLAGS += -DLOG_PPRZ
+
+#set the speed
+ap.CFLAGS += -DUSE_UART0 -DUART0_BAUD=B57600 -DUSE_UART0_RX_ONLY
+ap.CFLAGS += -DUSE_UART1 -DUART1_BAUD=B57600 -DUSE_UART1_RX_ONLY
+ap.srcs += $(SRC_ARCH)/uart_hw.c
+
+#efsl
+ap.CFLAGS += -I $(SRC_ARCH)/efsl/inc -I $(SRC_ARCH)/efsl/conf
+
+ap.srcs += $(SRC_ARCH)/efsl/src/efs.c $(SRC_ARCH)/efsl/src/plibc.c
+ap.srcs += $(SRC_ARCH)/efsl/src/disc.c $(SRC_ARCH)/efsl/src/partition.c
+ap.srcs += $(SRC_ARCH)/efsl/src/time.c $(SRC_ARCH)/efsl/src/fs.c
+ap.srcs += $(SRC_ARCH)/efsl/src/fat.c $(SRC_ARCH)/efsl/src/file.c
+ap.srcs += $(SRC_ARCH)/efsl/src/dir.c $(SRC_ARCH)/efsl/src/ls.c
+ap.srcs += $(SRC_ARCH)/efsl/src/mkfs.c $(SRC_ARCH)/efsl/src/debug.c
+ap.srcs += $(SRC_ARCH)/efsl/src/ioman.c $(SRC_ARCH)/efsl/src/ui.c
+ap.srcs += $(SRC_ARCH)/efsl/src/extract.c
+ap.srcs += $(SRC_ARCH)/efsl/src/interfaces/lpc2000_spi.c
+ap.srcs += $(SRC_ARCH)/efsl/src/interfaces/sd.c
+#ap.srcs += $(SRC_ARCH)/efsl/src/interfaces/lpc2000_dbg_printf.c
+
+#usb mass storage
+ap.CFLAGS += -DUSE_USB_MSC
+ap.CFLAGS += -I $(SRC_ARCH)/lpcusb -I $(SRC_ARCH)/lpcusb/examples
+
+ap.srcs += $(SRC_ARCH)/usb_msc_hw.c
+ap.srcs += $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbcontrol.c
$(SRC_ARCH)/lpcusb/usbstdreq.c $(SRC_ARCH)/lpcusb/usbinit.c
+ap.srcs += $(SRC_ARCH)/lpcusb/examples/msc_bot.c
$(SRC_ARCH)/lpcusb/examples/msc_scsi.c
$(SRC_ARCH)/lpcusb/examples/blockdev_sd.c
$(SRC_ARCH)/lpcusb/examples/lpc2000_spi0.c
+
+ap.CFLAGS += -DMICROMAG_DRDY_VIC_SLOT=9 -DSSP_VIC_SLOT=11 -DUSE_MAX11040
+ap.srcs += max11040.c $(SRC_ARCH)/max11040_hw.c
+
+ </makefile>
+
+</airframe>
+
Modified: paparazzi3/trunk/conf/messages.xml
===================================================================
--- paparazzi3/trunk/conf/messages.xml 2009-10-17 07:29:30 UTC (rev 4261)
+++ paparazzi3/trunk/conf/messages.xml 2009-10-17 15:17:59 UTC (rev 4262)
@@ -341,7 +341,45 @@
<field name="ref_pitch_angle" type="float" unit="rad" alt_unit="deg"
alt_unit_coef="57.3"/>
</message>
+ <message name="TURB_PRESSURE_RAW" id="61">
+ <field name="ch_0" type="int32" unit="adc"/>
+ <field name="ch_1" type="int32" unit="adc"/>
+ <field name="ch_2" type="int32" unit="adc"/>
+ <field name="ch_3" type="int32" unit="adc"/>
+ <field name="ch_4" type="int32" unit="adc"/>
+ <field name="ch_5" type="int32" unit="adc"/>
+ <field name="ch_6" type="int32" unit="adc"/>
+ <field name="ch_7" type="int32" unit="adc"/>
+ <field name="ch_8" type="int32" unit="adc"/>
+ <field name="ch_9" type="int32" unit="adc"/>
+ <field name="ch_10" type="int32" unit="adc"/>
+ <field name="ch_11" type="int32" unit="adc"/>
+ <field name="ch_12" type="int32" unit="adc"/>
+ <field name="ch_13" type="int32" unit="adc"/>
+ <field name="ch_14" type="int32" unit="adc"/>
+ <field name="ch_15" type="int32" unit="adc"/>
+ </message>
+ <message name="TURB_PRESSURE_VOLTAGE" id="62">
+ <field name="ch_1_p" type="float"/>
+ <field name="ch_1_t" type="float"/>
+ <field name="ch_2_p" type="float"/>
+ <field name="ch_2_t" type="float"/>
+ <field name="ch_3_p" type="float"/>
+ <field name="ch_3_t" type="float"/>
+ <field name="ch_4_p" type="float"/>
+ <field name="ch_4_t" type="float"/>
+ <field name="ch_5_p" type="float"/>
+ <field name="ch_5_t" type="float"/>
+ <field name="ch_6_p" type="float"/>
+ <field name="ch_6_t" type="float"/>
+ <field name="ch_7_p" type="float"/>
+ <field name="ch_7_t" type="float"/>
+ <field name="gnd1" type="float"/>
+ <field name="gnd2" type="float"/>
+ </message>
+
+
<message name="PPM" id="100">
<field name="ppm_rate" type="uint8"></field>
<field name="values" type="uint16[]" unit="ticks"/>
Added: paparazzi3/trunk/sw/airborne/arm7/max11040_hw.c
===================================================================
--- paparazzi3/trunk/sw/airborne/arm7/max11040_hw.c
(rev 0)
+++ paparazzi3/trunk/sw/airborne/arm7/max11040_hw.c 2009-10-17 15:17:59 UTC
(rev 4262)
@@ -0,0 +1,76 @@
+
+/* MAX11040 connected on SPI1
+
+ SS on P0.20 (SSEL)
+ DRDY on P0.16 (EINT0)
+*/
+
+
+#include "led.h"
+#include "max11040.h"
+
+#ifdef LOGGER
+extern unsigned int getclock(void);
+#endif
+
+volatile uint8_t num_irqs = 0;
+
+static void EXTINT_ISR(void) __attribute__((naked));
+
+void max11040_hw_init( void ) {
+
+ /* configure DRDY pin */
+ /* connected pin to EXINT */
+ MAXM_DRDY_PINSEL |= MAXM_DRDY_PINSEL_VAL << MAXM_DRDY_PINSEL_BIT;
+ SetBit(EXTMODE, MAXM_DRDY_EINT); /* EINT is edge trigered */
+ ClearBit(EXTPOLAR, MAXM_DRDY_EINT); /* EINT is trigered on falling edge */
+ SetBit(EXTINT, MAXM_DRDY_EINT); /* clear pending EINT */
+
+ /* initialize interrupt vector */
+ VICIntSelect &= ~VIC_BIT( MAXM_DRDY_VIC_IT ); /*
select EINT as IRQ source */
+ VICIntEnable = VIC_BIT( MAXM_DRDY_VIC_IT ); /*
enable it */
+ _VIC_CNTL(MAX11040_DRDY_VIC_SLOT) = VIC_ENABLE | MAXM_DRDY_VIC_IT;
+ _VIC_ADDR(MAX11040_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; /*
address of the ISR */
+}
+
+void EXTINT_ISR(void) {
+ ISR_ENTRY();
+
+ if (num_irqs++ == 5)
+ {
+ /* switch SSEL P0.20 to be used as GPIO */
+ PINSEL1 &= ~(3 << 8);
+ IO0DIR |= 1 << 20;
+ max11040_status = MAX11040_DATA2;
+ }
+
+ if (max11040_status == MAX11040_DATA2) {
+
+//LED_TOGGLE(2);
+//LED_TOGGLE(3);
+
+#ifdef LOGGER
+ max11040_timestamp = getclock();
+#endif
+
+ MaxmSelect();
+
+ /* read data */
+ SSP_Send(0xF0);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+
+ max11040_count = 0;
+ }
+
+ /* clear EINT */
+ SetBit(EXTINT, MAXM_DRDY_EINT);
+
+ VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
+ ISR_EXIT();
+}
+
Added: paparazzi3/trunk/sw/airborne/arm7/max11040_hw.h
===================================================================
--- paparazzi3/trunk/sw/airborne/arm7/max11040_hw.h
(rev 0)
+++ paparazzi3/trunk/sw/airborne/arm7/max11040_hw.h 2009-10-17 15:17:59 UTC
(rev 4262)
@@ -0,0 +1,61 @@
+
+#ifndef MAX11040_HW_H
+#define MAX11040_HW_H
+
+
+#include "LPC21xx.h"
+#include "interrupt_hw.h"
+
+#include "ssp_hw.h"
+#include BOARD_CONFIG
+
+#include "airframe.h"
+
+#define MAXM_DIVISOR_128 2
+#define MAXM_DIVISOR_256 3
+#define MAXM_DIVISOR_512 4
+#define MAXM_DIVISOR_1024 5
+
+#define MAXM_DIVISOR MAXM_DIVISOR_512
+
+/* ssp input clock 468.75kHz, clock that divided by SCR+1 */
+#define SSP_CLOCK 468750
+
+/* SSPCR0 settings */
+#define SSP_DDS 0x07 << 0 /* data size : 8 bits */
+#define SSP_FRF 0x00 << 4 /* frame format : SPI */
+#define SSP_CPOL 0x00 << 6 /* clock polarity : data captured on first
clock transition */
+#define SSP_CPHA 0x01 << 7 /* clock phase : SCK idles low */
+#define SSP_SCR 0x00 << 8 /* serial clock rate : divide by 16 */
+
+/* SSPCR1 settings */
+#define SSP_LBM 0x00 << 0 /* loopback mode : disabled */
+#define SSP_SSE 0x00 << 1 /* SSP enable : disabled */
+#define SSP_MS 0x00 << 2 /* master slave mode : master */
+#define SSP_SOD 0x00 << 3 /* slave output disable : don't care when master */
+
+#define SSPCR0_VAL (SSP_DDS | SSP_FRF | SSP_CPOL | SSP_CPHA | SSP_SCR )
+#define SSPCR1_VAL (SSP_LBM | SSP_SSE | SSP_MS | SSP_SOD )
+
+#define SSP_PINSEL1_SCK (2<<2)
+#define SSP_PINSEL1_MISO (2<<4)
+#define SSP_PINSEL1_MOSI (2<<6)
+#define SSP_PINSEL1_SSEL (2<<8)
+
+#define SSP_Enable() SetBit(SSPCR1, SSE);
+#define SSP_Disable() ClearBit(SSPCR1, SSE);
+#define SSP_EnableRxi() SetBit(SSPIMSC, RXIM)
+#define SSP_DisableRxi() ClearBit(SSPIMSC, RXIM)
+#define SSP_ClearRxi() SetBit(SSPICR, RXIM);
+#define SSP_EnableTxi() SetBit(SSPIMSC, TXIM)
+#define SSP_DisableTxi() ClearBit(SSPIMSC, TXIM)
+#define SSP_ClearTxi() SetBit(SSPICR, TXIM);
+#define SSP_EnableRti() SetBit(SSPIMSC, RTIM);
+#define SSP_DisableRti() ClearBit(SSPIMSC, RTIM);
+#define SSP_ClearRti() SetBit(SSPICR, RTIC);
+
+#define MaxmSelect() SetBit(MAXM_SS_IOCLR, MAXM_SS_PIN)
+#define MaxmUnselect() SetBit(MAXM_SS_IOSET, MAXM_SS_PIN)
+
+
+#endif /* MAX11040_HW_H */
Added: paparazzi3/trunk/sw/airborne/arm7/vic_slots.txt
===================================================================
--- paparazzi3/trunk/sw/airborne/arm7/vic_slots.txt
(rev 0)
+++ paparazzi3/trunk/sw/airborne/arm7/vic_slots.txt 2009-10-17 15:17:59 UTC
(rev 4262)
@@ -0,0 +1,15 @@
+ 1 TIMER0_VIC_SLOT
+ 2 AD0_VIC_SLOT
+ 4 AD1_VIC_SLOT
+ 5 UART0_VIC_SLOT
+ 6 UART1_VIC_SLOT
+ 9 I2C0_VIC_SLOT
+ I2C1_VIC_SLOT
+11 SSP_VIC_SLOT
+11 MS2001_DRDY_VIC_SLOT
+
+12 MICROMAG_DRDY_VIC_SLOT
+12 MAX11040_DRDY_VIC_SLOT
+
+?? MAX1167_EOC_VIC_SLOT
+
Added: paparazzi3/trunk/sw/airborne/baro_scp_i2c.c
===================================================================
--- paparazzi3/trunk/sw/airborne/baro_scp_i2c.c (rev 0)
+++ paparazzi3/trunk/sw/airborne/baro_scp_i2c.c 2009-10-17 15:17:59 UTC (rev
4262)
@@ -0,0 +1,300 @@
+
+/** \file baro_scp_i2c.c
+ * \brief VTI SCP1000 I2C sensor interface
+ *
+ * This reads the values for pressure and temperature from the VTI SCP1000
sensor through I2C.
+ */
+
+
+#include "baro_scp_i2c.h"
+
+#include "i2c.h"
+#include "led.h"
+
+#include <string.h>
+
+uint8_t baro_scp_status;
+uint32_t baro_scp_pressure;
+uint16_t baro_scp_temperature;
+bool_t baro_scp_available;
+volatile bool_t baro_scp_i2c_done;
+
+#define SCP1000_SLAVE_ADDR 0x22
+
+
+static void baro_scp_start_high_res_measurement(void) {
+ /* write 0x0A to 0x03 */
+ i2c0_buf[0] = 0x03;
+ i2c0_buf[1] = 0x0A;
+ i2c0_transmit(SCP1000_SLAVE_ADDR, 2, &baro_scp_i2c_done);
+}
+
+void baro_scp_init( void ) {
+ baro_scp_status = BARO_SCP_IDLE;
+ baro_scp_i2c_done = FALSE;
+ baro_scp_start_high_res_measurement();
+}
+
+void baro_scp_periodic( void ) {
+ if (baro_scp_i2c_done) {
+ if (baro_scp_status == BARO_SCP_IDLE) {
+
+ /* initial measurement */
+
+ /* start two byte temperature */
+ i2c0_buf[0] = 0x81;
+ baro_scp_status = BARO_SCP_RD_TEMP;
+ baro_scp_i2c_done = FALSE;
+ i2c0_transceive(SCP1000_SLAVE_ADDR, 1, 2, &baro_scp_i2c_done);
+//LED_ON(2);
+ }
+
+ else if (baro_scp_status == BARO_SCP_RD_TEMP) {
+
+ /* read two byte temperature */
+ baro_scp_temperature = i2c0_buf[0] << 8;
+ baro_scp_temperature |= i2c0_buf[1];
+ if (baro_scp_temperature & 0x2000) {
+ baro_scp_temperature |= 0xC000;
+ }
+ baro_scp_temperature *= 5;
+
+ /* start one byte msb pressure */
+ i2c0_buf[0] = 0x7F;
+ baro_scp_status = BARO_SCP_RD_PRESS_0;
+ baro_scp_i2c_done = FALSE;
+ i2c0_transceive(SCP1000_SLAVE_ADDR, 1, 1, &baro_scp_i2c_done);
+ }
+
+ else if (baro_scp_status == BARO_SCP_RD_PRESS_0) {
+
+ /* read one byte pressure */
+ baro_scp_pressure = i2c0_buf[0] << 16;
+
+ /* start two byte lsb pressure */
+ i2c0_buf[0] = 0x80;
+ baro_scp_status = BARO_SCP_RD_PRESS_1;
+ baro_scp_i2c_done = FALSE;
+ i2c0_transceive(SCP1000_SLAVE_ADDR, 1, 2, &baro_scp_i2c_done);
+ }
+
+ else if (baro_scp_status == BARO_SCP_RD_PRESS_1) {
+
+ /* read two byte pressure */
+ baro_scp_pressure |= i2c0_buf[0] << 8;
+ baro_scp_pressure |= i2c0_buf[1];
+ baro_scp_pressure *= 25;
+ baro_scp_available = TRUE;
+//LED_TOGGLE(2);
+
+ /* start two byte temperature */
+ i2c0_buf[0] = 0x81;
+ baro_scp_status = BARO_SCP_RD_TEMP;
+ baro_scp_i2c_done = FALSE;
+ i2c0_transceive(SCP1000_SLAVE_ADDR, 1, 2, &baro_scp_i2c_done);
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+//////////
+#if 0
+
+
+#include "std.h"
+#include "init_hw.h"
+#include "sys_time.h"
+#include "led.h"
+#include "interrupt_hw.h"
+
+#include "uart.h"
+#include "messages.h"
+#include "downlink.h"
+
+#include "spi_hw.h"
+
+#include "baro_scp.h"
+
+#define STA_UNINIT 0
+#define STA_INITIALISING 1
+#define STA_IDLE 2
+
+uint8_t baro_scp_status;
+uint32_t baro_scp_pressure;
+uint16_t baro_scp_temperature;
+bool_t baro_scp_available;
+
+static void baro_scp_start_high_res_measurement(void);
+static void baro_scp_read(void);
+static void EXTINT_ISR(void) __attribute__((naked));
+static void SPI1_ISR(void) __attribute__((naked));
+
+void baro_scp_periodic(void) {
+ if (baro_scp_status == STA_UNINIT && cpu_time_sec > 1) {
+ baro_scp_start_high_res_measurement();
+ baro_scp_status = STA_INITIALISING;
+ }
+}
+
+/* ssp input clock 468.75kHz, clock that divided by SCR+1 */
+#define SSP_CLOCK 468750
+
+/* SSPCR0 settings */
+#define SSP_DDS 0x07 << 0 /* data size : 8 bits */
+#define SSP_FRF 0x00 << 4 /* frame format : SPI */
+#define SSP_CPOL 0x00 << 6 /* clock polarity : data captured on first
clock transition */
+#define SSP_CPHA 0x00 << 7 /* clock phase : SCK idles low */
+#define SSP_SCR 0x0F << 8 /* serial clock rate : divide by 16 */
+
+/* SSPCR1 settings */
+#define SSP_LBM 0x00 << 0 /* loopback mode : disabled */
+#define SSP_SSE 0x00 << 1 /* SSP enable : disabled */
+#define SSP_MS 0x00 << 2 /* master slave mode : master */
+#define SSP_SOD 0x00 << 3 /* slave output disable : don't care when master */
+
+#define SS_PIN 20
+#define SS_IODIR IO0DIR
+#define SS_IOSET IO0SET
+#define SS_IOCLR IO0CLR
+
+#define ScpSelect() SetBit(SS_IOCLR,SS_PIN)
+#define ScpUnselect() SetBit(SS_IOSET,SS_PIN)
+
+void baro_scp_init( void ) {
+ /* setup pins for SSP (SCK, MISO, MOSI) */
+ PINSEL1 |= 2 << 2 | 2 << 4 | 2 << 6;
+
+ /* setup SSP */
+ SSPCR0 = SSP_DDS | SSP_FRF | SSP_CPOL | SSP_CPHA | SSP_SCR;
+ SSPCR1 = SSP_LBM | SSP_MS | SSP_SOD;
+ /* set prescaler for SSP clock */
+ SSPCPSR = PCLK/SSP_CLOCK;
+
+ /* initialize interrupt vector */
+ VICIntSelect &= ~VIC_BIT(VIC_SPI1); // SPI1 selected as IRQ
+ VICIntEnable = VIC_BIT(VIC_SPI1); // SPI1 interrupt enabled
+ VICVectCntl7 = VIC_ENABLE | VIC_SPI1;
+ VICVectAddr7 = (uint32_t)SPI1_ISR; // address of the ISR
+
+ /* configure SS pin */
+ SetBit(SS_IODIR, SS_PIN); /* pin is output */
+ ScpUnselect(); /* pin idles high */
+
+ /* configure DRDY pin */
+ /* connected pin to EXINT */
+ SPI1_DRDY_PINSEL |= SPI1_DRDY_PINSEL_VAL << SPI1_DRDY_PINSEL_BIT;
+ SetBit(EXTMODE, SPI1_DRDY_EINT); /* EINT is edge trigered */
+ SetBit(EXTPOLAR,SPI1_DRDY_EINT); /* EINT is trigered on rising edge */
+ SetBit(EXTINT,SPI1_DRDY_EINT); /* clear pending EINT */
+
+ /* initialize interrupt vector */
+ VICIntSelect &= ~VIC_BIT( SPI1_DRDY_VIC_IT ); /* select EINT as IRQ source
*/
+ VICIntEnable = VIC_BIT( SPI1_DRDY_VIC_IT ); /* enable it */
+ VICVectCntl11 = VIC_ENABLE | SPI1_DRDY_VIC_IT;
+ VICVectAddr11 = (uint32_t)EXTINT_ISR; // address of the ISR
+
+ baro_scp_status = STA_UNINIT;
+}
+
+void SPI1_ISR(void) {
+ ISR_ENTRY();
+
+ if (baro_scp_status == STA_INITIALISING) {
+ uint8_t foo1 = SSPDR;
+ uint8_t foo2 = SSPDR;
+ baro_scp_status = STA_IDLE;
+ foo1=foo2;
+ }
+ else if (baro_scp_status == STA_IDLE) {
+
+ uint8_t foo0 = SSPDR;
+ baro_scp_temperature = SSPDR<<8;
+ baro_scp_temperature += SSPDR;
+ if (baro_scp_temperature & 0x2000) {
+ baro_scp_temperature |= 0xC000;
+ }
+ baro_scp_temperature *= 5;
+
+ uint8_t foo1 = SSPDR;
+ uint32_t datard8 = SSPDR<<16;
+ uint8_t foo2 = SSPDR;
+ baro_scp_pressure = SSPDR<<8;
+ baro_scp_pressure += SSPDR;
+ baro_scp_pressure += datard8;
+ baro_scp_pressure *= 25;
+ baro_scp_available = TRUE;
+ foo1=foo2;
+ foo0=foo2;
+ }
+
+ ScpUnselect();
+ SpiClearRti();
+ SpiDisable();
+
+ VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
+ ISR_EXIT();
+}
+
+void EXTINT_ISR(void) {
+ ISR_ENTRY();
+ baro_scp_read();
+
+ SetBit(EXTINT,SPI1_DRDY_EINT); /* clear EINT2 */
+ VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
+ ISR_EXIT();
+}
+
+/* write 0x0A to 0x03 */
+static void baro_scp_start_high_res_measurement(void) {
+ uint8_t cmd = 0x03<<2|0x02;
+ uint8_t data = 0x0A;
+ ScpSelect();
+ SSPDR = cmd;
+ SSPDR = data;
+ SpiEnableRti();
+ SpiEnable();
+}
+
+/* read 0x21 (TEMP), 0x1F (MSB) and 0x20 (LSB) */
+static void baro_scp_read(void) {
+ uint8_t cmd0 = 0x21 << 2;
+ uint8_t cmd1 = 0x1F << 2;
+ uint8_t cmd2 = 0x20 << 2;
+ ScpSelect();
+ SSPDR = cmd0;
+ SSPDR = 0;
+ SSPDR = 0;
+ SSPDR = cmd1;
+ SSPDR = 0;
+ SSPDR = cmd2;
+ SSPDR = 0;
+ SSPDR = 0;
+ SpiEnable();
+}
+
+#endif
+//////////
+
+
Property changes on: paparazzi3/trunk/sw/airborne/baro_scp_i2c.c
___________________________________________________________________
Added: svn:executable
+ *
Added: paparazzi3/trunk/sw/airborne/baro_scp_i2c.h
===================================================================
--- paparazzi3/trunk/sw/airborne/baro_scp_i2c.h (rev 0)
+++ paparazzi3/trunk/sw/airborne/baro_scp_i2c.h 2009-10-17 15:17:59 UTC (rev
4262)
@@ -0,0 +1,20 @@
+#ifndef BARO_SCP_H
+#define BARO_SCP_H
+
+#include "std.h"
+
+#define BARO_SCP_IDLE 0
+#define BARO_SCP_RD_TEMP 1
+#define BARO_SCP_RD_PRESS_0 2
+#define BARO_SCP_RD_PRESS_1 3
+
+extern uint8_t baro_scp_status;
+extern uint32_t baro_scp_pressure;
+extern uint16_t baro_scp_temperature;
+extern bool_t baro_scp_available;
+extern volatile bool_t baro_scp_i2c_done;
+
+void baro_scp_init(void);
+void baro_scp_periodic(void);
+
+#endif
Property changes on: paparazzi3/trunk/sw/airborne/baro_scp_i2c.h
___________________________________________________________________
Added: svn:executable
+ *
Modified: paparazzi3/trunk/sw/airborne/main_ap.c
===================================================================
--- paparazzi3/trunk/sw/airborne/main_ap.c 2009-10-17 07:29:30 UTC (rev
4261)
+++ paparazzi3/trunk/sw/airborne/main_ap.c 2009-10-17 15:17:59 UTC (rev
4262)
@@ -115,6 +115,10 @@
#include "baro_MS5534A.h"
#endif
+#ifdef USE_MAX11040
+#include "max11040.h"
+#endif
+
#ifdef TRAFFIC_INFO
#include "traffic_info.h"
#endif
@@ -538,6 +542,44 @@
break;
#endif
+#ifdef USE_MAX11040
+ case 5:
+ {
+ float max11040_values_f[16];
+ int i;
+
+ if (max11040_data == MAX11040_DATA_AVAILABLE) {
+ LED_TOGGLE(3);
+ for (i=0; i<16; i++) {
+ max11040_values_f[i] = (max11040_values[i] * 2.2) / 8388608.0;
+ }
+
+ DOWNLINK_SEND_TURB_PRESSURE_VOLTAGE(
+ DefaultChannel,
+ &max11040_values_f[0],
+ &max11040_values_f[1],
+ &max11040_values_f[2],
+ &max11040_values_f[3],
+ &max11040_values_f[4],
+ &max11040_values_f[5],
+ &max11040_values_f[6],
+ &max11040_values_f[7],
+ &max11040_values_f[8],
+ &max11040_values_f[9],
+ &max11040_values_f[10],
+ &max11040_values_f[11],
+ &max11040_values_f[12],
+ &max11040_values_f[13],
+ &max11040_values_f[14],
+ &max11040_values_f[15] );
+ max11040_data = MAX11040_IDLE;
+ }
+ }
+ break;
+
+#endif
+
+
#ifdef USE_ADC_GENERIC
case 6:
adc_generic_periodic();
@@ -770,6 +812,11 @@
micromag_init();
#endif
+#ifdef USE_MAX11040
+ max11040_init_ssp();
+ max11040_init();
+#endif
+
/** - start interrupt task */
int_enable();
Modified: paparazzi3/trunk/sw/airborne/main_logger.c
===================================================================
--- paparazzi3/trunk/sw/airborne/main_logger.c 2009-10-17 07:29:30 UTC (rev
4261)
+++ paparazzi3/trunk/sw/airborne/main_logger.c 2009-10-17 15:17:59 UTC (rev
4262)
@@ -90,6 +90,10 @@
#include "efs.h"
#include "ls.h"
+#ifdef USE_MAX11040
+#include "max11040.h"
+#endif
+
#ifndef FALSE
#define FALSE 0
#endif
@@ -374,10 +378,31 @@
/* write to SD until key is pressed */
while ((IO0PIN & _BV(STOP_KEY))>>STOP_KEY)
{
+
+#ifdef USE_MAX11040
+ if (max11040_data == MAXM_DATA_AVAILABLE) {
+// LED_TOGGLE(3);
+ int i;
+
+ log_buffer[LOG_DATA_OFFSET+0] = 42; // sender_id;
+ log_buffer[LOG_DATA_OFFSET+1] = 59; // message_id;
+
+ for (i=0; i<16; i++) {
+// log_buffer[LOG_DATA_OFFSET + i + 0] = (max11040_values[i] << 24) &
0xFF;
+ log_buffer[LOG_DATA_OFFSET+2 + i*4 + 0] = i*4;
+ log_buffer[LOG_DATA_OFFSET+2 + i*4 + 1] = i*4+1;
+ log_buffer[LOG_DATA_OFFSET+2 + i*4 + 2] = i*4+2;
+ log_buffer[LOG_DATA_OFFSET+2 + i*4 + 3] = i*4+3;
+ }
+ log_payload(2 + 16 * 4, LOG_SOURCE_UART0, max11040_timestamp);
+ max11040_data = MAXM_IDLE;
+ }
+#endif
+
#ifdef USE_UART0
if (Uart0ChAvailable())
{
- LED_TOGGLE(2);
+ LED_TOGGLE(3);
inc = Uart0Getch();
#ifdef LOG_XBEE
log_xbee(inc, LOG_SOURCE_UART0);
@@ -393,7 +418,7 @@
#ifdef USE_UART1
if (Uart1ChAvailable())
{
- LED_TOGGLE(2);
+ LED_TOGGLE(3);
inc = Uart1Getch();
#ifdef LOG_XBEE
log_xbee(inc, LOG_SOURCE_UART1);
@@ -407,7 +432,7 @@
}
#endif
}
- LED_OFF(2);
+ LED_OFF(3);
file_fclose( &filew );
fs_umount( &efs.myFs ) ;
@@ -422,21 +447,23 @@
while(1)
{
- LED_ON(3);
+ LED_ON(2);
do_log();
- LED_OFF(3);
+ LED_OFF(2);
waitloop = 0;
ledcount = 0;
+
while (waitloop < 20)
{
sys_time_usleep(100000);
+
{
if (ledcount++ > 9) {
ledcount=0;
- LED_ON(3);
+ LED_ON(2);
} else {
- LED_OFF(3);
+ LED_OFF(2);
}
if (((IO0PIN & _BV(STOP_KEY))>>STOP_KEY) == 1) {
waitloop=0;
@@ -447,12 +474,12 @@
if ((IO0PIN & _BV(VBUS_PIN))>>VBUS_PIN)
{
- LED_OFF(3);
+ LED_OFF(2);
LED_ON(1);
main_mass_storage();
}
}
- LED_ON(3);
+ LED_ON(2);
while (((IO0PIN & _BV(STOP_KEY))>>STOP_KEY) == 0);
}
@@ -463,12 +490,19 @@
hw_init();
sys_time_init();
led_init();
+
#ifdef USE_UART0
Uart0Init();
#endif
#ifdef USE_UART1
Uart1Init();
#endif
+
+#ifdef USE_MAX11040
+ max11040_init_ssp();
+ max11040_init();
+#endif
+
int_enable();
}
Added: paparazzi3/trunk/sw/airborne/max11040.c
===================================================================
--- paparazzi3/trunk/sw/airborne/max11040.c (rev 0)
+++ paparazzi3/trunk/sw/airborne/max11040.c 2009-10-17 15:17:59 UTC (rev
4262)
@@ -0,0 +1,233 @@
+
+#include "max11040.h"
+
+
+volatile uint8_t max11040_status;
+volatile uint8_t max11040_data;
+volatile int32_t max11040_values[MAXM_NB_CHAN] = {0};
+volatile uint8_t max11040_count = 0;
+volatile uint32_t max11040_timestamp = 0;
+
+static void SSP_ISR(void) __attribute__((naked));
+
+
+static void SSP_ISR(void) {
+ int i;
+ ISR_ENTRY();
+
+ switch (max11040_status) {
+
+ case MAX11040_RESET:
+ {
+ /* read dummy control byte reply */
+ uint8_t foo __attribute__ ((unused));
+ foo = SSPDR;
+ foo = SSPDR;
+ /* write configuration register */
+ SSP_Send(0x60); /* wr conf */
+ SSP_Send(0x30); /* adc0: en24bit, xtalen, no faultdis */
+ for (i=1; i<MAXM_NB_ADCS; i++) {
+ SSP_Send(0x20); /* adcx: en24bit, no xtalen, no faultdis */
+ }
+ max11040_status = MAX11040_CONF;
+ SSP_ClearRti();
+ }
+ break;
+
+ case MAX11040_CONF:
+ {
+ /* read dummy control byte reply */
+ uint8_t foo __attribute__ ((unused));
+ foo = SSPDR;
+ for (i=0; i<MAXM_NB_ADCS; i++) {
+ foo = SSPDR;
+ }
+ /* write sampling instant register */
+ SSP_Send(0x40); /* wr instant */
+ for (i=0; i<MAXM_NB_ADCS; i++) {
+ SSP_Send(0); /* adcx: no delay */
+ SSP_Send(0);
+ SSP_Send(0);
+ SSP_Send(0);
+ }
+ max11040_status = MAX11040_INSTANT;
+ SSP_ClearRti();
+ }
+ break;
+
+ case MAX11040_INSTANT:
+ {
+ /* read dummy control byte reply */
+ uint8_t foo __attribute__ ((unused));
+ foo = SSPDR;
+ for (i=0; i<MAXM_NB_ADCS; i++) {
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ }
+ /* write data rate control register */
+ SSP_Send(0x50); /* wr rate */
+ SSP_Send(0x26); /* adc: 250.1 sps */
+ SSP_Send(0x00);
+ max11040_status = MAX11040_RATE;
+ SSP_ClearRti();
+ }
+ break;
+
+ case MAX11040_RATE:
+ {
+ uint8_t foo __attribute__ ((unused));
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ /* read data register */
+ SSP_Send(0xF0); /* rd data */
+ for (i=0; i<MAXM_NB_ADCS; i++) {
+ SSP_Send(0x00); /* adcx: data */
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ }
+ max11040_status = MAX11040_DATA;
+ SSP_ClearRti();
+ }
+ break;
+
+ case MAX11040_DATA:
+ {
+ uint8_t foo __attribute__ ((unused));
+ foo = SSPDR;
+ for (i=0; i<MAXM_NB_ADCS; i++) {
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ foo = SSPDR;
+ }
+
+ /* read data */
+ /* read data register */
+ SSP_Send(0xF0); /* rd data */
+ for (i=0; i<MAXM_NB_ADCS; i++) {
+ SSP_Send(0x00); /* adc0: data */
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ }
+
+ SSP_ClearRti();
+ }
+ break;
+
+ case MAX11040_DATA2:
+ {
+ uint8_t foo __attribute__ ((unused));
+
+ SSP_ClearRti();
+ SSP_ClearRxi();
+
+ if (max11040_count <= MAXM_NB_CHAN+2)
+ {
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ SSP_Send(0x00);
+ }
+
+ if (max11040_count == 0) foo = SSPDR;
+
+ max11040_values[max11040_count] = SSPDR << 16;
+ max11040_values[max11040_count] |= SSPDR << 8;
+ max11040_values[max11040_count] |= SSPDR;
+ if (max11040_values[max11040_count] & 0x800000)
+ max11040_values[max11040_count] |= 0xFF000000;
+
+ max11040_count++;
+
+ max11040_values[max11040_count] = SSPDR << 16;
+ max11040_values[max11040_count] |= SSPDR << 8;
+ max11040_values[max11040_count] |= SSPDR;
+ if (max11040_values[max11040_count] & 0x800000)
+ max11040_values[max11040_count] |= 0xFF000000;
+
+ max11040_count++;
+
+ if (max11040_count == MAXM_NB_CHAN)
+ {
+ MaxmUnselect();
+ max11040_data = MAX11040_DATA_AVAILABLE;
+ }
+ }
+ break;
+
+ }
+
+ VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
+ ISR_EXIT();
+}
+
+void max11040_init_ssp(void) {
+
+ /* setup pins for SSP (SCK, MISO, MOSI, SSEL) */
+ PINSEL1 |= SSP_PINSEL1_SCK | SSP_PINSEL1_MISO | SSP_PINSEL1_MOSI |
SSP_PINSEL1_SSEL;
+
+ /* setup SSP */
+ SSPCR0 = SSPCR0_VAL;;
+ SSPCR1 = SSPCR1_VAL;
+ SSPCPSR = 0x02;
+
+ /* initialize interrupt vector */
+ VICIntSelect &= ~VIC_BIT( VIC_SPI1 ); /* SPI1 selected as IRQ */
+ VICIntEnable = VIC_BIT( VIC_SPI1 ); /* enable it */
+ _VIC_CNTL(SSP_VIC_SLOT) = VIC_ENABLE | VIC_SPI1;
+ _VIC_ADDR(SSP_VIC_SLOT) = (uint32_t)SSP_ISR; /* address of the ISR */
+}
+
+void max11040_init( void ) {
+
+ int i;
+ max11040_hw_init();
+
+ max11040_status = MAX11040_RESET;
+ max11040_data = MAX11040_RESET;
+
+ /* write configuration register */
+ SSP_Send(0x60); /* wr conf */
+ for (i=0; i<MAXM_NB_ADCS; i++) {
+ SSP_Send(0x40); /* adcx: reset */
+ }
+ SSP_Enable();
+ SSP_ClearRti();
+ SSP_EnableRti();
+}
+
+void max11040_reset() {
+ max11040_status = MAX11040_IDLE;
+}
+
Added: paparazzi3/trunk/sw/airborne/max11040.h
===================================================================
--- paparazzi3/trunk/sw/airborne/max11040.h (rev 0)
+++ paparazzi3/trunk/sw/airborne/max11040.h 2009-10-17 15:17:59 UTC (rev
4262)
@@ -0,0 +1,38 @@
+#ifndef MAX11040_H
+#define MAX11040_H
+
+
+#include "std.h"
+#include "max11040_hw.h"
+
+#define MAXM_NB_CHAN 16
+#define MAXM_NB_ADCS ((MAXM_NB_CHAN+3)/4)
+
+extern void max11040_init_ssp(void);
+extern void max11040_init( void );
+
+extern void max11040_reset( void);
+extern void max11040_periodic( void );
+
+extern void max11040_hw_init( void );
+
+extern volatile uint8_t max11040_status;
+extern volatile uint8_t max11040_data;
+extern volatile int32_t max11040_values[MAXM_NB_CHAN];
+extern volatile uint8_t max11040_count;
+extern volatile uint32_t max11040_timestamp;
+
+
+#define MAX11040_RESET 0
+#define MAX11040_CONF 1
+#define MAX11040_INSTANT 2
+#define MAX11040_RATE 3
+#define MAX11040_DONE 4
+#define MAX11040_DATA 5
+#define MAX11040_DATA2 6
+
+#define MAX11040_IDLE 0
+#define MAX11040_DATA_AVAILABLE 1
+
+
+#endif /* MAX11040_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paparazzi-commits] [4262] Add Maxim MAX11040 SPI and VTI SCP1000 I2C,
Martin Mueller <=