mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
+ 0.1.06 support Wire.setClock()
+ reindent
This commit is contained in:
parent
b89c9decb0
commit
2e49f9234a
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: MultiSpeedI2CScanner.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.05
|
||||
// VERSION: 0.1.06
|
||||
// PURPOSE: I2C scanner @different speeds
|
||||
// DATE: 2013-11-05
|
||||
// URL: http://forum.arduino.cc/index.php?topic=197360
|
||||
@ -12,14 +12,15 @@
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
const char version[] = "0.1.05";
|
||||
const char version[] = "0.1.06";
|
||||
|
||||
// scans devices from 50 to 800KHz I2C speeds.
|
||||
// lower than 50 is not possible
|
||||
// DS3231 RTC works on 800 KHz. TWBR = 2; (?)
|
||||
const long allSpeed[] = {
|
||||
50, 100, 200, 250, 400, 500, 800 };
|
||||
long speed[sizeof(allSpeed)/sizeof(allSpeed[0])];
|
||||
50, 100, 200, 250, 400, 500, 800
|
||||
};
|
||||
long speed[sizeof(allSpeed) / sizeof(allSpeed[0])];
|
||||
int speeds;
|
||||
|
||||
int addressStart = 0;
|
||||
@ -35,7 +36,8 @@ bool header = true;
|
||||
|
||||
// STATE MACHINE
|
||||
enum states {
|
||||
STOP, ONCE, CONT, HELP };
|
||||
STOP, ONCE, CONT, HELP
|
||||
};
|
||||
states state = STOP;
|
||||
|
||||
uint32_t startScan;
|
||||
@ -64,7 +66,7 @@ void loop()
|
||||
case 'd':
|
||||
delayFlag = !delayFlag;
|
||||
Serial.print(F("<delay="));
|
||||
Serial.println(delayFlag?F("5>"):F("0>"));
|
||||
Serial.println(delayFlag ? F("5>") : F("0>"));
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
@ -74,12 +76,12 @@ void loop()
|
||||
case 'h':
|
||||
header = !header;
|
||||
Serial.print(F("<header="));
|
||||
Serial.println(header?F("yes>"):F("no>"));
|
||||
Serial.println(header ? F("yes>") : F("no>"));
|
||||
break;
|
||||
case 'p':
|
||||
printAll = !printAll;
|
||||
Serial.print(F("<print="));
|
||||
Serial.println(printAll?F("all>"):F("found>"));
|
||||
Serial.println(printAll ? F("all>") : F("found>"));
|
||||
break;
|
||||
|
||||
case '0':
|
||||
@ -102,7 +104,7 @@ void loop()
|
||||
break;
|
||||
}
|
||||
|
||||
switch(state)
|
||||
switch (state)
|
||||
{
|
||||
case ONCE:
|
||||
I2Cscan();
|
||||
@ -146,7 +148,7 @@ void setAddress()
|
||||
|
||||
void setSpeed(char sp)
|
||||
{
|
||||
switch(sp)
|
||||
switch (sp)
|
||||
{
|
||||
case '1':
|
||||
speed[0] = 100;
|
||||
@ -164,9 +166,9 @@ void setSpeed(char sp)
|
||||
speed[0] = 800;
|
||||
speeds = 1;
|
||||
break;
|
||||
case '0':
|
||||
speeds = sizeof(allSpeed)/sizeof(allSpeed[0]);
|
||||
for (int i=0; i< speeds; i++)
|
||||
case '0': // reset
|
||||
speeds = sizeof(allSpeed) / sizeof(allSpeed[0]);
|
||||
for (int i = 0; i < speeds; i++)
|
||||
{
|
||||
speed[i] = allSpeed[i];
|
||||
}
|
||||
@ -250,7 +252,11 @@ void I2Cscan()
|
||||
|
||||
for (uint8_t s = 0; s < speeds ; s++)
|
||||
{
|
||||
TWBR = (F_CPU/(speed[s]*1000) - 16)/2;
|
||||
#if ARDUINO >= 158
|
||||
Wire.setClock(speed[s] * 1000);
|
||||
#else
|
||||
TWBR = (F_CPU / (speed[s] * 1000) - 16) / 2;
|
||||
#endif
|
||||
Wire.beginTransmission (address);
|
||||
found[s] = (Wire.endTransmission () == 0);
|
||||
fnd |= found[s];
|
||||
@ -274,7 +280,7 @@ void I2Cscan()
|
||||
for (uint8_t s = 0; s < speeds ; s++)
|
||||
{
|
||||
Serial.print(F("\t"));
|
||||
Serial.print(found[s]? F("V"):F("."));
|
||||
Serial.print(found[s] ? F("V") : F("."));
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user