Mainly end the problems I encountered in this process
1. No response signal after writing data (instructions or addresses)
The general start timing can be easily written according to the timing diagram in the manual. If there is no response at the first time, it is possible that the data is written to the slave device. Generally, the main thing to check at this time is the rising edge and the falling edge. See if the manual says it is read and written on the rising edge or the falling edge. In my project, the rising edge reads and writes data. In other words, the level indication on the SDA line is read and written at the rising edge; the data is changed at the falling edge. One thing to note is that the SCL line is pulled down first to generate a falling edge. There should be a certain delay after pulling it down in the program, because it takes a certain amount of time for the I/O port to stabilize the level. Otherwise, when SDA is high, if SCL is pulled low by mistake, a start condition will be generated, and the write operation will naturally fail.
2. The data is incorrect when reading data. In
this case, there is data but it is not valid data. Generally, at this time, it is necessary to check whether the simulation timing is correct. It is necessary to clearly read the data at the rising edge, and then pay attention to the data shift. After reading each bit of data, one data bit must be shifted. The following is a code for reading 8 bits of data.
for(i=0;i<8;i++)
{
IIC_SCL_HIGH(); //Conversion completed, SLAVE device pulls the data line low, the clock line generates a rising edge to read the high 8-bit data
REC1=(REC1<<1)+IIC_SDA;
delay_us(5);
IIC_SCL_LOW(); //Pull the clock line low and wait for the next rising edge to arrive
delay_us(5);
}
3. How to write high and low levels in the process of using I/O operations
The input and output I/O ports have directions, so pay attention to the direction of writing. The recommended writing method is to configure the I/O as input when writing high levels, so that the pull-up effect will output a high level to the bus. The advantage of this is that you can wait for the operation of the bus from the device after writing, and there will be no certain conflicts. The following is a high-ground level writing method
#define IIC_SCL_HIGH() IIC_SCL_DIR = PORT_INPUT //Pull the clock line high
#define IIC_SCL_LOW() IIC_SCL_DIR = PORT_OUTPUT; IIC_SCL=0//Pull the clock line low
#define IIC_SDA_HIGH() IIC_SDA_DIR = PORT_INPUT //Pull the data line high
#define IIC_SDA_LOW() IIC_SDA_DIR = PORT_OUTPUT; IIC_SDA=0//Pull the data line low
Previous article:Microcontroller Development Experience Summary
Next article:Simulating bus timing using I/O ports
Recommended ReadingLatest update time:2024-11-16 14:39
- Popular Resources
- Popular amplifiers
- Siemens PLC from Beginner to Mastery with Color Illustrations (Yang Rui)
- Siemens S7-1200-PLC Programming and Application Tutorial (3rd Edition) (Edited by Shi Shouyong)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Compiler Principles C Language Description (Ampel)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- EEWORLD University Hall----Mentor Expedition VX2.3 four-layer Bluetooth product
- EEWORLD University - Key points of analog front-end design for power grid automation equipment and TI solutions
- [Resource Download] STM32CubeExpansion MEMS1 V6.2.0
- Configuration and use of TI C2000 TMS320F28379D SCID SCIB
- MSP430 single chip microcomputer makes intelligent digital multimeter circuit diagram + program
- DSP28335 ECAP module configuration issue
- EEWORLD University Hall----Principles and Applications of Sensors (Tongji University)
- 【Qinheng Trial】CH554 Unboxing
- EEWORLD University ---- Operating System (RISC-V)
- [Zero-knowledge ESP8266 tutorial] Quick Start 7- Make a buzzer