You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
\section{I2C Unit}
|
|
|
|
The I2C unit provides access to one of the microcontroller's I2C peripherals. It can be configured to use either of the three speeds (Standard, Fast and Fast+) and supports both 10-bit and 7-bit addressing. 10-bit addresses can be used in commands by setting their highest bit (0x8000), as a flag to the unit.
|
|
|
|
\subsection{I2C Configuration}
|
|
|
|
\begin{inicode}
|
|
[I2C:d@4]
|
|
# Peripheral number (I2Cx)
|
|
device=1
|
|
# Pin mappings (SCL,SDA)
|
|
# I2C1: (0) B6,B7 (1) B8,B9
|
|
# I2C2: (0) B10,B11 (1) B13,B14
|
|
remap=0
|
|
|
|
# Speed: 1-Standard, 2-Fast, 3-Fast+
|
|
speed=1
|
|
# Analog noise filter enable (Y,N)
|
|
analog-filter=Y
|
|
# Digital noise filter bandwidth (0-15)
|
|
digital-filter=0
|
|
\end{inicode}
|
|
|
|
\subsection{I2C Commands}
|
|
|
|
\begin{cmdlist}
|
|
|
|
0 & \cname{WRITE}
|
|
Raw write transaction
|
|
& \begin{cmdreq}
|
|
\cfield{u16} slave address
|
|
\cfield{u8[]} bytes to write
|
|
\end{cmdreq} \\
|
|
|
|
1 & \cname{READ}
|
|
Raw read transaction
|
|
& \begin{cmdreq}
|
|
\cfield{u16} slave address
|
|
\cfield{u16} number of read bytes
|
|
\end{cmdreq}
|
|
\cjoin
|
|
\begin{cmdresp}
|
|
\cfield{u8[]} received bytes
|
|
\end{cmdresp} \\
|
|
|
|
2 & \cname{WRITE\_REG}
|
|
Write to a slave register. Sends the register number and the data in the same I2C transaction. Multiple registers can be written to slaves supporting auto-increment.
|
|
& \begin{cmdreq}
|
|
\cfield{u16} slave address
|
|
\cfield{u8} register number
|
|
\cfield{u8[]} bytes to write
|
|
\end{cmdreq} \\
|
|
|
|
3 & \cname{READ\_REG}
|
|
Read from a slave register. Writes the register number and issues a read transaction of the given length. Multiple registers can be read from slaves supporting auto-increment.
|
|
& \begin{cmdreq}
|
|
\cfield{u16} slave address
|
|
\cfield{u8} register number
|
|
\cfield{u16} number of read bytes
|
|
\end{cmdreq}
|
|
\cjoin
|
|
\begin{cmdresp}
|
|
\cfield{u8[]} received bytes
|
|
\end{cmdresp} \\
|
|
|
|
\end{cmdlist}
|
|
|
|
|