1 /******************************************************************************
2 *  Filename:       i2c_doc.h
3 *  Revised:        2016-03-30 13:03:59 +0200 (Wed, 30 Mar 2016)
4 *  Revision:       45971
5 *
6 *  Copyright (c) 2015 - 2020, Texas Instruments Incorporated
7 *  All rights reserved.
8 *
9 *  Redistribution and use in source and binary forms, with or without
10 *  modification, are permitted provided that the following conditions are met:
11 *
12 *  1) Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *
15 *  2) Redistributions in binary form must reproduce the above copyright notice,
16 *     this list of conditions and the following disclaimer in the documentation
17 *     and/or other materials provided with the distribution.
18 *
19 *  3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 *     be used to endorse or promote products derived from this software without
21 *     specific prior written permission.
22 *
23 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 *  POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36 //! \addtogroup i2c_api
37 //! @{
38 //! \section sec_i2c Introduction
39 //!
40 //! The Inter-Integrated Circuit (\i2c) API provides a set of functions for using
41 //! the \ti_device \i2c master and slave module. Functions are provided to perform
42 //! the following actions:
43 //! - Initialize the \i2c module.
44 //! - Send and receive data.
45 //! - Obtain status.
46 //! - Manage interrupts for the \i2c module.
47 //!
48 //! The \i2c master and slave module provide the ability to communicate to other IC
49 //! devices over an \i2c bus. The \i2c bus is specified to support devices that can
50 //! both transmit and receive (write and read) data. Also, devices on the \i2c bus
51 //! can be designated as either a master or a slave. The \ti_device \i2c module
52 //! supports both sending and receiving data as either a master or a slave, and also
53 //! support the simultaneous operation as both a master and a slave. Finally, the
54 //! \ti_device \i2c module can operate at two speeds: standard (100 kb/s) and fast
55 //! (400 kb/s).
56 //!
57 //! The master and slave \i2c module can generate interrupts. The \i2c master
58 //! module generates interrupts when a transmit or receive operation
59 //! completes (or aborts due to an error).
60 //! The \i2c slave module can generate interrupts when data is
61 //! sent or requested by a master and when a START or STOP condition is present.
62 //!
63 //! \section sec_i2c_master Master Operations
64 //!
65 //! When using this API to drive the \i2c master module, the user must first
66 //! initialize the \i2c master module with a call to \ref I2CMasterInitExpClk(). This
67 //! function sets the bus speed and enables the master module.
68 //!
69 //! The user may transmit or receive data after the successful initialization of
70 //! the \i2c master module. Data is transferred by first setting the slave address
71 //! using \ref I2CMasterSlaveAddrSet(). This function is also used to define whether
72 //! the transfer is a send (a write to the slave from the master) or a receive (a
73 //! read from the slave by the master). Then, if connected to an \i2c bus that has
74 //! multiple masters, the \ti_device \i2c master must first call \ref I2CMasterBusBusy()
75 //! before trying to initiate the desired transaction. After determining that
76 //! the bus is not busy, if trying to send data, the user must call the
77 //! \ref I2CMasterDataPut() function. The transaction can then be initiated on the bus
78 //! by calling the \ref I2CMasterControl() function with any of the following commands:
79 //!  - \ref I2C_MASTER_CMD_SINGLE_SEND
80 //!  - \ref I2C_MASTER_CMD_SINGLE_RECEIVE
81 //!  - \ref I2C_MASTER_CMD_BURST_SEND_START
82 //!  - \ref I2C_MASTER_CMD_BURST_RECEIVE_START
83 //!
84 //! Any of these commands result in the master arbitrating for the bus,
85 //! driving the start sequence onto the bus, and sending the slave address and
86 //! direction bit across the bus. The remainder of the transaction can then be
87 //! driven using either a polling or interrupt-driven method.
88 //!
89 //! For the single send and receive cases, the polling method involves looping
90 //! on the return from \ref I2CMasterBusy(). Once the function indicates that the \i2c
91 //! master is no longer busy, the bus transaction is complete and can be
92 //! checked for errors using \ref I2CMasterErr(). If there are no errors, then the data
93 //! has been sent or is ready to be read using \ref I2CMasterDataGet(). For the burst
94 //! send and receive cases, the polling method also involves calling the
95 //! \ref I2CMasterControl() function for each byte transmitted or received
96 //! (using either the \ref I2C_MASTER_CMD_BURST_SEND_CONT or \ref I2C_MASTER_CMD_BURST_RECEIVE_CONT
97 //! commands), and for the last byte sent or received (using either the
98 //! \ref I2C_MASTER_CMD_BURST_SEND_FINISH or \ref I2C_MASTER_CMD_BURST_RECEIVE_FINISH
99 //! commands).
100 //!
101 //! If any error is detected during the burst transfer,
102 //! the appropriate stop command (\ref I2C_MASTER_CMD_BURST_SEND_ERROR_STOP or
103 //! \ref I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP) should be used to call the
104 //! \ref I2CMasterControl() function.
105 //!
106 //! For the interrupt-driven transaction, the user must register an interrupt
107 //! handler for the \i2c devices and enable the \i2c master interrupt; the interrupt
108 //! occurs when the master is no longer busy.
109 //!
110 //! \section sec_i2c_slave Slave Operations
111 //!
112 //! When using this API to drive the \i2c slave module, the user must first
113 //! initialize the \i2c slave module with a call to \ref I2CSlaveInit(). This function
114 //! enables the \i2c slave module and initializes the address of the slave. After the
115 //! initialization completes, the user may poll the slave status using
116 //! \ref I2CSlaveStatus() to determine if a master requested a send or receive
117 //! operation. Depending on the type of operation requested, the user can call
118 //! \ref I2CSlaveDataPut() or \ref I2CSlaveDataGet() to complete the transaction.
119 //! Alternatively, the \i2c slave can handle transactions using an interrupt handler
120 //! registered with \ref I2CIntRegister(), and by enabling the \i2c slave interrupt.
121 //!
122 //! \section sec_i2c_api API
123 //!
124 //! The \i2c API is broken into three groups of functions:
125 //! those that handle status and initialization, those that
126 //! deal with sending and receiving data, and those that deal with
127 //! interrupts.
128 //!
129 //! Status and initialization functions for the \i2c module are:
130 //! - \ref I2CMasterInitExpClk()
131 //! - \ref I2CMasterEnable()
132 //! - \ref I2CMasterDisable()
133 //! - \ref I2CMasterBusBusy()
134 //! - \ref I2CMasterBusy()
135 //! - \ref I2CMasterErr()
136 //! - \ref I2CSlaveInit()
137 //! - \ref I2CSlaveEnable()
138 //! - \ref I2CSlaveDisable()
139 //! - \ref I2CSlaveStatus()
140 //!
141 //! Sending and receiving data from the \i2c module is handled by the following functions:
142 //! - \ref I2CMasterSlaveAddrSet()
143 //! - \ref I2CSlaveAddressSet()
144 //! - \ref I2CMasterControl()
145 //! - \ref I2CMasterDataGet()
146 //! - \ref I2CMasterDataPut()
147 //! - \ref I2CSlaveDataGet()
148 //! - \ref I2CSlaveDataPut()
149 //!
150 //! The \i2c master and slave interrupts are handled by the following functions:
151 //! - \ref I2CIntRegister()
152 //! - \ref I2CIntUnregister()
153 //! - \ref I2CMasterIntEnable()
154 //! - \ref I2CMasterIntDisable()
155 //! - \ref I2CMasterIntClear()
156 //! - \ref I2CMasterIntStatus()
157 //! - \ref I2CSlaveIntEnable()
158 //! - \ref I2CSlaveIntDisable()
159 //! - \ref I2CSlaveIntClear()
160 //! - \ref I2CSlaveIntStatus()
161 //!
162 //! @}
163