1.I2C master and slave device relationship
For write operations, the master acts as a transmitter and the slave device acts as a receiver.
For read operations, the master acts as a receiver and the slave device acts as a transmitter.
2.I2C controller
2.1 Overall Block Diagram
Pclk = 50Mhz, after being divided by the prescaler, SCL can be obtained.
IICSTAT: Sends S (start) signal or P (stop) signal.
Data Bus can write data into the IICDS register, then automatically generate SCL, and synchronize the 8-bit data from SDA to the slave dev.
After the data is sent out, it will receive an ack response from the slave dev at the 9th SCL clock. You can determine whether there is an ACK response by querying IICSTAT.
When the slave dev responds with ACK, it can continue to send data and continue to write data to IICDS.
When the master wants to end, it sets IICSTAT to send a P signal.
2.2 Register Introduction
1.IICCON (used to configure the i2c clock)
Bit[7]: For the sending mode, there is no need to configure the ack signal, which is the response sent back by the receiver. For the receiving mode, set it to 1 to send an ack signal at the 9th CLK (pulling sda low).
Bit[6]: SCL clock source, pclk frequency division is sufficient
Bit[5]: interrupt enable, must be enabled when using i2c
Bit[4]: Interrupt status flag indicates whether the interrupt has ended. When this bit is read as 1, SCL is pulled low to indicate busy, that is, the i2c interrupt is still being processed. When the i2c interrupt is processed, this bit can be cleared to 0 to release SCL.
Bit[3:0]: i2c clock division coefficient configuration, SCL clock = IICCLK/(IICCON[3:0]+1)
2.IICSTAT (configuration mode, S, P signal, check whether there is ack)
bit[7:6]: mode selection
Bit[5]: When reading, 0 means not busy, 1 means busy
When writing, 0 means writing STOP, 1 means writing START
Bit[4]: Data output enable, 0: disable, 1: enable
Bit[3]: arbitration flag
Bit[0]: Indicates whether there is an ack in the 9th clock cycle on the i2c bus. 1 indicates an ack, and 0 indicates no ack
3.IICADD (Configure slave address)
4.IICDS: (stores data to be sent or received)
3. Read and write operation process
The following steps must be executed before any IIC Tx/Rx operations.
1. Write own slave address on IICADD register, if needed.
2. Set IICCON register.
a) Enable interrupt
b) Define SCL period
3. Set IICSTAT to enable Serial Output
Before operating tx and rx, you must first perform the following steps:
1.IICADD writes the slave device address
2. Set IICCON, set clock, enable interrupt
3. Set IICSTAT to enable transmission
Operation Mode:
The S3C2440A IIC-bus interface has four operation modes:
— Master transmitter mode
— Master receive mode
— Slave transmitter mode
— Slave receive mode
①Master/Transmitter Mode
-
Configured to master tx mode (that is, IICSTAT[7:6] is configured to 11)
-
Write the slave device address into IICDS (the first transmission address)
-
IICSTAT writes 0xF0 (enables transmission, sends S signal, enables tx/rx)
-
The data configured in IICDS (slave device address 7bit + read/write bit 1bit) is sent out (an interrupt will be generated after each data is transmitted)
-
Determine whether the 9th clk slave device has ack
-
If the slave device has ack, resume i2c transmission
-
IICDS = buf
-
Clear pending bit
-
The data is sent out and the i2c transmission continues
-
If there is no ack, stop and return an error
-
IICSTAT = 0xd0
-
Clear pending bit(IICCON[4])
-
Delay for a while to wait for the stop condition to take effect
②Master/Receiver Mode
-
Configured to master rx mode (that is, IICSTAT[7:6] is configured to 10)
-
Write the slave device address into IICDS (the first transmission address)
-
IICSTAT writes 0xB0 (enables transmission)
-
The data configured in IICDS (slave device address 7bit + read/write bit 1bit) is sent out (an interrupt will be generated after each data is transmitted)
-
Determine whether the 9th clk slave device has ack
-
If the slave device has ack, resume i2c transmission
-
Buf = IICDS
-
Clear pending bit
-
The data is received and the i2c transmission continues
-
If there is no ack, stop and return an error
-
IICSTAT = 0x90
-
Clear pending bit
-
Delay for a while
③Slave/Transmitter Mode
④Slave/Receiver Mode
Previous article:s3c2440 bare metal - i2c programming - 3 - i2c program framework
Next article:s3c2440 bare metal - i2c programming - 1 - i2c protocol
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Precision control techniques and methods for PCB board milling
- MSP430FR6989IPZR Mixed-Signal Microprocessor MCU
- Can anyone help me see how to write the transfer function of the following type of op amp circuit?
- fault mask switching cycles?
- EEWORLD大学堂----Modern Robotics: Mechanics, Planning, and Control
- What makes supercapacitors “super”?
- Please help me, God!
- How to understand the pre-scaling of one stm32 timer as another timer
- [GigaDevice GD32F310 Review] +OLED screen display driver
- Today is the second day of the college entrance examination. Let’s talk about those who accompany the students to take the exam and the good wishes for the college entrance examination.