2015-10-22 12:55 PM
Hi everyone.
I must ask for help one more time. I've been tring do it on my own (using examples and my own functions), but nothing works. I'm want to read data from ACC, just one register, on my F3 discovery board. Init look like this:I2C_InitTypeDef I2C_InitStructure;
/* I2C configuration -------------------------------------------------------*/
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStructure.I2C_DigitalFilter = 0x00;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_Timing = 0x00902025;
/* Apply LSM303DLHC_I2C configuration after enabling it */
I2C_Init(LSM303DLHC_I2C, &I2C_InitStructure);
/* LSM303DLHC_I2C Peripheral Enable */
I2C_Cmd(LSM303DLHC_I2C, ENABLE);
It's init from examples.
Then main:
uint8_t out_x_buff=0;
uint8_t ctrl_reg[2];
LSM303DLHC_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG4_A, ctrl_reg,2);
LSM303DLHC_Read(ACC_I2C_ADDRESS, LSM303DLHC_OUT_X_H_M, out_x_buff, 1);
And read function:
uint16_t LSM303DLHC_Read(uint8_t DeviceAddr, uint8_t RegAddr, uint8_t* pBuffer, uint16_t NumByteToRead)
{
(DeviceAddr & 0x7f) <<
1
; //<----With or without doesn't matter, not working ; (
LSM303DLHC_Timeout
=
LSM303DLHC_LONG_TIMEOUT
;
while(I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_BUSY) != RESET){
if((LSM303DLHC_Timeout--) == 0) return LSM303DLHC_TIMEOUT_UserCallback();
}
I2C_TransferHandling(LSM303DLHC_I2C, DeviceAddr, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
LSM303DLHC_Timeout
=
LSM303DLHC_LONG_TIMEOUT
;
while(I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TXIS) == RESET){
if((LSM303DLHC_Timeout--) == 0) return LSM303DLHC_TIMEOUT_UserCallback();
}
if(NumByteToRead>1)
RegAddr |= 0x80;
I2C_SendData(LSM303DLHC_I2C, (uint8_t)RegAddr);
LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
while(I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TC) == RESET){
if((LSM303DLHC_Timeout--) == 0) return LSM303DLHC_TIMEOUT_UserCallback();
}
I2C_TransferHandling(LSM303DLHC_I2C, DeviceAddr, NumByteToRead, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
while (NumByteToRead){
LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
while(I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_RXNE) == RESET) {
if((LSM303DLHC_Timeout--) == 0) return LSM303DLHC_TIMEOUT_UserCallback();
}
*pBuffer = I2C_ReceiveData(LSM303DLHC_I2C);
pBuffer++;
NumByteToRead--;
}
LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
while(I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_STOPF) == RESET){
if((LSM303DLHC_Timeout--) == 0) return LSM303DLHC_TIMEOUT_UserCallback();
}
I2C_ClearFlag(LSM303DLHC_I2C, I2C_ICR_STOPCF);
return LSM303DLHC_OK;
}
Program hangs in geting TXIS flag status. I now there was problem like this, i found something in web, but none solutions works for me.
Thank in advance and have a nice day!
#txis-flag #lsm303dlhc #stm32f3