https://github.com/karlp/libopencm3-tests/tree/master/tests/i2c-master is the code I wrote while developing the "standard" api. (You shouldn't really have to know about the v1/v2 differences, for the most part...) Those "set_fast_mode" and "set_standard_mode" are part of the original very low level apis. you (probably) want something more like:
https://github.com/karlp/libopencm3-tests/blob/master/tests/i2c-master/i2c-master.c#L29-L38 (i2c_set_speed() and then just i2c_transfer7() The main-<hardware> have the onnly board specfic setup required, normally setting up clocks and gpio modes. There's a couple of issues reported with i2c as well: https://github.com/libopencm3/libopencm3/pulls?q=is%3Apr+is%3Aopen+i2c that _may_ be relevant to you, or at least to bear in mind. Chris Chronopoulos <chronopoulos.ch...@gmail.com> wrote: > Hmm, well update - I figured out that I was missing the > following line: > > rcc_periph_clock_enable(RCC_GPIOB); > > before my GPIO setup calls. Makes sense. The thing I'm confused > about now is the clock speed. With i2c_set_fast_mode(), I get a > clock speed of 178 kHz. With i2c_set_standard_mode(), it's 266 > kHz. Weird, shouldn't fast mode be.. faster? > > Also, one more thing: if I try and wait for "address > transferred" by doing: > > while (!(I2C_SR1(I2C1) & I2C_SR1_ADDR)); > > after the i2c_send_7bit_address() call, then it gets stuck > here. So I think I am still doing something wrong with the > setup. > > > On Sat, Aug 1, 2020 at 6:00 PM Chris Chronopoulos < > chronopoulos.ch...@gmail.com> wrote: > > > I've also noticed that if I put in the while-loops to check for status > > register updates, e.g. > > > > while (!((I2C_SR1(I2C1) & I2C_SR1_SB) > > & (I2C_SR2(I2C1) & (I2C_SR2_MSL | I2C_SR2_BUSY)))); > > > > Then this just gets stuck, confirming that the start condition is not > > being sent. > > > > On Sat, Aug 1, 2020 at 5:52 PM Chris Chronopoulos < > > chronopoulos.ch...@gmail.com> wrote: > > > >> Hi, just joined this list, not sure what the protocol is.. but I have a > >> question about getting I2C working on the STM32L1(52RE). > >> > >> First of all, I see that there are two versions of the I2C API: v1 and > >> v2. Can someone explain what the difference is between these? From digging > >> through the library, I can see that different device families use different > >> versions, e.g.: > >> > >> F0: v2 > >> F1: v1 > >> F2: v1 > >> F3: v2 > >> F4: v1 > >> F7: v2 > >> L0: v2 > >> L1: v1 > >> L4: v2 > >> > >> So when following code examples, I guess I need to find examples that use > >> the v1 API. In libopencm3-examples, the only STM32 I2C v1 example I could > >> find is this one for F1 > >> <https://github.com/libopencm3/libopencm3-examples/tree/master/examples/stm32/f1/other/i2c_stts75_sensor>. > >> Unfortunately, the i2c_setup() function in this code doesn't compile for > >> L1, because of some differences between the RCC and GPIO API's (namely, > >> RCC_AFIO and gpio_set_mode() are not defined for L1). So I made some > >> adjustments based on my best guesses, and ended up with this code > >> <https://gist.github.com/chronopoulos/d34de9b6119d4ec052451d6afaa99e79>, > >> which compiles. But, when I monitor the I2C lines with a logic analyzer, I > >> see nothing. Dead silence. > >> > >> Am I missing something? Can anyone provide an example of I2C being used > >> on STM32L1? > >> > >> > _______________________________________________ > libopencm3-devel mailing list > libopencm3-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libopencm3-devel
OpenPGP-digital-signature.html
Description: OpenPGP Digital Signature
_______________________________________________ libopencm3-devel mailing list libopencm3-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libopencm3-devel