Small fixes

This commit is contained in:
Lennart Eriksson 2016-10-06 10:45:16 +02:00
parent 4c6adc9c89
commit dca3a03ab9
4 changed files with 12 additions and 9 deletions

View File

@ -195,7 +195,7 @@ bool mpu6000_who_am_i();
while(1) while(1)
{ {
// Read the fifo queue, this returns the number of bytes read // 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 returned is negative an error has occurred
if(num > 0) if(num > 0)
@ -219,5 +219,6 @@ bool mpu6000_who_am_i();
// HAL_Delay(100); // HAL_Delay(100);
// --------------- END ACCELEROMETER TEST ------------ // --------------- END ACCELEROMETER TEST ------------
} }
}
*/ */

View File

@ -9,6 +9,7 @@
#include "drivers/spi.h" #include "drivers/spi.h"
spi_profile mpu6000_spi_profile; spi_profile mpu6000_spi_profile;
uint8_t num_failed_receive = 0;
/*********************************************************************** /***********************************************************************
* BRIEF: SPI1_Init initializes the SPI1 instance with predefined values* * 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); fifoCount = (uint16_t)((countH << 8) | countL);
if (fifoCount == 1024) if (fifoCount == 1024 || num_failed_receive > 20)
{ {
reg[0] = MPU_RA_USER_CTRL; reg[0] = MPU_RA_USER_CTRL;
reg[1] = BIT_FIFO_RESET; reg[1] = BIT_FIFO_RESET;
@ -337,7 +338,12 @@ int mpu6000_read_fifo(gyro_t* gyro, int16_t* data_out)
} }
if (fifoCount < 6) if (fifoCount < 6)
{
num_failed_receive++;
return -3; return -3;
}
else
num_failed_receive = 0;
/* Make sure that only complete sets of gyro data are read */ /* Make sure that only complete sets of gyro data are read */
bytesRead = (fifoCount/6)*6; bytesRead = (fifoCount/6)*6;

View File

@ -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.Pin = out_profile->spi_nss;
gpioInit.Mode = GPIO_MODE_OUTPUT_PP; gpioInit.Mode = GPIO_MODE_OUTPUT_PP;
gpioInit.Pull = GPIO_PULLUP; gpioInit.Pull = GPIO_PULLUP;
gpioInit.Speed = GPIO_SPEED_LOW; gpioInit.Speed = GPIO_SPEED_HIGH;
gpioInit.Alternate = 0; gpioInit.Alternate = 0;
HAL_GPIO_Init(out_profile->spi_nss_port, &gpioInit); 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.Pin = spi_miso | spi_mosi | spi_sck;
gpioInit.Mode = GPIO_MODE_AF_PP; gpioInit.Mode = GPIO_MODE_AF_PP;
gpioInit.Pull = GPIO_NOPULL; gpioInit.Pull = GPIO_NOPULL;
gpioInit.Speed = GPIO_SPEED_LOW; gpioInit.Speed = GPIO_SPEED_HIGH;
gpioInit.Alternate = spi_af; gpioInit.Alternate = spi_af;
HAL_GPIO_Init(spi_miso_port, &gpioInit); 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_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) // 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); HAL_GPIO_WritePin(profile->spi_nss_port, profile->spi_nss, GPIO_PIN_RESET);
// Send the data // Send the data

View File

@ -14,7 +14,7 @@
static uint32_t usTicks = 0; 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 * * INFORMATION: In the current version it works with ADC and DMA *
***********************************************************************/ ***********************************************************************/
void system_clock_config(void) void system_clock_config(void)