I'm trying to communicate with an I²C chip which is connected to the I2CD1 of the STM32F4-Discovery board (PB8 and PB9). I use the following code:
Code: Select all
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
static const I2CConfig i2ccfg = {
OPMODE_I2C,
400000,
FAST_DUTY_CYCLE_2,
};
uint8_t txbuf[2];
uint8_t rxbuf[2];
int main(void) {
halInit();
chSysInit();
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4)); /* SCL */
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4)); /* SDA */
txbuf[0] = 0x00;
txbuf[0] = 0x00;
i2cStart(&I2CD1, &i2ccfg);
while(1) {
i2cAcquireBus(&I2CD1);
i2cMasterTransmit(&I2CD1, 0x82 >> 1, txbuf, 1, rxbuf, 2);
i2cReleaseBus(&I2CD1);
chprintf(shell, "Received: 0x%02X 0x%02X\r\n", rxbuf[0], rxbuf[1]);
chThdSleepMilliseconds(500);
}
return 0;
}
I get 0x00 0x00 all the time (I'm expected to get 0x0811). So here's what's my scope says to that:
I'm not sure from where this 'half' state comes from. There's no other hardware on these two pins which would make any problems with the I²C interface. But the main issue I'm seing here is that the STM32 does not generate the clock for the phase where the slave is supposed to return two bytes. The chip I'm trying to interface is an STMPE811.
Any ideas?
~ Tectu