Page 1 of 1

Nucleo-64 STM32L476RG I2C not working

Posted: Fri Oct 22, 2021 7:24 pm
by nbourre
Hi guys,

I have a Nucleo-64 STM32L476RG and I did a simple program using the Cube[MX|IDE] to communicate with an I2C device and it works on pins A4 and A5.

On the other side using the Arduino IDE, I can't figure out what I'm doing wrong. The I2C scanner is not working in my case.

I'm surely missing something out.

Can someone guide me?

thank you

Re: Nucleo-64 STM32L476RG I2C not working

Posted: Fri Oct 22, 2021 7:58 pm
by fpiSTM
Scanner example uses the default pins which are:
#define PB9 14
#define PB8 15
Which are D14 ans D15 not A4 and A5.
See the wiki to known how to change default Wire instance pins.
And of course you need pull up on each I2C lines.

Re: Nucleo-64 STM32L476RG I2C not working

Posted: Sun Oct 24, 2021 8:49 pm
by nbourre
Thanks!

I managed to make it work using the following code before the begin():

Code: Select all

// ...
  Wire.setSDA(A4);
  Wire.setSCL(A5);
  
  if (!wire.begin()) {
// ... 
It works until, it starts to give plenty of 0s as values. I guess this is due to the lack of pullups.