I'm trying to get I2C to run but after a few days of searching and stripping down my project to the bare minimum for I2C I never see a single bit sent on I2C outputs (no signal change on oscilloscope), no clock.
I made sure that the outputs actually work by toggling the output and seeing the level change on my oscilloscope.
There must be something I'm missing but I cannot figure out what…
Any help would be much appreciated.
The first I2C transmit runs through but the second one halts the system with reason "i2cMasterTransmitTimeout". Increasing the timeout did yield no success.
MCU is a STM32F103.
Code from main.c:
Code: Select all
#include "ch.h"
#include "hal.h"
#include "board.h"
#define NV_DEVADDR 0b1010110 // E1, E2 are pulled HIGH in hardware, only 7 bits for address, R/W bit is added by driver
#define NV_MEMSIZE 512 // 4 Kibit / 512 Byte
#define NV_PAGESIZE 16 // Bytes
#define NV_PAGES 32
#define NV_WRITETIME_MS 5 // guaranteed maximum in datasheet
#define NV_TIMEOUT_MS 5
static const I2CConfig i2ccfg = {
OPMODE_I2C,
400000,
FAST_DUTY_CYCLE_2
};
static const I2CConfig i2ccfg_ls = {
OPMODE_I2C,
100000,
STD_DUTY_CYCLE
};
/** Application entry point. */
int main(void) {
uint8_t mem_address[1] = {0x00};
uint8_t nvsettings[4] = {0}; // holds the temporay read values
halInit(); // calls boardInit() at last
chSysInit();
// start I2C
i2cStart(&I2CD1, &i2ccfg_ls);
/*
* Normal main() thread activity, in this demo it does nothing.
*/
while (true) {
i2cAcquireBus(&I2CD1);
i2cMasterTransmitTimeout(&I2CD1,
NV_DEVADDR,
mem_address, sizeof(mem_address),
nvsettings, sizeof(nvsettings),
TIME_MS2I(NV_TIMEOUT_MS)
);
i2cReleaseBus(&I2CD1);
chThdSleepMilliseconds(500);
}
return 0;
}
board.h:
Code: Select all
/*
* Port B setup.
* Everything input with pull-up except:
* PB0,1 - Push Pull output (LED).
* PB6,7 - open drain "I2C"
* PB8,9 - "debug" outputs
* PB11..15 - normal input, pull-down externally provided
*/
#define VAL_GPIOBCRL 0x55888833 /* PB7...PB0 */
#define VAL_GPIOBCRH 0x44444338 /* PB15...PB8 */
#define VAL_GPIOBODR 0xFFFFFFFF
mcuconf.h:
Code: Select all
/*
* I2C driver system settings.
*/
#define STM32_I2C_USE_I2C1 TRUE
halconf.h:
Code: Select all
#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
#define HAL_USE_I2C TRUE
#endif
#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
#define I2C_USE_MUTUAL_EXCLUSION TRUE
#endif