mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-26 08:22:43 +08:00
baro on spi (doesn't work yet)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#ifndef CONFIG_WT_H
|
||||
#define CONFIG_WT_H
|
||||
|
||||
/* Master oscillator freq. */
|
||||
#define FOSC (12000000)
|
||||
/* PLL multiplier */
|
||||
#define PLL_MUL (5)
|
||||
/* CPU clock freq. */
|
||||
#define CCLK (FOSC * PLL_MUL)
|
||||
/* Peripheral bus speed mask 0x00->4, 0x01-> 1, 0x02 -> 2 */
|
||||
#define PBSD_BITS 0x00
|
||||
#define PBSD_VAL 4
|
||||
/* Peripheral bus clock freq. */
|
||||
#define PCLK (CCLK / PBSD_VAL)
|
||||
|
||||
#define LED_1_BANK 1
|
||||
#define LED_1_PIN 24
|
||||
|
||||
#define SPI_SELECT_SLAVE0_PORT 0
|
||||
#define SPI_SELECT_SLAVE0_PIN 20
|
||||
|
||||
#define SPI1_DRDY_PINSEL PINSEL1
|
||||
#define SPI1_DRDY_PINSEL_BIT 0
|
||||
#define SPI1_DRDY_PINSEL_VAL 1
|
||||
#define SPI1_DRDY_EINT 0
|
||||
#define SPI1_DRDY_VIC_IT VIC_EINT0
|
||||
|
||||
|
||||
#endif /* CONFIG_WT_H */
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "wt_servo.h"
|
||||
|
||||
#include "spi.h"
|
||||
#include "wt_baro.h"
|
||||
|
||||
static inline void main_init( void );
|
||||
static inline void main_periodic_task( void );
|
||||
@@ -45,16 +47,32 @@ static inline void main_init( void ) {
|
||||
wt_servo_init();
|
||||
wt_servo_set(500);
|
||||
|
||||
spi_init();
|
||||
wt_baro_init();
|
||||
|
||||
int_enable();
|
||||
}
|
||||
|
||||
static inline void main_periodic_task( void ) {
|
||||
// LED_TOGGLE(1);
|
||||
LED_TOGGLE(1);
|
||||
DOWNLINK_SEND_TAKEOFF(&motor_power);
|
||||
wt_baro_periodic();
|
||||
DOWNLINK_SEND_DEBUG(3,buf_input);
|
||||
}
|
||||
|
||||
static inline void main_event_task( void ) {
|
||||
DatalinkEvent();
|
||||
|
||||
// spi baro
|
||||
if (spi_message_received) {
|
||||
/* Got a message on SPI. */
|
||||
spi_message_received = FALSE;
|
||||
wt_baro_event();
|
||||
uint16_t temp = 0;
|
||||
float alt = 0.;
|
||||
DOWNLINK_SEND_BARO_MS5534A(&wt_baro_pressure,&temp,&alt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -82,3 +100,5 @@ void dl_parse_msg(void) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2007 ENAC
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief
|
||||
*
|
||||
*/
|
||||
|
||||
#include "wt_baro.h"
|
||||
#include "spi.h"
|
||||
|
||||
uint32_t wt_baro_pressure;
|
||||
bool_t wt_baro_available;
|
||||
|
||||
static bool_t status_read_data;
|
||||
|
||||
#define CMD_INIT_1 0x24 // set chanel AIN1/AIN2 and next operation on filter high
|
||||
#define CMD_INIT_2 0xCF // set unipolar mode, 24 bits, no boost, filter high
|
||||
#define CMD_INIT_3 0x34 // set chanel AIN1/AIN2 and next operation on filter low
|
||||
#define CMD_INIT_4 0x00 // set low filter
|
||||
#define CMD_INIT_5 0x14 // set chanel AIN1/AIN2 and next operation on mode register
|
||||
#define CMD_INIT_6 0x20 // set gain to 1, burnout current off, no filter sync, self calibration
|
||||
#define CMD_MEASUREMENT 0x54 // set chanel AIN1/AIN2 and next operation on data register
|
||||
|
||||
|
||||
uint8_t buf_input[3];
|
||||
uint8_t buf_output[3];
|
||||
|
||||
#define Uint24(buf_input) (((uint32_t)buf_input[0]) << 16 |((uint16_t)buf_input[1]) << 8 | buf_input[2])
|
||||
|
||||
|
||||
static void send1_on_spi(uint8_t d) {
|
||||
buf_output[0] = d;
|
||||
spi_buffer_length = 1;
|
||||
|
||||
spi_buffer_input = (uint8_t*)&buf_input;
|
||||
spi_buffer_output = (uint8_t*)&buf_output;
|
||||
SpiStart();
|
||||
}
|
||||
|
||||
|
||||
void wt_baro_init( void ) {
|
||||
|
||||
wt_baro_pressure = 0;
|
||||
|
||||
send1_on_spi(CMD_INIT_1);
|
||||
send1_on_spi(CMD_INIT_2);
|
||||
send1_on_spi(CMD_INIT_3);
|
||||
send1_on_spi(CMD_INIT_4);
|
||||
send1_on_spi(CMD_INIT_5);
|
||||
send1_on_spi(CMD_INIT_6);
|
||||
|
||||
status_read_data = FALSE;
|
||||
wt_baro_available = FALSE;
|
||||
|
||||
}
|
||||
|
||||
void wt_baro_periodic(void) {
|
||||
if (!SpiCheckAvailable()) {
|
||||
SpiOverRun();
|
||||
return;
|
||||
}
|
||||
|
||||
if (status_read_data) {
|
||||
buf_output[0] = buf_output[1] = buf_output[2] = 0;
|
||||
spi_buffer_length = 3;
|
||||
}
|
||||
else {
|
||||
buf_output[0] = CMD_MEASUREMENT;
|
||||
spi_buffer_length = 1;
|
||||
}
|
||||
|
||||
spi_buffer_input = (uint8_t*)&buf_input;
|
||||
spi_buffer_output = (uint8_t*)&buf_output;
|
||||
//if (status_read_data)
|
||||
// SpiSetCPHA();
|
||||
//else
|
||||
// SpiClrCPHA();
|
||||
SpiStart();
|
||||
}
|
||||
|
||||
static uint32_t data;
|
||||
|
||||
/* Handle the SPI message, i.e. store the received values in variables */
|
||||
void wt_baro_event( void ) {
|
||||
|
||||
if (status_read_data) {
|
||||
data = Uint24(buf_input);
|
||||
/* Compute pressure */
|
||||
wt_baro_pressure = data;
|
||||
wt_baro_available = TRUE;
|
||||
} /* else nothing to read */
|
||||
|
||||
status_read_data = !status_read_data;
|
||||
|
||||
//if (!status_read_data) {
|
||||
// /* Ask next conversion now */
|
||||
// baro_MS5534A_send();
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2007 ENAC
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief
|
||||
*
|
||||
*/
|
||||
|
||||
#include "std.h"
|
||||
|
||||
extern uint8_t buf_input[3];
|
||||
extern uint8_t buf_output[3];
|
||||
|
||||
extern bool_t wt_baro_available;
|
||||
extern uint32_t wt_baro_pressure;
|
||||
|
||||
extern void wt_baro_init(void);
|
||||
extern void wt_baro_periodic(void);
|
||||
extern void wt_baro_event(void);
|
||||
|
||||
Reference in New Issue
Block a user