fixed open #endif in sensors.c, and added using i2cUnstick() at startup to clean up I2C bus.
git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@89 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
738541b269
commit
e4574698c5
18
drv_i2c.c
18
drv_i2c.c
|
@ -7,6 +7,7 @@
|
||||||
static I2C_TypeDef *I2Cx;
|
static I2C_TypeDef *I2Cx;
|
||||||
static void i2c_er_handler(void);
|
static void i2c_er_handler(void);
|
||||||
static void i2c_ev_handler(void);
|
static void i2c_ev_handler(void);
|
||||||
|
static void i2cUnstick(void);
|
||||||
|
|
||||||
void I2C2_ER_IRQHandler(void)
|
void I2C2_ER_IRQHandler(void)
|
||||||
{
|
{
|
||||||
|
@ -224,6 +225,9 @@ void i2cInit(I2C_TypeDef *I2C)
|
||||||
|
|
||||||
I2Cx = I2C;
|
I2Cx = I2C;
|
||||||
|
|
||||||
|
// clock out stuff to make sure slaves arent stuck
|
||||||
|
i2cUnstick();
|
||||||
|
|
||||||
// Init I2C
|
// Init I2C
|
||||||
I2C_DeInit(I2Cx);
|
I2C_DeInit(I2Cx);
|
||||||
I2C_StructInit(&I2C_InitStructure);
|
I2C_StructInit(&I2C_InitStructure);
|
||||||
|
@ -248,6 +252,7 @@ void i2cInit(I2C_TypeDef *I2C)
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn;
|
NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void i2cUnstick(void)
|
static void i2cUnstick(void)
|
||||||
|
@ -265,6 +270,7 @@ static void i2cUnstick(void)
|
||||||
// Wait for any clock stretching to finish
|
// Wait for any clock stretching to finish
|
||||||
while (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_10))
|
while (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_10))
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
|
|
||||||
// Pull low
|
// Pull low
|
||||||
GPIO_ResetBits(GPIOB, GPIO_Pin_10); //Set bus low
|
GPIO_ResetBits(GPIOB, GPIO_Pin_10); //Set bus low
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
|
@ -273,6 +279,18 @@ static void i2cUnstick(void)
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a start then stop condition
|
||||||
|
// SCL PB10
|
||||||
|
// SDA PB11
|
||||||
|
|
||||||
|
GPIO_ResetBits(GPIOB, GPIO_Pin_11); // Set bus data low
|
||||||
|
delayMicroseconds(10);
|
||||||
|
GPIO_ResetBits(GPIOB, GPIO_Pin_10); // Set bus scl low
|
||||||
|
delayMicroseconds(10);
|
||||||
|
GPIO_SetBits(GPIOB, GPIO_Pin_10); // Set bus scl high
|
||||||
|
delayMicroseconds(10);
|
||||||
|
GPIO_SetBits(GPIOB, GPIO_Pin_11); // Set bus sda high
|
||||||
|
|
||||||
// Init pins
|
// Init pins
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
|
|
|
@ -209,7 +209,6 @@ static void Mag_getRawADC(void)
|
||||||
magADC[ROLL] = rawADC[0]; // X or negative? who knows mag stuff in multiwii is broken hardcore
|
magADC[ROLL] = rawADC[0]; // X or negative? who knows mag stuff in multiwii is broken hardcore
|
||||||
magADC[PITCH] = rawADC[2]; // Y
|
magADC[PITCH] = rawADC[2]; // Y
|
||||||
magADC[YAW] = rawADC[1]; // Z
|
magADC[YAW] = rawADC[1]; // Z
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mag_init(void)
|
void Mag_init(void)
|
||||||
|
|
Loading…
Reference in New Issue