Regarding similar problems, you can make a board and try it yourself. I believe it should not be difficult to simulate I2C communication with IO ports. The implementation method is to connect a pull-up resistor to the port, set the output register to zero, and then change the direction register to realize the conversion between 0 and 1. If it is set to output, it is 0, and if it is set to 1, the port will be pulled high under the action of the pull-up resistor. The other IO ports of the port are used for control. When doing I2C communication, it is found that when the I2C bus outputs 0, the result output is always high. Observe with an oscilloscope and finally find that the problem is that after the output register is set to 0, when writing other IO ports of the port, the entire port value will come, and then modify the written bit, and write the entire port again. Because the IO port of I2C has a pull-up resistor, the value read back each time is 1. When writing the entire port, the value of the output register is rewritten to 1, resulting in the problem that the output cannot be zero. The solution is to set the shadow register of the port. Every time you want to modify the value of any IO port of the port, you first modify the corresponding bit of the shadow register, and then use the value of the shadow register to write the entire port, and the problem is solved. By solving this problem, I have a deeper understanding of the read-modify-write function of the port.
Let's systematically introduce what read-modify-write is, the problems it causes and their solutions:
As long as the final value of the FILE (register, memory, and I/O) processed by the PICmicro command is related to the value before the command is processed, then this command is a so-called read-modify-write command. Because the operation of this type of command can be further divided into three small steps, namely read (READ), modify (MODIFY), and then write (WRITE).
Such as: ADDWF, DECF, IORWF, XORWF, BSF, BCF, etc.
When using this type of command, if the FILE being processed is I/O, you must be especially careful. Because, assuming the task voltage is 5V; and you have connected 8 diodes (perhaps LEDs) to the ground instead of resistors in series on the 8 pins of PORTB. If you previously issued the command "BSF PORTB,0", the LED on the 0th pin of PORTB is on. When you run the command "BSF PORTB,1", although the LED on the 1st pin of PORTB is on, the LED on the 0th pin of PORTB will be off. The reason is that when running "BSF PORTB,1", the entire PORTB value will be read back first, and the 0th pin of PORTB it reads is equivalent to a low potential (pulled to 0.7V by a diode). When it writes the entire PORTB value out again, the 0th pin of PORTB is written as a low potential, and the light is naturally off.
The solution is to add resistors in series or not to directly perform read-modify-write commands on the I/O.
There is another situation that needs attention: when you connect the two commands "BSF PORTB,0" and "BSF PORTB,1" together without idle running, even if you do not have the bad circuit design mentioned in the previous paragraph, sometimes you will find that the high potential of PORTB,0 will disappear. The reason for this phenomenon is: because you may have long wires connected to the outside of these two pins, there are considerable capacitance and inductance that will prevent the change of potential; and, the PIC command operation is "written out" in the last 1/4 cycle and "read in" in the first 1/4 cycle, PORTB,0 has not had time to rise to a high potential and is read back by the next command.
The solution is: usually just insert a NOP command between two commands.
Previous article:PIC microcontroller software development method
Next article:PIC16F877A serial port sending string problem
Recommended ReadingLatest update time:2024-11-16 11:43
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
- Feasibility of using QSPI + PSRAM to expand RAM for STM32
- Tailing Micro B91 Development Kit---MESH
- [NXP Rapid IoT Review] Week 2: Get familiar with the online GUI Rapid IoT Studio
- IoT-related applications of SensorTile.box
- How to solve the problem of glitch in ADC08D500 high output?
- National College Student Electronic Design Competition Quadcopter UAV Data Album
- A picture shows the layout of Qorvo and domestic replacement-penetration in various fields
- It is suggested to add a bonus to the post asking for advice, so that the questions raised will receive more positive and higher quality responses.
- [National Technology Low Power Series N32L43x Review] 08. Software and Hardware I2C Driver 1.5-inch 16-color grayscale OLED display
- Free application: Support Linux RISC-V development board, Sipeed LicheeRV 86