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.
STM32F0 I2C....
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: STM32F0 I2C....
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
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....
I use I2C extensively on the 32F051; but only at 100kHz.
Following is my config block:
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....
Because I knew that I have a "V2" i2c peripheral I copied:
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.
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
};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.