Open adam-at-epsilon opened 9 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 ...
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.
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
.
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.
Also added question on StackExchange
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.
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.