Some Problems Encountered in Using I/O Ports to Simulate IIC Bus Protocol

Publisher:等风来88888Latest update time:2016-09-28 Source: eefocusKeywords:I Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
A recent project is a sensor system based on IIC bus communication. Since another sensor uses a similar IIC protocol instead of standard IIC, the MCU cannot communicate with it. In the end, there is no other way but to implement IIC bus communication through I/O port simulation. The specific program has been posted in my blog earlier. If you are interested, you can check my blog.

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

Keywords:I Reference address:Some Problems Encountered in Using I/O Ports to Simulate IIC Bus Protocol

Previous article:Microcontroller Development Experience Summary
Next article:Simulating bus timing using I/O ports

Recommended ReadingLatest update time:2024-11-16 14:39

1.10.5_I2C_I2C controller programming_interrupt_P
The interrupt program is the core of the I2C controller, and the ACK confirmation is completed in the interrupt program. The interrupt processing flow is completed through the relevant flow chart of 2440 and the data structure of AT24cxx. The following figure is the flow chart of 2440 IIC controller in Transmitter
[Microcontroller]
1.10.5_I2C_I2C controller programming_interrupt_P
The difference between i++ and ++i in C language
In actual programming, in order to make the program concise, statements such as i++ and ++i are often used. Here is a brief explanation of their difference: i++: perform calculations first, and then execute the operation of i = i +1; while ++i first executes the operation of i = i +1, and then performs cal
[Microcontroller]
Traffic Solution | Building a smart public transportation system based on the Flink A40i core board
Waiting for the bus is an annoying thing. This process will constantly challenge our patience. Maybe your hard work will only result in the bus passing by you, or maybe your patient waiting will only result in the bus being late. Even if you wait for the bus, you still have to take the risk of not being able to get
[Embedded]
Traffic Solution | Building a smart public transportation system based on the Flink A40i core board
LPC_11C14 platform I2C analysis
1) Initialization of IIC: reset IIC, enable IIC clock unit, set corresponding I0 port to IIC function, clear acknowledge bit, start bit, interrupt bit, IIC enable bit, set IIC transmission rate, if it is a slave, set slave address, enable IIC interrupt, and finally start IIC. 2) Start of IIC uint32_t I2CStart( voi
[Microcontroller]
A big competition of 77GHz millimeter-wave radar chip solutions, which one is the most attractive?
According to Yole's recently released report "Automotive Radar Technology - 2018 Edition", although the annual sales volume of global automobiles will grow slowly from 2017 to 2022 (about 3%), the annual sales volume of automotive radar modules is expected to grow rapidly (about 25%), and the annual sales volume of ra
[Automotive Electronics]
A big competition of 77GHz millimeter-wave radar chip solutions, which one is the most attractive?
Avnet launches MaaXBoard based on NXP i.MX 8M for edge development
Avnet's MaaXBoard single-board computer is ideal for industrial automation, IoT, AI and multimedia applications. Avnet has launched a low-cost, production-ready MaaXBoard to provide customers with single-board computers that focus more on the software side of development. Based on the NXP i.MX 8M application processo
[Embedded]
LPC824-I2C interface (continued 2)
Continue to look at the I2C interrupt enable setting and reading register INTENSET. The following table shows its entire bit structure. Its addresses are 0x40050008 (I2C0), 0x40054008 (I2C1), 0x40070008 (I2C2) and 0x40074008 (I2C3)). (1) Bit 0 (MSTPENDINGEN) is the host pending interrupt enable bit. When writing 0
[Microcontroller]
LPC824-I2C interface (continued 2)
Comparison of PDM and I²S interfaces in MEMS microphones
麦克风用在嵌入式系统中已经有很多年了。然而,自其诞生以来,由于家居、汽车和可穿戴设备中基于语音的应用范围不断扩大,MEMS 麦克风的市场使用率迅速增加。MEMS 麦克风不仅具有显著减少电路板空间、低功率要求和提高抗电噪声能力的优点,而且还具有更高的设计灵活性,有多种输出选择。模拟输出 MEMS 麦克风仍然是工程师们的一个选择,以及像脉冲密度调制 (PDM) 和集成电路内置音频 (I²S) 这样的数字输出亦是如此。 This article will discuss these two digital interfaces in detail, introduce their unique characte
[Embedded]
Comparison of PDM and I²S interfaces in MEMS microphones
Recommended Content
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号