I2C2 bus instead of I2C1 - default pinout
Whole example code you finde here.
It is the same case like using of alternative pinout of I2C1.
You set the SDA (PB7) and SCL (PB6) through funtions and the STM32duino arduino package enables I2C2 bus instead of I2C1.
setSDA and setSCL.
The I2C2 is now default I2C bus.
#include "Wire.h"
#include "SI7021.h"
SI7021 sensor;
// the setup function runs once when you press reset or power the board
void setup()
{
Wire.setSCL(PB_6); // alternative pinout of I2C1_SCL - PB6 (Morpho con) instead of PB8 (D15)
Wire.setSDA(PB_7); // alternative pinout of I2C1_SDA - PB7 (D10) instead of PB9 (D14)
sensor.begin(); // initialization of Si7021 sensor
Serial.begin(9600); // initialization of Serial (STLink), 9600 Bd
// wait for serial
while (!Serial)
{
delay(100);
}
Serial.println("Test of Si7021 and STM32duino");
if (!sensor.begin())
{
Serial.println("Si7021 sensor wasn't found");
while (true);
}
}
// the loop function runs over and over again forever
void loop()
{
// send data through onboard USB-UART converter (STLink)
Serial.print("Temperature: ");
Serial.print(String(sensor.getCelsiusHundredths()/100.0, 2)); // 2450 = 24.50 ?C
Serial.println(" ?C");
Serial.print("Humidity: ");
Serial.print(sensor.getHumidityPercent());
Serial.println(" %");
delay(1000);
}
If you want to use I2C3 bus, the steps are the same like previous cases.
Don't forget to check PeripheralPins.cpp where are described pinouts of I2C buses.
|