afry-south / dragonfly-fcb

ÅF Dragonfly Quadrotor UAV Project
Other
7 stars 3 forks source link

I2C bus speed LSM303DLHC #91

Open adam-at-epsilon opened 9 years ago

adam-at-epsilon commented 9 years ago

The application note sheet says that that the LSM303DLHC sensor supports 400kbit speed, see if we can use this to speed up reading the sensor.

adam-at-epsilon commented 8 years ago

The CPU side supports 400kHz in "fast-mode" operation. It has three modes of operation:

LSM303DLHC Datasheet also refers to this device support 400 kHz as well.

To be continued ...

adam-at-epsilon commented 8 years ago

The I2C1 clock is per default set to HSI clock, which is the default value as per reference manual section 9.4.13.

Changing to SYSCLK did not yield positive results.

Measuring the I2C frequency using the GPIO PB6 pin for the SCL line, current bus speed is about 82kHz which is well below the 100kHz normal operation mode and only a 5th of the fast-mode 400kHz mode.

adam-at-epsilon commented 8 years ago

Using the excel sheet configuration tool stsw-stm32126 to calculate a value for the TIMINGR register did not yield positive results.

Using the HSI clock also did not improve matters significantly.

The I2C1 clock source can be configured in the ConfigSystemClock function on the line below the USB clock. The TIMINGR register is set in the I2Cx_Init function as I2cHandle.Init.Timing.

A question has been posted on the STM32 forum: https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM32Discovery%2fSTM32F3-Discovery%20accessing%20LSM303DLHC%20with%20I2C%20fastmode&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FAllItems.aspx&currentviews=0

adam-at-epsilon commented 8 years ago

According to section 2.2.3 in AN4235 (ST Application Note) tPCLK must satisfy

tPCLK < 4/3 tSCL

As our system clock is 72MHz is divided by two for PCLK1, this should not be a problem as even 36MHz is more than 10 times faster than 400kHz.

adam-at-epsilon commented 8 years ago

Also added question on StackExchange

http://electronics.stackexchange.com/questions/190292/stm32f3-discovery-accessing-lsm303dlhc-with-i2c-fastmode

adam-at-epsilon commented 8 years ago

From LSM303DLHC data sheet section 5.5.1 it's possible to enable autoincrement of the sub address to the LSM303DLHC.

Enabling this means that we don't have to send the sub address for every individual byte (2 bytes each for X, Y and Z. A measurement with my NI MyDAQ oscilloscope on pins PD9 (accelerometer) and PD11 (magnetometer, unmodified) indicates that reading the 6 bytes only takes ~200us in one go,but ~400us for the magnetometer which reads them individually.

Next step: modifiy code for magnetometer as well.