Difference between revisions of "Example i2c test"
Line 6: | Line 6: | ||
<code>I²C</code> is a two wire serial interface used to connect to a variety of sensor and I/O devices. The interface uses only two bi-directional open-drain I/Os, Serial Data Line (SDA) and Serial Clock (SCL), to communicate to devices based on an address encoded within the data transmission. SDA is a data signal which sends and receives serially transmitted data. SCL is a clock signal which is used to determine when to latch data from the SDA line. | <code>I²C</code> is a two wire serial interface used to connect to a variety of sensor and I/O devices. The interface uses only two bi-directional open-drain I/Os, Serial Data Line (SDA) and Serial Clock (SCL), to communicate to devices based on an address encoded within the data transmission. SDA is a data signal which sends and receives serially transmitted data. SCL is a clock signal which is used to determine when to latch data from the SDA line. | ||
− | This procedure provides an overview of how to compile and run the <code>i2c_test</code> C example project. This is an example test interface for reading/writing to the Linux I²C device interface. It is only relevant if the I²C device interface is enabled and an external I²C device is connected to the bus. It assumes familiarity with the C programming language and is intended to be used by experienced programmers who are looking to learn the EMAC SDK. | + | This procedure provides an overview of how to compile and run the <code>i2c_test</code> C example project. This is an example test interface for reading/writing to the Linux <code>I²C</code> device interface. It is only relevant if the <code>I²C</code> device interface is enabled and an external <code>I²C</code> device is connected to the bus. It assumes familiarity with the C programming language and is intended to be used by experienced programmers who are looking to learn the EMAC SDK. |
For more information about the protocol see the following page:http://en.wikipedia.org/wiki/I²C | For more information about the protocol see the following page:http://en.wikipedia.org/wiki/I²C | ||
Line 67: | Line 67: | ||
The slave address receives the clock and responds when addressed by the master. This is the lower 7 bits of the devices slave address. | The slave address receives the clock and responds when addressed by the master. This is the lower 7 bits of the devices slave address. | ||
− | This function is to set the slave address of the | + | This function is to set the slave address of the <code>I²C</code> device. This only need to be done once to initialize the address and then each time that a new device is addressed. |
* '''Write byte to register'''<br /> | * '''Write byte to register'''<br /> | ||
Line 87: | Line 87: | ||
i2c_write_cmd reports success | i2c_write_cmd reports success | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | This function is to write one byte to the <code>I²C</code> device. This should be changed to use the SMBus functions if possible. | |
* '''Write 2 bytes to register''' | * '''Write 2 bytes to register''' | ||
+ | <syntaxhighlight lang=console> | ||
+ | Select a function to test: | ||
+ | a: Set slave address | ||
+ | b: Write byte to register | ||
+ | c: Write 2 bytes to register | ||
+ | d: Read byte from register | ||
+ | e: Read 2 bytes from register | ||
+ | q: Quit | ||
+ | >> c | ||
+ | </syntaxhighlight> | ||
</cl> | </cl> |
Revision as of 17:53, 27 January 2014
Create a real intro. This is going to need quite a bit of work still.
This is a guide to the i2c_test
example project included in the EMAC OE SDK.
I²C
is a two wire serial interface used to connect to a variety of sensor and I/O devices. The interface uses only two bi-directional open-drain I/Os, Serial Data Line (SDA) and Serial Clock (SCL), to communicate to devices based on an address encoded within the data transmission. SDA is a data signal which sends and receives serially transmitted data. SCL is a clock signal which is used to determine when to latch data from the SDA line.
This procedure provides an overview of how to compile and run the i2c_test
C example project. This is an example test interface for reading/writing to the Linux I²C
device interface. It is only relevant if the I²C
device interface is enabled and an external I²C
device is connected to the bus. It assumes familiarity with the C programming language and is intended to be used by experienced programmers who are looking to learn the EMAC SDK.
For more information about the protocol see the following page:http://en.wikipedia.org/wiki/I²C
The i2c_test
project build one executable: i2c_test
.
Contents
Opening, Building and Uploading the Project Files
For information on opening the project from within Eclipse, please see Importing the EMAC OE SDK Projects with Eclipse. Then, follow Using the EMAC OE SDK Projects with Eclipse for information on how to build, upload and execute the example.
Alternatively, the Makefile
can be used with the make
command from the commandline to build and upload the example. For more information on this method, please see Using EMAC OE SDK Example Projects.
Usage and Behavior
Hardware Requirements
The i2c_test
C example project will run on any EMAC carrier board which has an I²C
interface.
This is far too sparse. They could discover this on their own. There needs to be information on how and why to use each option of these menus.
Using i2c_test
The i2c_test
program is executed from the console. It takes no parameters.
root@emac-oe~:$ ./i2c_test
A menu will appear in the terminal:
Select a function to test:
a: Set slave address
b: Write byte to register
c: Write 2 bytes to register
d: Read byte from register
e: Read 2 bytes from register
q: Quit
Select a function (a,b,c,d,e) to test or q to quit. You will be prompted for read, write and register values as appropriate. Test results will be displayed in the terminal.
Test Options
-
Set Slave Address
Press the A key to select the Set slave address function, then press Enter.Select a function to test: a: Set slave address b: Write byte to register c: Write 2 bytes to register d: Read byte from register e: Read 2 bytes from register q: Quit >> a Enter the slave address (in hex): 48 Calling i2c_set_slave(3, 0x48) i2c_set_slave reports success
The slave address receives the clock and responds when addressed by the master. This is the lower 7 bits of the devices slave address.
This function is to set the slave address of the
I²C
device. This only need to be done once to initialize the address and then each time that a new device is addressed. -
Write byte to register
Press the B key to select the Write byte to register function, then press EnterSelect a function to test: a: Set slave address b: Write byte to register c: Write 2 bytes to register d: Read byte from register e: Read 2 bytes from register q: Quit >> b Enter a byte to write (in hex): aa Enter a register value to write (in hex): 01 Calling i2c_write_cmd(3, 0x1, 0xAA) i2c_write_cmd reports success
This function is to write one byte to the
I²C
device. This should be changed to use the SMBus functions if possible. -
Write 2 bytes to register
Select a function to test: a: Set slave address b: Write byte to register c: Write 2 bytes to register d: Read byte from register e: Read 2 bytes from register q: Quit >> c