When I first started debugging the connection between the TWI bus and AT24C02, I took a few days of detours because it was my first time to implement I2C in hardware. Today, I have completely debugged it. I will write down some debugging experience to save others from taking the same detours in the future.
It can be said that it is very convenient to debug I2C using Proteus. For example, after connecting MEGA8 and AT24C02 on the drawing, if you want to see the I2C debugging status, you can use two methods:
The first method is to connect an I2C Debugger instrument to the I2C bus. During the simulation debugging period, the instrument can display the I2C data transmission time, S (START state), Sr (ReStart state), A (Ask response), N (No ask state), P (Stop state), data (displaying the hexadecimal value of the data and the value of each bit at the same time). By checking the display of the I2C Debugger window, you can know whether the data sent and received on the I2C bus is correct.
The second method is to use the Log function in the property settings of the 24C series I2C EEPROM components. These Log functions are No by default, that is, not used. We can set it to Yes. One point in particular: the last item of these Log functions is Log to main Simulation Log, that is, whether to write the recorded situation to the main window simulation Log file. If you want to see the Log situation, this option must be selected Yes, otherwise you will not see the historical records. If the 24C series components receive or send flag information and data information, these information records can be seen in the Log file of the main window. The specific way to view it is to click Text Viewer in the System menu.
Let's talk about some debugging features of 24c series components in Proteus.
Once the data is correctly written to a certain address of the 24c series component placed in the schematic, the data will remain regardless of whether the debugging is stopped or the data file is reloaded or the schematic is reloaded. It's amazing, right? I found this problem in Proteus 6.9sp4, and this situation is completely different from what we imagined.
In addition, the reading and writing of 24c02 components must be performed in the following manner:
Read. AVR must send the START bit first, and then check whether the bus is under control. In many cases, TWI_STATUS returns TW_START, TW_REP_START, or can continue to transmit. Next, send [address|TW_WRITE], then check TWI_STATUS. If correct, it should return TW_MT_SLA_ACK, and then you can send the address byte. If the transmission is successful, TWI_STATUS returns TW_MT_DATA_ACK, and then you can continue to send the START bit, [address|TW_READ], and then AVR automatically switches to the host read state. After waiting for a while, if something is read, you can detect TW_MR_DATA_ACK or TW_MR_DATA_NACK in TWI_STATUS, and the data obtained in TWDR is the read data.
It is worth noting that in Proteus simulation, the response is very slow, and often TWI_STATUS will get TW_NO_INFO (no information). This happens because after the AVR receives the response signal, it takes a while for the value in TWI_STATUS to be updated. In order to read the correct data, you can wait for dozens of microseconds after TWINT is set, and then you can get the correct TWI_STATUS value.
The reason is that when data is sent or received, TWINT is set, but it takes some time to receive ACK/NACK, so it takes some time to receive the correct TWI_STATUS value. I have been struggling with this problem for a long time, and it is different from what I imagined, and the MEGA8 manual does not mention this. Finally, after a long time of struggling, I suddenly got an idea and figured it out.
I wrote this article to share with you.
Previous article:Atmega16L analog/digital converter - AVR microcontroller introduction
Next article:Design and implementation of solar energy water heater controller
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Technical books and materials related to lighting LED power supply design
- AT90S2323-2343 Chinese Data Sheet
- Cutoff frequency calculation
- HyperLynx High-Speed Circuit Design and Simulation (V) Transmission Line Crosstalk after Termination
- Suspicious signal from outer space
- 51 MCU header file added
- Download gift: USB Type C related development and test materials, read it when you have nothing to do, and you will become a master by accident
- Show your face, be careful not to scare people.
- Qorvo explains WIFI and 5G clearly
- NUCLEO-G431RB Review Using the Library to Do FFT