Understanding Arduino I2C library for Nucleo-L432KC

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
stm32_noob
Posts: 3
Joined: Wed Aug 11, 2021 8:30 pm

Understanding Arduino I2C library for Nucleo-L432KC

Post by stm32_noob »

Hi,

I am trying to get the I2C1 bus in master mode up and running on the Nucleo-L432KC board and I can't get it working. I am using the Wire and TwoWire class which don't work with the way I have the code written (below). I have tried setting the SDA and SCL pins using the setSDA() and setSCL() functions. I've tried altering the pin maps as suggest on this web page (https://github.com/stm32duino/wiki/wiki/API#i2C). Still nothing, I've checked the pins with an oscilloscope and there's no activity.

I know I'm missing something here but I have no idea what it is. I'm I missing a configuration setting in the setup() function? If you know please let me know.

Thanks.

Example code:

Code: Select all


void setup() {
	Wire.setSDA(D4);
	Wire.setSCL(D5);
	Wire.begin();
}

void loop() {
	Wire.beginTransmission(0b0101110);
	Wire.write(0x00);
        Wire.write(0x7A);
        Wire.endTransmission();
        
        delay(250);
}

by fpiSTM » Thu Aug 12, 2021 8:52 am
OK. I've tested and it works on my side.
i2C_NucleoL432KC.png
Maybe a wiring issue or solder bridge. For example by default SB16 and SB18 are ON so D4/D5 are connected to A4/A5.

Just a note about the setSDA and setSCL in your sketch , you don't need to use it as by default D4 and D5 are the default pins of the Wire instance for Nucleo L432KC.
Go to full post
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Understanding Arduino I2C library for Nucleo-L432KC

Post by fpiSTM »

Do you have pull up resistors on each I2C lines?
stm32_noob
Posts: 3
Joined: Wed Aug 11, 2021 8:30 pm

Re: Understanding Arduino I2C library for Nucleo-L432KC

Post by stm32_noob »

fpiSTM wrote: Wed Aug 11, 2021 9:11 pm Do you have pull up resistors on each I2C lines?
Yes I do, 4.7K on each line.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Understanding Arduino I2C library for Nucleo-L432KC

Post by fpiSTM »

OK. I've tested and it works on my side.
i2C_NucleoL432KC.png
i2C_NucleoL432KC.png (19.94 KiB) Viewed 2983 times
Maybe a wiring issue or solder bridge. For example by default SB16 and SB18 are ON so D4/D5 are connected to A4/A5.

Just a note about the setSDA and setSCL in your sketch , you don't need to use it as by default D4 and D5 are the default pins of the Wire instance for Nucleo L432KC.
stm32_noob
Posts: 3
Joined: Wed Aug 11, 2021 8:30 pm

Re: Understanding Arduino I2C library for Nucleo-L432KC

Post by stm32_noob »

fpiSTM wrote: Thu Aug 12, 2021 8:52 am OK. I've tested and it works on my side.
i2C_NucleoL432KC.png

Maybe a wiring issue or solder bridge. For example by default SB16 and SB18 are ON so D4/D5 are connected to A4/A5.

Just a note about the setSDA and setSCL in your sketch , you don't need to use it as by default D4 and D5 are the default pins of the Wire instance for Nucleo L432KC.
Thanks, that would explain the problem since I am using A4 and A5 for other stuff and had already initialized the IO.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Understanding Arduino I2C library for Nucleo-L432KC

Post by fpiSTM »

OK fine.
Please next time give us all information ;) This would help a lot to understand your issue.
If you need A4 an A5 you can remove the SB as explained in the user manual. Then you will be able to use all pins.
Post Reply

Return to “General discussion”