I2C Read Issue STM32 F3
Posted: Mon Jun 02, 2014 3:01 am
Hey,
I'm trying to talk to an MPU9150 from an STM32F303C on a custom board. In debugging the I2C communication, I don't seem to be able to perform reads from the IMU.
I get a complete I2C transaction (see first attachment for logic analyzer cap) when I call i2cMasterTransmitTimeout in the following manner (corresponding to a write of 'd' to register 'ra' on the IMU):
However, when I call it in the next manner (corresponding to a read from register 'ra', putting the data in 'd'), the microcontroller sends the address byte, receives an ack, and then hangs with SCL low until the timeout event (see second capture from logic analyzer):
I'm configuring the timing for the i2c in the following manner (which I pulled from an F373 testhal example). The I2CConfig struct on this architecture corresponds to low-level registers in the microcontroller.
Things I've verified:
I've verified that I can read from and write to the accelerometer using a different hardware library, so I'm assuming my problem is with ChibiOS HAL configuration. Any advice would be appreciated!
I'm trying to talk to an MPU9150 from an STM32F303C on a custom board. In debugging the I2C communication, I don't seem to be able to perform reads from the IMU.
I get a complete I2C transaction (see first attachment for logic analyzer cap) when I call i2cMasterTransmitTimeout in the following manner (corresponding to a write of 'd' to register 'ra' on the IMU):
Code: Select all
txbuf[0] = ra;
txbuf[1] = d;
status = i2cMasterTransmitTimeout(i2cptr, mpu9150_addr, txbuf, 2, rxbuf, 0, 100);
However, when I call it in the next manner (corresponding to a read from register 'ra', putting the data in 'd'), the microcontroller sends the address byte, receives an ack, and then hangs with SCL low until the timeout event (see second capture from logic analyzer):
Code: Select all
txbuf[0] = ra;
status = i2cMasterTransmitTimeout(i2cptr, mpu9150_addr, txbuf, 1, rxbuf, 1, 100);
d = rxbuf[0];
I'm configuring the timing for the i2c in the following manner (which I pulled from an F373 testhal example). The I2CConfig struct on this architecture corresponds to low-level registers in the microcontroller.
Code: Select all
const I2CConfig i2c1_config = {
STM32_TIMINGR_PRESC(15U) |
STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) |
STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U),
0,
0
};
Things I've verified:
- -There ARE pullup resistors on the SDA and SCL lines
- I don't have SDA and SCL swapped
- I'm using the correct I2CD peripheral (I2CD1)
- I've set the "alternate" PAL mode, the correct alternate function, and have set them both as open drain (configuration in board.h)
- The address I'm sending is correct
- I'm attempting to read from a valid register
- Timing appears to be valid (since I get complete 'write' operations, but not 'read' ones).
- I've looked through this (http://forum.chibios.org/phpbb/viewtopic.php?f=16&t=1312) forum post, and my problem seems to be different.
I've verified that I can read from and write to the accelerometer using a different hardware library, so I'm assuming my problem is with ChibiOS HAL configuration. Any advice would be appreciated!