打印
[开发工具]

STM32使用arduino开发的方式のIIC

[复制链接]
932|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主

使用特权

评论回复
沙发
goodluck09876|  楼主 | 2019-8-26 15:24 | 只看该作者

使用特权

评论回复
板凳
goodluck09876|  楼主 | 2019-8-26 15:25 | 只看该作者
#include "Wire.h"
#include "SI7021.h"

SI7021 sensor;

// the setup function runs once when you press reset or power the board
void setup()
{
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");

if (!sensor.begin())
{
Serial.println("Si7021 sensor wasn't found");
while (true);
}
}

使用特权

评论回复
地板
goodluck09876|  楼主 | 2019-8-26 15:25 | 只看该作者
// 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);
}

使用特权

评论回复
5
goodluck09876|  楼主 | 2019-8-26 15:25 | 只看该作者
I2C1 bus wit alternative pinout:
Whole example code you find here.
The important change is using of these fucntions. Wire.setSCL(PB6) and Wire.setSDA(PB7). These functions define where will be connected SDA and SCL of I2C. The connection has to corespond with document which is mentioned above (Pinout of Nucleo develepment boards).

#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(PB6); // alternative pinout of I2C1_SCL - PB6 (Morpho con) instead of PB8 (D15)
Wire.setSDA(PB7); // 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);
}

使用特权

评论回复
6
goodluck09876|  楼主 | 2019-8-26 15:26 | 只看该作者

使用特权

评论回复
7
goodluck09876|  楼主 | 2019-8-26 15:26 | 只看该作者
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.

使用特权

评论回复
8
goodluck09876|  楼主 | 2019-8-26 15:27 | 只看该作者

使用特权

评论回复
9
goodluck09876|  楼主 | 2019-8-26 15:27 | 只看该作者
看来 使用arduino 搞一个STM32的开发的确是一个很好的环境平台!

使用特权

评论回复
10
comparison| | 2019-8-26 15:32 | 只看该作者
全英文的啊!楼主厉害了

使用特权

评论回复
11
goodluck09876|  楼主 | 2019-8-26 17:11 | 只看该作者
这个是国外的一个网站!感觉比较新颖!没想到stm32还可以使用arduino来开发!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

220

主题

5843

帖子

21

粉丝