Skip to content

Commit 2b97b8d

Browse files
committed
0.1.11 version
1 parent d36fddb commit 2b97b8d

File tree

5 files changed

+117
-79
lines changed

5 files changed

+117
-79
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2013-2020 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

sketches/MultiSpeedI2CScanner/MultiSpeedI2CScanner.ino

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
//
22
// FILE: MultiSpeedI2CScanner.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.10
4+
// VERSION: 0.1.11
55
// PURPOSE: I2C scanner at different speeds
66
// DATE: 2013-11-05
7+
// URL: https://github.com/RobTillaart/MultiSpeedI2CScanner
78
// URL: http://forum.arduino.cc/index.php?topic=197360
89
//
9-
// Released to the public domain
10-
//
1110

12-
#include <Wire.h>
1311
#include <Arduino.h>
12+
#include <Wire.h>
1413

1514
TwoWire *wi;
1615

17-
const char version[] = "0.1.10";
16+
const char version[] = "0.1.11";
1817

1918

2019
// INTERFACE COUNT (TESTED TEENSY 3.5 AND ARDUINO DUE ONLY)
@@ -23,8 +22,7 @@ int selectedWirePort = 0;
2322

2423

2524
// scans devices from 50 to 800KHz I2C speeds.
26-
// lower than 50 is not possible
27-
// DS3231 RTC works on 800 KHz. TWBR = 2; (?)
25+
// speed lower than 50 and above 400 can cause problems
2826
long speed[10] = { 100, 200, 300, 400 };
2927
int speeds;
3028

@@ -42,7 +40,7 @@ bool delayFlag = false;
4240
// MINIMIZE OUTPUT
4341
bool printAll = true;
4442
bool header = true;
45-
43+
bool disableIRQ = false;
4644

4745
// STATE MACHINE
4846
enum states {
@@ -61,8 +59,8 @@ void setup()
6159
Serial.begin(115200);
6260

6361
#if defined (ESP8266) || defined(ESP32)
64-
uint8_t sda = 15;
65-
uint8_t scl = 2;
62+
uint8_t sda = 21;
63+
uint8_t scl = 22;
6664
Wire.begin(sda, scl, 100000); // ESP32 - change config pins if needed.
6765
#else
6866
Wire.begin();
@@ -90,6 +88,7 @@ void setup()
9088

9189
void loop()
9290
{
91+
yield();
9392
char command = getCommand();
9493
switch (command)
9594
{
@@ -147,6 +146,11 @@ void loop()
147146
Serial.print(F("<print="));
148147
Serial.println(printAll ? F("all>") : F("found>"));
149148
break;
149+
case 'i':
150+
disableIRQ = !disableIRQ;
151+
Serial.print(F("<irq="));
152+
Serial.println(disableIRQ ? F("diabled>") : F("enabled>"));
153+
break;
150154

151155
case '0':
152156
case '1':
@@ -300,6 +304,7 @@ void displayHelp()
300304
Serial.println(F("\tc = continuous scan - 1 second delay"));
301305
Serial.println(F("\tq = quit continuous scan"));
302306
Serial.println(F("\td = toggle latency delay between successful tests. 0 - 5 ms"));
307+
Serial.println(F("\ti = toggle enable/disable interrupts"));
303308

304309
Serial.println(F("Output:"));
305310
Serial.println(F("\tp = toggle printAll - printFound."));
@@ -309,7 +314,7 @@ void displayHelp()
309314
Serial.println(F("Speeds:"));
310315
Serial.println(F("\t0 = 100..800 Khz - step 100 (warning - can block!!)"));
311316
Serial.println(F("\t1 = 100 KHz"));
312-
Serial.println(F("\t2 = 200 KH"));
317+
Serial.println(F("\t2 = 200 KHz"));
313318
Serial.println(F("\t4 = 400 KHz"));
314319
Serial.println(F("\t9 = 50..400 Khz - step 50 < DEFAULT >"));
315320
Serial.println();
@@ -328,6 +333,8 @@ void I2Cscan()
328333
startScan = millis();
329334
uint8_t count = 0;
330335

336+
if (disableIRQ) noInterrupts();
337+
331338
if (header)
332339
{
333340
Serial.print(F("TIME\tDEC\tHEX\t"));
@@ -344,18 +351,6 @@ void I2Cscan()
344351
Serial.println();
345352
}
346353

347-
// TEST
348-
// 0.1.04: tests only address range 8..120
349-
// --------------------------------------------
350-
// Address R/W Bit Description
351-
// 0000 000 0 General call address
352-
// 0000 000 1 START byte
353-
// 0000 001 X CBUS address
354-
// 0000 010 X reserved - different bus format
355-
// 0000 011 X reserved - future purposes
356-
// 0000 1XX X High Speed master code
357-
// 1111 1XX X reserved - future purposes
358-
// 1111 0XX X 10-bit slave addressing
359354
for (uint8_t address = addressStart; address <= addressEnd; address++)
360355
{
361356
bool printLine = printAll;
@@ -364,12 +359,15 @@ void I2Cscan()
364359

365360
for (uint8_t s = 0; s < speeds ; s++)
366361
{
362+
yield(); // keep ESP happy
367363

368364
#if ARDUINO < 158 && defined (TWBR)
365+
uint16_t PREV_TWBR = TWBR;
369366
TWBR = (F_CPU / (speed[s] * 1000) - 16) / 2;
370367
if (TWBR < 2)
371368
{
372369
Serial.println("ERROR: not supported speed");
370+
TWBR = PREV_TWBR;
373371
return;
374372
}
375373
#else
@@ -413,4 +411,8 @@ void I2Cscan()
413411
Serial.print(stopScan - startScan);
414412
Serial.println(F(" milliseconds."));
415413
}
414+
415+
interrupts();
416416
}
417+
418+
// -- END OF FILE --

sketches/MultiSpeedI2CScanner/readme.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2-
# Arduino MultiSpeed I2C Scanner - 0.1.10
2+
# Arduino MultiSpeed I2C Scanner
3+
4+
## Version: 0.1.11
5+
6+
## Description
37

48
MultiSpeedI2CScanner is a menu driven I2C scanner, see below.
59
The scanner is tested on an UNO and an ESP32.
@@ -8,7 +12,7 @@ The scanner provides an overview of which addresses can be found
812
at which speed. This allows one to optimize the I2C performance of
913
many devices above the standard 100KHz speed.
1014

11-
# Menu dialog
15+
## Menu dialog
1216

1317
```
1418
<speeds = 50 100 150 200 250 300 350 400 >
@@ -22,6 +26,7 @@ Scan mode:
2226
c = continuous scan - 1 second delay
2327
q = quit continuous scan
2428
d = toggle latency delay between successful tests. 0 - 5 ms
29+
i = toggle enable/disable interrupts
2530
Output:
2631
p = toggle printAll - printFound.
2732
h = toggle header - noHeader.
@@ -46,11 +51,13 @@ Speeds:
4651
## Functions
4752

4853
### I2C ports
54+
4955
**@** selects through the different Wire ports.
5056
Note that the current Wire port is given after I2C ports: count
5157
Wire0 is just Wire but it was easier to program.
5258

5359
### Scan mode
60+
5461
**s** selects single scan mode, think of it as manual.
5562

5663
**c** selects continuous scanning, think of it as automatic.
@@ -60,7 +67,10 @@ Wire0 is just Wire but it was easier to program.
6067
**d** toggles the latency between successful scans.
6168
Only needed sometimes.
6269

70+
**i** toggles disable/enable interrupts, use with care.
71+
6372
### Output selection
73+
6474
**p** toggles printAll and printFound.
6575
PrintAll will print also the addresses where nothing is found.
6676
PrintFound will only generate a line if an I2C device is found on that address.
@@ -74,13 +84,11 @@ but as some addresses are reserved, one can limit this range to 8 .. 120 .
7484

7585
All options here select a single speed or a range of speeds.
7686

77-
Since 0.1.10 experimental speeds of 1000, 3400 and 5000 are added as
78-
these are part of the I2C standards.
87+
Since 0.1.10 version experimental speeds of 1000, 3400 and 5000 are added as
88+
these are part of the I2C standards.
89+
http://i2c.info/i2c-bus-specification
7990

80-
NOTE: not all processors will support these speeds.
91+
NOTE: not all processors will support these higher speeds.
8192
This can show up as blocking or it can even look like it is working.
8293
Check your datasheet to see which speeds are applicable for the processor in use.
8394

84-
85-
86-
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Release Notes
2+
3+
MultiSpeedI2CScanner
4+
5+
## Version
6+
7+
0.1.11
8+
9+
### 0.1.11 2018-07-20
10+
11+
+ Fix failing TWBR setting
12+
+ added yield() during scan to improve ESP behavior.
13+
+ added disable interrupts flag
14+
+ refactor / cleanup
15+
16+
### 0.1.10 2018-04-02
17+
18+
+ Fix #152
19+
+ improved support for ESP32
20+
+ changed multispeed ranges a bit (option 0 and 9)
21+
+ refactor
22+
+ added experimental high speeds 1000, 3400, 5000 KHz.
23+
24+
verified on UNO and ESP32,
25+
note the latter one must adjust the pins in the code.
26+
27+
### 0.1.9 2018-04-02
28+
29+
+ '9' command to scan up to 400 KHz only to prevent blocking
30+
+ changed "scan up to 400 KHz" as default at startup
31+
32+
### 0.1.8 2017-08-03
33+
34+
+ DUE support
35+
36+
### 0.1.7 2017-07-17
37+
38+
+ TEENSY support - multiple I2C ports
39+
+ '@' command to select I2C Port
40+
+ changed # speeds steps of 100
41+
42+
### 0.1.6 2015-03-29
43+
44+
+ Wire.setClock as more portable way to set I2C clock
45+
46+
### 0.1.5 2014-07-06
47+
48+
+ void setSpeed() - more control about what is scanned
49+
+ void setAddress() - address range
50+
+ extended help
51+
52+
### older versions not documented
53+
54+
55+
// END OF FILE

sketches/MultiSpeedI2CScanner/releaseNotes.txt

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)