8 years, 4 months ago.

Can SPI and I2C1 & I2C2 be enabled at the same time ?

Hello. Working with the Nucleo F072RB based board and the results are very positive using a local SPI based LCD display (Alternate function # 0 as per GPIO use inside STM32F072 datasheet). Now, wish to chat with 2 I2C devices (fixed address and same address for each function) but this appears to involve Alternate function #1 as per GPIO use inside STM32F072 datasheet).

Is it possible to have enabled all of the following functions on the STM32F072 ? or any other STM32F processor ?

SPI I2C1 I2C2

If the port pins are mapped using mbed for I2C then the compiled code fails to function with the SPI LCD.

Can the SPI function be disabled after its use (ie. after LCD is enabled and displaying correct data so does not need to be refreshed) ? Then I2Cx could be enabled to perform its task and then SPI LCD enabled again and keep this loop going...

Any ideas are welcomed else will have to consider another co-processor idea (MBED + another to split the tasks).

Here is the SPI LCD definition (works): SPI_TFT_ILI9341 TFT(PA_7, PA_6, PA_5, PA_4, PA_0, PA_1,"TFT"); /* mosi, miso, sclk, cs, reset, dc */

Here is the I2C definition (breaks the above operation): I2C i2c1(PB_8, PB_9);

I2C i2c1(PB_6, PB_7); /* also does not work and breaks the above SPI code use */

Update - After much reading, does not appear that the STM32F series Nucleo boards (072RB / 401RE) will do the trick. Instead, the KL25Z (Freescale / NXP) with ALT2 configuration looks to be suitable to allow for the SPI + I2C0 + I2C1 ports to be all enabled. Will confirm the details tomorrow !!

1 Answer

8 years, 4 months ago.

There should be no issue with declaring SPI on PA7-PA4 and I2C1 on D15,D14, I2C2 on PB10,PB11. I suspect something else is wrong.

Accepted Answer

Thank you Bill ! You forced us to do a thorough review and very embarrassed to say the issue was the wrong definition in our code for SDA & SCL. That is, had the 2 pins reversed in the code and that can cause the code to break the SPI port (LCD stopped working). Nasty stuff but great to have it now working. The Beagle bus analyzer is spewing working I2C transactions on both of the 2 x I2C ports that are now enabled. Many thanks again Bill for your time !!

posted by Sanjiv Bhatia 15 Dec 2015