cancel
Showing results for 
Search instead for 
Did you mean: 

SPI and I2C Pin Conflict Issue on NUCLEO-L412KB

marianoo2001
Associate II

 

Hardware Setup

  • Board: NUCLEO-L412KB
  • Peripherals:
    • SD Card (SPI1)
    • Temperature Sensor (I2C1)

Original Pin Configuration (SPI Not Working properly)

SD Card (SPI1):
CS: PA5
MISO: PA6
MOSI: PA7
CK: PA1
Temperature Sensor (I2C1):
SDA: PB7
SCL: PB6

Issue Description

When using both SPI1 and I2C1 peripherals simultaneously with the above pin configuration, the SPI communication fails to work properly. Interestingly, when commenting out the I2C initialization, the SPI communication functions correctly.

Working Solution

I resolved the issue by remapping the pins as follows:

 

 
Modified Pins:
SPI1_MOSI: Changed to PB5
I2C1_SDA: Changed to PA10
I2C1_SCL: Changed to PA9

After this remapping, both peripherals work correctly together.

Suggestion

This pin conflict might be worth documenting in the board's errata, as the original configuration leads to unexpected behavior when using these common peripherals together.

Has anyone else encountered similar issues with this board when using SPI1 and I2C1 simultaneously?

1 ACCEPTED SOLUTION

Accepted Solutions

Hey, my intention was only red flagging this situation in case it was clear why this was happening. 
But if it is not it is not worth it to keep digging since for me, with this remapping I mentioned it worked.

THank you very much for your time. I will set this thread solved.

View solution in original post

12 REPLIES 12
ELABI.1
ST Employee

Hi @marianoo2001 

For the SPI1 configuration, why did you choose pin PA5 as CS? According to the datasheet, pins PA4 and PB0 can be used as CS, while pin PA5 is used for SCK.

Have you tried configuring I2C with pins PB7 & PB6 alone without using SPI1? If so, did it work or not? This would help determine if the issue is related to I2C.

Thank you.

ELABI.1

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @ELABI.1,

Let me clarify regarding your questions:

  1. Regarding PA5 as CS:
    • I'm using PA5 as a General Purpose Output (GPIO), not as the SPI1_NSS pin
    • The CS control is handled by the SD Card Library through this GPIO
    • PA1 is used for SPI1_SCK (clock), not PA5
  2. Regarding I2C1 testing:
    • Yes, I tested I2C1 (PB7 & PB6) alone first - it worked perfectly
    • The issue only appeared when combining both peripherals

To better explain the sequence of events:

  1. Initial setup with SPI1 worked fine:
    SD Card (SPI1):- CS (GPIO): PA5- MISO:     PA6- MOSI:     PA7- SCK:      PA1
  2. The problem emerged when:
  • Started fresh project
  • Configured SPI1 + SD Card libraries -> Working correctly
  • Added I2C1 (PB7&PB6) in IOC -> SD card stopped mounting
  • Disabled I2C1 in IOC -> SD card worked again
  1. This suggests a peripheral conflict rather than a pin configuration issue. After finding similar issues documented in other STM32 erratas, I resolved it by remapping:

    • SPI1_MOSI to PB5
    • I2C1_SDA to PA10
    • I2C1_SCL to PA9

    Now both peripherals work correctly together. Hope this helps clarify the situation.

Thanks in advance.

 


@marianoo2001 wrote:
  1. This suggests a peripheral conflict .


Or a problem in the software.

Have you tried debugging why the  SD Card is not mounting?

Hi @Andrew Neil,

Yes, I did extensive debugging to isolate the issue:

  1. I had two identical programs running on the same hardware:
    • Program A (Working): SD Card library + SPI enabled
    • Program B (Not Working): Same exact code + I2C enabled
  2. Using a logic analyzer, I compared the SPI signals between both programs:
    • The initial SD Card command sequences were identical from the MCU side
    • Program A: SD Card responded properly and completed the mounting sequence
    • Program B: SD Card didn't respond to the same command, causing the mounting sequence to fail

Key observation: Using the exact same:

  • Hardware setup
  • SD Card
  • Base program
  • SD Card library code

The only difference was enabling I2C in the IOC. This simple action consistently reproduced the issue:

  1. Start with working SD Card program
  2. Enable I2C in IOC
  3. SD Card immediately stops mounting
  4. Disable I2C in IOC
  5. SD Card works again

While I've found a workaround by remapping the pins, I'm sharing this because:

  1. The issue is consistently reproducible
  2. It appears to be a hardware/peripheral interaction issue rather than software
  3. Other developers might encounter the same problem

I leave it to you whether this warrants further investigation. If you believe it's purely a software issue, feel free to close this thread. However, the fact that merely enabling I2C in IOC (without any code changes) causes the SD Card to stop working suggests a deeper peripheral interaction issue.





 

What activity is happening on the I2C?

@marianoo2001 wrote:
  1. After finding similar issues documented in other STM32 erratas, I resolved it by remapping:


 Could you please precise where did you find a similar issue please?Thanks.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Similar issue I found, for another board, that made me try different pins configurations: 

https://community.st.com/t5/stm32-mcus-products/spi-stops-working-when-enable-i2c/td-p/98433

 

Regards,

Mariano.-

 

Even with no code related to I2C, at the moment I enable I2C it stopped working.

Regards.


@marianoo2001 wrote:

Similar issue I found, for another board, that made me try different pins configurations: 

https://community.st.com/t5/stm32-mcus-products/spi-stops-working-when-enable-i2c/td-p/98433


So have you checked your chip's Errata - is the same thing mentioned there?

Or anything else relevant?