Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
I2C_Address_Scan.ino
Go to the documentation of this file.
1 /*
2 I2C Address Scan
3 
4 This program will scan all 128 I2C addresses on the QuikEval connector
5 and report all addresses that acknowledge an address+!w command.
6 
7 DATA TYPES:
8 char = 1 byte
9 int = 2 bytes
10 long = 4 bytes
11 float = 4 bytes
12 
13 
14 Copyright 2018(c) Analog Devices, Inc.
15 
16 All rights reserved.
17 
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20  - Redistributions of source code must retain the above copyright
21  notice, this list of conditions and the following disclaimer.
22  - Redistributions in binary form must reproduce the above copyright
23  notice, this list of conditions and the following disclaimer in
24  the documentation and/or other materials provided with the
25  distribution.
26  - Neither the name of Analog Devices, Inc. nor the names of its
27  contributors may be used to endorse or promote products derived
28  from this software without specific prior written permission.
29  - The use of this software may or may not infringe the patent rights
30  of one or more patent holders. This license does not release you
31  from the requirement that you obtain separate licenses from these
32  patent holders to use this software.
33  - Use of the software either in source or binary form, must be run
34  on or directly connected to an Analog Devices Inc. component.
35 
36 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
37 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
38 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
40 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
42 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
43 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  */
47 
48 // set I2C frequency in kHz
49 #define SW_I2C_FREQUENCY 400
50 
51 #include <Arduino.h>
52 #include <stdint.h>
53 #include "LT_I2C.h"
54 #include "QuikEval_EEPROM.h"
55 #include "UserInterface.h"
56 #include "Linduino.h"
57 
59 // Print the title block
60 {
61  Serial.println("");
62  Serial.println("*****************************************************************");
63  Serial.println("* I2C Address Scan *");
64  Serial.println("* *");
65  Serial.println("* This program will scan all 128 I2C addresses and report those *");
66  Serial.println("* that acknowledge a address+!w command. *");
67  Serial.println("* *");
68  Serial.println("* Set the baud rate to 115200 select the newline terminator. *");
69  Serial.println("* *");
70  Serial.println("*****************************************************************");
71 }
72 
73 void setup()
74 // Setup the program
75 {
76  quikeval_I2C_init(); // Enable the Software I2C
77  quikeval_I2C_connect(); // Connects to main I2C port
78  Serial.begin(115200); // Initialize the serial port to the PC
79  print_title();
80 }
81 
82 void loop()
83 {
84  unsigned char ack;
85  unsigned char address;
86  unsigned char ack_count;
87  Serial.println("\nSend any character to start the I2C address scan. (Press enter in Arduino Serial Monitor.)");
88  read_int();
89  ack_count = 0;
90  for (address = 0; address < 128; address++)
91  {
92  i2c_start();
93  ack = i2c_write(address << 1);
94  i2c_stop();
95  if (!ack)
96  {
97  ack_count++;
98  Serial.print("Acknowledge received from address : 0x");
99  Serial.print(address, HEX);
100  Serial.print(" (7 bit) 0x:");
101  Serial.print(address<<1, HEX);
102  Serial.println(" (8-bit)");
103  }
104  }
105  if (ack_count == 0) Serial.println("No addresses acknowledged.");
106 }
107 
108 
static void loop()
static void setup()
Header File for Linduino Libraries and Demo Code.
void i2c_stop()
Write stop bit to the hardware I2C port.
Definition: LT_I2C.cpp:462
int8_t i2c_start()
Write start bit to the hardware I2C port.
Definition: LT_I2C.cpp:425
static uint8_t address
Definition: DC2091A.ino:83
int8_t i2c_write(uint8_t data)
Send a data byte to hardware I2C port.
Definition: LT_I2C.cpp:470
static void print_title()
QuikEval EEPROM Library.
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
int32_t read_int()
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401