From dca3a03ab9b6996fd558dc797d6a4840ea64e380 Mon Sep 17 00:00:00 2001 From: Lennart Eriksson Date: Thu, 6 Oct 2016 10:45:16 +0200 Subject: [PATCH] Small fixes --- UAV-ControlSystem/inc/drivers/accel_gyro.h | 3 ++- UAV-ControlSystem/src/drivers/accel_gyro.c | 8 +++++++- UAV-ControlSystem/src/drivers/spi.c | 8 ++------ UAV-ControlSystem/src/drivers/system_clock.c | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/UAV-ControlSystem/inc/drivers/accel_gyro.h b/UAV-ControlSystem/inc/drivers/accel_gyro.h index a5a39e5..e8cd064 100644 --- a/UAV-ControlSystem/inc/drivers/accel_gyro.h +++ b/UAV-ControlSystem/inc/drivers/accel_gyro.h @@ -195,7 +195,7 @@ bool mpu6000_who_am_i(); while(1) { // Read the fifo queue, this returns the number of bytes read - int num = mpu6000_read_fifo(&g, dataz); + int num = mpu6000_read_fifo(&g, data); // if num returned is negative an error has occurred if(num > 0) @@ -219,5 +219,6 @@ bool mpu6000_who_am_i(); // HAL_Delay(100); // --------------- END ACCELEROMETER TEST ------------ } +} */ diff --git a/UAV-ControlSystem/src/drivers/accel_gyro.c b/UAV-ControlSystem/src/drivers/accel_gyro.c index cb5060e..95ae8d0 100644 --- a/UAV-ControlSystem/src/drivers/accel_gyro.c +++ b/UAV-ControlSystem/src/drivers/accel_gyro.c @@ -9,6 +9,7 @@ #include "drivers/spi.h" spi_profile mpu6000_spi_profile; +uint8_t num_failed_receive = 0; /*********************************************************************** * BRIEF: SPI1_Init initializes the SPI1 instance with predefined values* @@ -322,7 +323,7 @@ int mpu6000_read_fifo(gyro_t* gyro, int16_t* data_out) fifoCount = (uint16_t)((countH << 8) | countL); - if (fifoCount == 1024) + if (fifoCount == 1024 || num_failed_receive > 20) { reg[0] = MPU_RA_USER_CTRL; reg[1] = BIT_FIFO_RESET; @@ -337,7 +338,12 @@ int mpu6000_read_fifo(gyro_t* gyro, int16_t* data_out) } if (fifoCount < 6) + { + num_failed_receive++; return -3; + } + else + num_failed_receive = 0; /* Make sure that only complete sets of gyro data are read */ bytesRead = (fifoCount/6)*6; diff --git a/UAV-ControlSystem/src/drivers/spi.c b/UAV-ControlSystem/src/drivers/spi.c index cae9c0d..f2ff785 100644 --- a/UAV-ControlSystem/src/drivers/spi.c +++ b/UAV-ControlSystem/src/drivers/spi.c @@ -69,7 +69,7 @@ bool spi_init(SPI_TypeDef *spi_instance, // The spi instance to be used i.e. SPI gpioInit.Pin = out_profile->spi_nss; gpioInit.Mode = GPIO_MODE_OUTPUT_PP; gpioInit.Pull = GPIO_PULLUP; - gpioInit.Speed = GPIO_SPEED_LOW; + gpioInit.Speed = GPIO_SPEED_HIGH; gpioInit.Alternate = 0; HAL_GPIO_Init(out_profile->spi_nss_port, &gpioInit); @@ -81,7 +81,7 @@ bool spi_init(SPI_TypeDef *spi_instance, // The spi instance to be used i.e. SPI gpioInit.Pin = spi_miso | spi_mosi | spi_sck; gpioInit.Mode = GPIO_MODE_AF_PP; gpioInit.Pull = GPIO_NOPULL; - gpioInit.Speed = GPIO_SPEED_LOW; + gpioInit.Speed = GPIO_SPEED_HIGH; gpioInit.Alternate = spi_af; HAL_GPIO_Init(spi_miso_port, &gpioInit); @@ -123,10 +123,6 @@ bool spi_transmit(spi_profile *profile, { HAL_StatusTypeDef err; /* SPI transmission status variable */ -// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); -// err = HAL_SPI_Transmit(profile->profile, data, 2, 10); -// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); - // Tell the selected slave that the data is intended for him/her (hen) HAL_GPIO_WritePin(profile->spi_nss_port, profile->spi_nss, GPIO_PIN_RESET); // Send the data diff --git a/UAV-ControlSystem/src/drivers/system_clock.c b/UAV-ControlSystem/src/drivers/system_clock.c index 44510b9..3d3fe75 100644 --- a/UAV-ControlSystem/src/drivers/system_clock.c +++ b/UAV-ControlSystem/src/drivers/system_clock.c @@ -14,7 +14,7 @@ static uint32_t usTicks = 0; /*********************************************************************** -* BRIEF: Starts the system clock at 100MHz * +* BRIEF: Starts the system clock at 144MHz * * INFORMATION: In the current version it works with ADC and DMA * ***********************************************************************/ void system_clock_config(void)