Page 1 of 1

STM32F0 I2C....

Posted: Sat Jun 06, 2015 5:16 pm
by rew
Hi,

Is STM32F0 I2C supposed to work?

When I work with I2C1, according to the logic analyser it works. Except:

* The clock speed is about 1MHz instead of 100kHz. (or 400). This seems due to the timing register being 0. I can read back the timing register right after i2cStart and it is zero.
* The i2cMasterTransmitTimeout returns error. This is due to the TC interrupt never happening. TCIE seems enabled.

Switching to I2C2 left me with "nothing": No data seems to be output outside of the chip. Suggestions?

P.S. Thinking: I could try this on my '405, how would I go about porting my application from '072 to '405? The PCB that holds the chips is the same, so all pin assignments are the same, just the CPU is different.

Re: STM32F0 I2C....

Posted: Sat Jun 06, 2015 7:54 pm
by Giovanni
Hi,

Is the configuration structure correct? there are clock-dependent settings there. Note that also the driver is different, v1 for the F4, v2 for the F0 and the configuration structure is VERY different.

Giovanni

Re: STM32F0 I2C....

Posted: Sat Jun 06, 2015 9:43 pm
by steved
I use I2C extensively on the 32F051; but only at 100kHz.

Following is my config block:

Code: Select all

static I2CConfig i2cfg1 = {
     STM32_TIMINGR_PRESC(5U)  |            /* 48MHz/6 = 8MHz I2CCLK.           */
     STM32_TIMINGR_SCLDEL(3U) | STM32_TIMINGR_SDADEL(3U) |
     STM32_TIMINGR_SCLH(3U)   | STM32_TIMINGR_SCLL(9U),
                    // Just scale bits 28..31 if not 8MHz clock
    0,              // CR1
    0,              // CR2
};

Re: STM32F0 I2C....

Posted: Sun Jun 07, 2015 6:16 am
by rew
Because I knew that I have a "V2" i2c peripheral I copied:

Code: Select all

static const I2CConfig i2cfg1 = {
    STM32_TIMINGR_PRESC(0x02) | STM32_TIMINGR_SCLH(0x09) | STM32_TIMINGR_SCLL(0x0E),
    I2C_CR1_PE,
    I2C_CR2_AUTOEND
};
from the i2c-F3 example, to have something that at least works. If it runs 2x too fast or slow, we'll manage. I can see that on my logic analyser. Moreover, the chip I'm addressing didn't find 1MHz a problem. It ACKs the "reset" command just fine at 1MHz. (The bus is only 10cm long, extended by 15cm to reach the logic analyser).

But: Steve, thanks very much, your initialization works.

Steve: Is there a good reason to chose the SCL LOW time longer than the high time? With a long bush, the SCL line takes a while to become high. So I would think you drive it low for say 4 microseconds, let it float/ high for 6 microseconds nominal. With "extreme" capacitance on the bus, it might take 2 microseconds for hte bus to become high. Now you have 4-6 microseconds of low time, and 6-4 microseconds of high-time. If you start out with SCL low time longer than the high time, you'd get worse deviations from the normal 50/50 dutycycle.