Page 1 of 1

Understanding Arduino I2C library for Nucleo-L432KC

Posted: Wed Aug 11, 2021 8:47 pm
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);
}


Re: Understanding Arduino I2C library for Nucleo-L432KC

Posted: Wed Aug 11, 2021 9:11 pm
by fpiSTM
Do you have pull up resistors on each I2C lines?

Re: Understanding Arduino I2C library for Nucleo-L432KC

Posted: Thu Aug 12, 2021 2:17 am
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.

Re: Understanding Arduino I2C library for Nucleo-L432KC

Posted: Thu Aug 12, 2021 8:52 am
by fpiSTM
OK. I've tested and it works on my side.
i2C_NucleoL432KC.png
i2C_NucleoL432KC.png (19.94 KiB) Viewed 3328 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.

Re: Understanding Arduino I2C library for Nucleo-L432KC

Posted: Thu Aug 12, 2021 1:15 pm
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.

Re: Understanding Arduino I2C library for Nucleo-L432KC

Posted: Thu Aug 12, 2021 2:11 pm
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.