I2c with Nucleo L476

Development environment specific, Arduino, Eclipse, VS2013, Em::Blocks etc
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

I2c with Nucleo L476

Post by mebab »

I have two questions:
1. My Arduino uses the I2c protocol to communicate with an external RTC and it works fine. However, I cannot use it with Nucleo 64 L476. Does anybody know how to define an I2C device while programming Nucleo64 L476 with ArduinoIDE? It looks like the STM doesn't recognize I2c device!

2. Is there a way to activate the internal RTC of Nucleo by Arduino IDE?

Thanks for any help!
by fpiSTM » Thu Aug 27, 2020 4:30 pm
On Nucleo L476 you can use A4/A5 for I2C.

If you want use the default Wire instance then simply do before the Wire.begin():

Code: Select all

Wire.setSDA(PC1); //A4
Wire.setSCL(PC0); // A5
Wire.begin()
or define your own wire instance.

FYI:
https://github.com/stm32duino/wiki/wiki/API#i2C
Go to full post
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: I2c with Nucleo L476

Post by GonzoG »

User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: I2c with Nucleo L476

Post by fpiSTM »

For 1: did you use a PULL UP resistor on each line? Wire is defined by default using pins D14/D15
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: I2c with Nucleo L476

Post by mebab »

Thanks a lot for the Great comments given by GonzoG and fpiSTM!
I could implement the STM32 internal RTC. Though I need to find out how to supply it with a Lithium Cell Battery to keep data permanently.
I also will pull up the lines SDA and SCK soon to see if it works. I still wonder how I didn't need these resistors in Arduino but I need them in STM32 board!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: I2c with Nucleo L476

Post by fpiSTM »

Probably the internal pull-up resistors of the Arduino microcontroller are enabled in the library.
For STM32, they are not enabled by default because it is better to use external one.
For the battery you will have to connect it to vbat. https://os.mbed.com/users/gregeric/note ... n-stm32-n/
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: I2c with Nucleo L476

Post by GonzoG »

To power RTC connect 3V battery to VBAT and GND.
Schowek-2.jpg
Schowek-2.jpg (23.13 KiB) Viewed 9077 times
To use RTC with VBAT power, you need to set clock source to LSE

Code: Select all

rtc.setClockSource(STM32RTC::LSE_CLOCK);
before starting RTC.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: I2c with Nucleo L476

Post by mebab »

fpiSTM wrote: Tue Aug 25, 2020 5:44 pm For 1: did you use a PULL-UP resistor on each line? Wire is defined by default using pins D14/D15
I pulled up both pins (D14 and D15) with two 10k resistors. I even pulled up A4 and A5 that are marked as SCL and SDA. However, The RTC board is not diagnosed yet.
I even run I2cScanner to see if my I2c device (RTC) is detected, but it is not! It looks like I2c lines are not connected somehow!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: I2c with Nucleo L476

Post by fpiSTM »

I2c works on L476. I use it daily.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: I2c with Nucleo L476

Post by mebab »

fpiSTM wrote: Wed Aug 26, 2020 9:06 pm I2c works on L476. I use it daily.
Based on your help. I am happy to figure out some points in this regard:

It is correct that (D14 and D15) on Nucleo L476 are (SDA and SCL). In addition, A4-A5 pins are also marked as SDA-SCL. However, in Arduino, these two pins are connected to A4 and A5 where this is not the case in Nucleo L476. I don't know why!
If I connect my RTC directly to SDA and SCL on Nucleo, it will work as you mentioned. However, it won't work if you connect it through A4-A5 which was my problem.

There is an important point that: some Arduino related shields (usually SPI shields such as SD card shields) are designed to connect to Arduino in a way that they are connected to A4-A5 and not to SDA-SCL because they don't need SDA-SCL. Then, if you connect another I2c shield on top of that SPI shield, it won't be connected to SCL-SDA as well. This won't be a problem if you use Arduino. This is because, as mentioned, A4-A5 pins are already connected to SDA-SCL. However, if you use Nucleo your I2c shield will not be diagnosed. The only way is to make sure that your SDA-SCL pins are connected to A4-A5 that I don't know how?

I decided to use SDA (D14)-SCL (D15) on Nucleo L476 instead of relying on A4-A5. This solved my problem!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: I2c with Nucleo L476

Post by fpiSTM »

On Nucleo L476 you can use A4/A5 for I2C.

If you want use the default Wire instance then simply do before the Wire.begin():

Code: Select all

Wire.setSDA(PC1); //A4
Wire.setSCL(PC0); // A5
Wire.begin()
or define your own wire instance.

FYI:
https://github.com/stm32duino/wiki/wiki/API#i2C
Post Reply

Return to “IDE's”