I2C Slave Mode - STMicroelectronics STM32F05 series Reference Manual

Advanced arm-based 32-bit mcus
Table of Contents

Advertisement

RM0091
Caution:
The AUTOEND bit has no effect when the RELOAD bit is set.
Table 65.
Master Tx/Rx NBYTES + STOP
Master Tx/Rx + NBYTES + RESTART
all received bytes ACKed
Slave Rx with ACK control
2
23.4.8
I
C slave mode
I2C slave initialization
In order to work in slave mode, you must enable at least one slave address. Two registers
I2Cx_OAR1 and I2Cx_OAR2 are available in order to program the slave own addresses
OA1 and OA2.
OA1 can be configured either in 7-bit mode (by default) or in 10-bit addressing mode by
setting the OA1MODE bit in the I2Cx_OAR1 register.
OA1 is enabled by setting the OA1EN bit in the I2Cx_OAR1 register.
If additional slave addresses are required, you can configure the 2nd slave address
OA2. Up to 7 OA2 LSB can be masked by configuring the OA2MSK[2:0] bits in the
I2Cx_OAR2 register. Therefore for OA2MSK configured from 1 to 6, only OA2[7:2],
OA2[7:3], OA2[7:4], OA2[7:5], OA2[7:6] or OA2[7] are compared with the received
address. As soon as OA2MSK is not equal to 0, the address comparator for OA2
excludes the I2C reserved addresses (0000 XXX and 1111 XXX), which are not
acknowledged. If OA2MSK=7, all received 7-bit addresses are acknowledged (except
reserved addresses). OA2 is always a 7-bit address.
These reserved addresses can be acknowledged if they are enabled by the specific
enable bit, if they are programmed in the I2Cx_OAR1 or I2Cx_OAR2 register with
OA2MSK=0.
OA2 is enabled by setting the OA2EN bit in the I2Cx_OAR2 register.
The General Call address is enabled by setting the GCEN bit in the I2Cx_CR1 register.
When the I2C is selected by one of its enabled addresses, the ADDR interrupt status flag is
set, and an interrupt is generated if the ADDRIE bit is set.
By default, the slave uses its clock stretching capability, which means that it stretches the
SCL signal at low level when needed, in order to perform software actions. If the master
does not support clock stretching, the I2C must be configured with NOSTRETCH=1 in the
I2Cx_CR1 register.
After receiving an ADDR interrupt, if several addresses are enabled you must read the
ADDCODE[6:0] bits in the I2Cx_ISR register in order to check which address matched. DIR
flag must also be checked in order to know the transfer direction.
I2C Configuration table
Function
Slave Tx/Rx
Doc ID 018940 Rev 1
Inter-integrated circuit (I
SBC bit
RELOAD bit
x
0
x
0
0
x
1
1
2
C) interface
AUTOEND bit
1
0
x
x
479/742

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM32F05 series and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents