PDA

View Full Version : GPIO library importance in I2C and its functions explanations?



Qlirim
Mar 8th, 2019, 04:32 PM
I've been assigned in a project where I have to communicate mpr121 capacitive touch sensing keyboard with 8051 microcontroller with I2C using Easy8051a board.
I have pretty much learned the theoretical part of I2C communications but struggling with the implementations I've come across a GitHub project where they use GPIO library with some functions very hard to understand.
My question is why do we need GPIO to implement an I2C communication rather doing in the standard way, can we use GPIO with all microcontrollers like the 8051 and I want to know the meaning of the functions below.
If anyone could give me a push on this, I'd be very grateful. Thank you!

Here are the GPIO functions..

void Init_I2C_GPIO(void)
{
GPIO_DIS_OUTPUT(SCL);
PIN_PULLUP_EN(GPIO_PIN_REG(SCL));
GPIO_DIS_OUTPUT(SDA);
PIN_PULLUP_EN(GPIO_PIN_REG(SDA));
}


void SCL_0()
{
GPIO_OUTPUT_SET(SCL, 0);
PIN_PULLUP_DIS(GPIO_PIN_REG(SCL));
}


void SCL_1()
{
GPIO_OUTPUT_SET(SCL, 1);
PIN_PULLUP_EN(GPIO_PIN_REG(SCL));
}


void SDA_0()
{
GPIO_OUTPUT_SET(SDA, 0);
PIN_PULLUP_DIS(GPIO_PIN_REG(SDA));
}


void SDA_1()
{
GPIO_OUTPUT_SET(SDA, 1);
PIN_PULLUP_EN(GPIO_PIN_REG(SDA));
}


unsigned char SDA_R()
{
return GPIO_INPUT_GET(SDA);
//return 0;
}

I have a clue with middle 4 but at 5th SDA_R() and first Init_I2C_GPIO() not quite understandable.

Why not go the standard way like this:

void I2CInit()
{
SDA = 1;
SCL = 1;
}

void I2CStart()
{
SDA = 0;
SCL = 0;
}

void I2CRestart()
{
SDA = 1;
SCL = 1;
SDA = 0;
SCL = 0;
}

void I2CStop()
{
SCL = 0;
SDA = 0;
SCL = 1;
SDA = 1;
}

How can i translate SDA_R() to the standard way shown above?