当前位置:网站首页>Arduino Wire 库使用
Arduino Wire 库使用
2022-07-02 06:08:00 【谢娘蓝桥】
1. 扫描所有IIC 从设备
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not known.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for Serial Monitor
Serial.println("\nI2C Scanner");
}
void loop() {
int nDevices = 0;
Serial.println("Scanning...");
for (byte address = 1; address < 127; ++address) {
// The i2c_scanner uses the return value of
// the Wire.endTransmission to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
byte error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.print(address, HEX);
Serial.println(" !");
++nDevices;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.println(address, HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(5000); // Wait 5 seconds for next scan
}
2.写数据
Wire.beginTransmission(CLD_ADDR1);
Wire.write(&TAS6424_Write_data_1_4[i][0], 2);
Wire.endTransmission();3.指定从设备寄存器读取数据
//CLD_ADDR1 从设备地址
//读取一个数据,
//reg data 从设备地址
//地址位宽 1
//0 --不发送stop
Wire.requestFrom((uint8_t)CLD_ADDR1, 1,reg_addr,1,0);
while (Wire.available()) {
c = Wire.read(); // 以字符形式接受并读取从机发来的一个字节的数据
}
Serial.println(c, HEX); // 串口输出该字符
Wire.endTransmission();边栏推荐
- Flutter 混合开发: 开发一个简单的快速启动框架 | 开发者说·DTalk
- Shenji Bailian 3.52-prim
- keepalived安装使用与快速入门
- Current situation analysis of Devops and noops
- BGP 路由优选规则和通告原则
- Stc8h8k series assembly and C51 actual combat - digital display ADC, key serial port reply key number and ADC value
- Detailed steps of JS foreground parsing of complex JSON data "case: I"
- 500. Keyboard line
- Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
- 格式校验js
猜你喜欢

Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music

VRRP之监视上行链路

Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice

WLAN相关知识点总结

Frequently asked questions about jetpack compose and material you

ESP8266与STC8H8K单片机联动——天气时钟

Zhuanzhuanben - LAN construction - Notes

浏览器原理思维导图

Community theory | kotlin flow's principle and design philosophy

线性dp(拆分篇)
随机推荐
Scheme and implementation of automatic renewal of token expiration
Deep learning classification network -- vggnet
How vite is compatible with lower version browsers
Deep learning classification network -- alexnet
Servlet web XML configuration details (3.0)
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
ESP8266与STC8H8K单片机联动——天气时钟
官方零基础入门 Jetpack Compose 的中文课程来啦!
Talking about MySQL database
Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
Comment utiliser mitmproxy
Format check JS
The real definition of open source software
Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
Stc8h8k series assembly and C51 actual combat - keys allow key counting (using falling edge interrupt control)
Use some common functions of hbuilderx
Sumo tutorial Hello World
How to use mitmproxy
BGP 路由優選規則和通告原則