diff --git a/flight/AHRS/Makefile b/flight/AHRS/Makefile index f9906b940..eb8dd2f04 100644 --- a/flight/AHRS/Makefile +++ b/flight/AHRS/Makefile @@ -95,6 +95,7 @@ SRC += $(PIOSSTM32F10X)/pios_usart.c SRC += $(PIOSSTM32F10X)/pios_irq.c SRC += $(PIOSSTM32F10X)/pios_adc.c SRC += $(PIOSSTM32F10X)/pios_i2c.c +SRC += $(PIOSSTM32F10X)/pios_gpio.c #SRC += $(PIOSSTM32F10X)/pios_spi.c ## PIOS Hardware (Common) diff --git a/flight/AHRS/ahrs.c b/flight/AHRS/ahrs.c index 20fa77460..6962f77d8 100644 --- a/flight/AHRS/ahrs.c +++ b/flight/AHRS/ahrs.c @@ -33,6 +33,7 @@ /* Function Prototypes */ + /** * AHRS Main function */ @@ -54,6 +55,10 @@ int main() PIOS_I2C_Init(); PIOS_HMC5843_Init(); + /* Setup the Accelerometer FS (Full-Scale) GPIO */ + PIOS_GPIO_Enable(0); + SET_ACCEL_2G; + /* Configure the HMC5843 Sensor */ PIOS_HMC5843_ConfigTypeDef HMC5843_InitStructure; HMC5843_InitStructure.M_ODR = PIOS_HMC5843_ODR_10; @@ -82,12 +87,13 @@ int main() if(heading < 0) heading += 360; // Output Heading data to - PIOS_COM_SendFormattedString(COM_USART1, "Chip ID: %s\rHeading: %d\rRaw Mag Values: X=%d Y=%d Y=%d\r", id, heading, data[0], data[1], data[2]); + PIOS_COM_SendFormattedString(COM_USART1, "HMC5843 Chip ID: %s\rHeading: %d\rRaw Mag Values: X=%d Y=%d Y=%d\r", id, heading, data[0], data[1], data[2]); // Test ADC PIOS_COM_SendFormattedString(COM_USART1, "ADC Values: %d,%d,%d,%d,%d,%d\r\n", PIOS_ADC_PinGet(0), PIOS_ADC_PinGet(1), PIOS_ADC_PinGet(2), PIOS_ADC_PinGet(3), PIOS_ADC_PinGet(4), PIOS_ADC_PinGet(5)); - PIOS_DELAY_WaitmS(250); + // Delay until next reading + PIOS_DELAY_WaitmS(500); } return 0; diff --git a/flight/AHRS/inc/pios_board.h b/flight/AHRS/inc/pios_board.h index 6d8fb6ad5..f09107f3a 100644 --- a/flight/AHRS/inc/pios_board.h +++ b/flight/AHRS/inc/pios_board.h @@ -302,4 +302,17 @@ TIM8 | | | | /* (1 / (ADCCLK / CYCLES)) = Sample Time (�S) */ #define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH +//------------------------- +// GPIO +//------------------------- +#define PIOS_GPIO_1_PORT GPIOB +#define PIOS_GPIO_1_PIN GPIO_Pin_9 +#define PIOS_GPIO_1_GPIO_CLK RCC_APB2Periph_GPIOB +#define PIOS_GPIO_PORTS { PIOS_GPIO_1_PORT } +#define PIOS_GPIO_PINS { PIOS_GPIO_1_PIN } +#define PIOS_GPIO_CLKS { PIOS_GPIO_1_GPIO_CLK } +#define PIOS_GPIO_NUM 1 +#define SET_ACCEL_2G PIOS_GPIO_On(0); +#define SET_ACCEL_6G PIOS_GPIO_Off(0) + #endif /* PIOS_BOARD_H */ diff --git a/flight/AHRS/inc/pios_config.h b/flight/AHRS/inc/pios_config.h index c066d1b23..4f3f118a6 100644 --- a/flight/AHRS/inc/pios_config.h +++ b/flight/AHRS/inc/pios_config.h @@ -38,6 +38,7 @@ #define PIOS_INCLUDE_USART #define PIOS_INCLUDE_COM #define PIOS_INCLUDE_HMC5843 +#define PIOS_INCLUDE_GPIO #endif /* PIOS_CONFIG_H */ diff --git a/flight/PiOS/STM32F10x/pios_gpio.c b/flight/PiOS/STM32F10x/pios_gpio.c index 0b99a7873..6293969d6 100644 --- a/flight/PiOS/STM32F10x/pios_gpio.c +++ b/flight/PiOS/STM32F10x/pios_gpio.c @@ -41,7 +41,7 @@ static const uint32_t GPIO_CLK[PIOS_GPIO_NUM] = PIOS_GPIO_CLKS; /** -* Initialises all the LED's +* Initialises all the GPIO's */ void PIOS_GPIO_Init(void) {