GPIO library importance in I2C and its functions explanations?Msp430 i²c module and librariesConfiguring STM32 output ports for I2CTaking output from an Adafruit I2C 16 channel driverHow to initialize I2C on STM32F0?Not getting correct values in I2C interfacing in AtmegaI2C-dev: Change write and read parametersAnyone ever split I2C across two microcontrollers?BT HC-06 not receiving data from 8051How To Measure I2C Setup Time?Capacitance measurement, mpr121

In a Spin are Both Wings Stalled?

Anagram holiday

Do I have a twin with permutated remainders?

How can I fix/modify my tub/shower combo so the water comes out of the showerhead?

What is going on with Captain Marvel's blood colour?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

Did Shadowfax go to Valinor?

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

How to take photos in burst mode, without vibration?

Why can't we play rap on piano?

Watching something be written to a file live with tail

Infinite Abelian subgroup of infinite non Abelian group example

SSH "lag" in LAN on some machines, mixed distros

How to draw the figure with four pentagons?

Brothers & sisters

Combinations of multiple lists

Can I ask the recruiters in my resume to put the reason why I am rejected?

What does it mean to describe someone as a butt steak?

How to prevent "they're falling in love" trope

What exploit are these user agents trying to use?

Is it possible to run Internet Explorer on OS X El Capitan?

Were any external disk drives stacked vertically?

I'm flying to France today and my passport expires in less than 2 months

Why do I get two different answers for this counting problem?



GPIO library importance in I2C and its functions explanations?


Msp430 i²c module and librariesConfiguring STM32 output ports for I2CTaking output from an Adafruit I2C 16 channel driverHow to initialize I2C on STM32F0?Not getting correct values in I2C interfacing in AtmegaI2C-dev: Change write and read parametersAnyone ever split I2C across two microcontrollers?BT HC-06 not receiving data from 8051How To Measure I2C Setup Time?Capacitance measurement, mpr121






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















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);



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?










share|improve this question






















  • what do you mean by "the standard way"?

    – old_timer
    Mar 9 at 4:09











  • Your "standard way" implies a pointer of some sort. That "standard way" is a bit risky in general, but assuming it works for you and that version of that compiler, then go for it. Using abstraction allows for much more flexibility and you can turn an abstraction like that into a volatile pointer scheme using macros but cant turn volatile pointer schemes into abstraction layers.

    – old_timer
    Mar 9 at 4:17











  • to bit bang i2c or other bi-directional data busses you will need to either open drain or switch the gpio to be push-pull or input/tristate at the right times so the slave can control the data line. that can be done with a volatile pointer scheme (assuming you have that working correctly with this version of this compiler) or abstraction layer solutions. so your "standard way" needs code to do the writes and reads and depending on how you implement that might need more code in the functions you have created to control the direction.

    – old_timer
    Mar 9 at 4:20











  • Using abstraction layer functions will benefit you in the long run. But there are platforms that are so resource/performance starved and/or have instruction set features where you really want to gamble on the volatile pointer thing. But if/when you get into working against simulations or writing code that the one module/function/library can be used both in baremetal and a kernel driver and an application wont work so well with the volatile pointer solution but is trivial with the abstraction layer/function approach.

    – old_timer
    Mar 9 at 4:25

















-1















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);



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?










share|improve this question






















  • what do you mean by "the standard way"?

    – old_timer
    Mar 9 at 4:09











  • Your "standard way" implies a pointer of some sort. That "standard way" is a bit risky in general, but assuming it works for you and that version of that compiler, then go for it. Using abstraction allows for much more flexibility and you can turn an abstraction like that into a volatile pointer scheme using macros but cant turn volatile pointer schemes into abstraction layers.

    – old_timer
    Mar 9 at 4:17











  • to bit bang i2c or other bi-directional data busses you will need to either open drain or switch the gpio to be push-pull or input/tristate at the right times so the slave can control the data line. that can be done with a volatile pointer scheme (assuming you have that working correctly with this version of this compiler) or abstraction layer solutions. so your "standard way" needs code to do the writes and reads and depending on how you implement that might need more code in the functions you have created to control the direction.

    – old_timer
    Mar 9 at 4:20











  • Using abstraction layer functions will benefit you in the long run. But there are platforms that are so resource/performance starved and/or have instruction set features where you really want to gamble on the volatile pointer thing. But if/when you get into working against simulations or writing code that the one module/function/library can be used both in baremetal and a kernel driver and an application wont work so well with the volatile pointer solution but is trivial with the abstraction layer/function approach.

    – old_timer
    Mar 9 at 4:25













-1












-1








-1








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);



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?










share|improve this question














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);



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?







microcontroller i2c 8051






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 23:41









Çlirim MuratiÇlirim Murati

197




197












  • what do you mean by "the standard way"?

    – old_timer
    Mar 9 at 4:09











  • Your "standard way" implies a pointer of some sort. That "standard way" is a bit risky in general, but assuming it works for you and that version of that compiler, then go for it. Using abstraction allows for much more flexibility and you can turn an abstraction like that into a volatile pointer scheme using macros but cant turn volatile pointer schemes into abstraction layers.

    – old_timer
    Mar 9 at 4:17











  • to bit bang i2c or other bi-directional data busses you will need to either open drain or switch the gpio to be push-pull or input/tristate at the right times so the slave can control the data line. that can be done with a volatile pointer scheme (assuming you have that working correctly with this version of this compiler) or abstraction layer solutions. so your "standard way" needs code to do the writes and reads and depending on how you implement that might need more code in the functions you have created to control the direction.

    – old_timer
    Mar 9 at 4:20











  • Using abstraction layer functions will benefit you in the long run. But there are platforms that are so resource/performance starved and/or have instruction set features where you really want to gamble on the volatile pointer thing. But if/when you get into working against simulations or writing code that the one module/function/library can be used both in baremetal and a kernel driver and an application wont work so well with the volatile pointer solution but is trivial with the abstraction layer/function approach.

    – old_timer
    Mar 9 at 4:25

















  • what do you mean by "the standard way"?

    – old_timer
    Mar 9 at 4:09











  • Your "standard way" implies a pointer of some sort. That "standard way" is a bit risky in general, but assuming it works for you and that version of that compiler, then go for it. Using abstraction allows for much more flexibility and you can turn an abstraction like that into a volatile pointer scheme using macros but cant turn volatile pointer schemes into abstraction layers.

    – old_timer
    Mar 9 at 4:17











  • to bit bang i2c or other bi-directional data busses you will need to either open drain or switch the gpio to be push-pull or input/tristate at the right times so the slave can control the data line. that can be done with a volatile pointer scheme (assuming you have that working correctly with this version of this compiler) or abstraction layer solutions. so your "standard way" needs code to do the writes and reads and depending on how you implement that might need more code in the functions you have created to control the direction.

    – old_timer
    Mar 9 at 4:20











  • Using abstraction layer functions will benefit you in the long run. But there are platforms that are so resource/performance starved and/or have instruction set features where you really want to gamble on the volatile pointer thing. But if/when you get into working against simulations or writing code that the one module/function/library can be used both in baremetal and a kernel driver and an application wont work so well with the volatile pointer solution but is trivial with the abstraction layer/function approach.

    – old_timer
    Mar 9 at 4:25
















what do you mean by "the standard way"?

– old_timer
Mar 9 at 4:09





what do you mean by "the standard way"?

– old_timer
Mar 9 at 4:09













Your "standard way" implies a pointer of some sort. That "standard way" is a bit risky in general, but assuming it works for you and that version of that compiler, then go for it. Using abstraction allows for much more flexibility and you can turn an abstraction like that into a volatile pointer scheme using macros but cant turn volatile pointer schemes into abstraction layers.

– old_timer
Mar 9 at 4:17





Your "standard way" implies a pointer of some sort. That "standard way" is a bit risky in general, but assuming it works for you and that version of that compiler, then go for it. Using abstraction allows for much more flexibility and you can turn an abstraction like that into a volatile pointer scheme using macros but cant turn volatile pointer schemes into abstraction layers.

– old_timer
Mar 9 at 4:17













to bit bang i2c or other bi-directional data busses you will need to either open drain or switch the gpio to be push-pull or input/tristate at the right times so the slave can control the data line. that can be done with a volatile pointer scheme (assuming you have that working correctly with this version of this compiler) or abstraction layer solutions. so your "standard way" needs code to do the writes and reads and depending on how you implement that might need more code in the functions you have created to control the direction.

– old_timer
Mar 9 at 4:20





to bit bang i2c or other bi-directional data busses you will need to either open drain or switch the gpio to be push-pull or input/tristate at the right times so the slave can control the data line. that can be done with a volatile pointer scheme (assuming you have that working correctly with this version of this compiler) or abstraction layer solutions. so your "standard way" needs code to do the writes and reads and depending on how you implement that might need more code in the functions you have created to control the direction.

– old_timer
Mar 9 at 4:20













Using abstraction layer functions will benefit you in the long run. But there are platforms that are so resource/performance starved and/or have instruction set features where you really want to gamble on the volatile pointer thing. But if/when you get into working against simulations or writing code that the one module/function/library can be used both in baremetal and a kernel driver and an application wont work so well with the volatile pointer solution but is trivial with the abstraction layer/function approach.

– old_timer
Mar 9 at 4:25





Using abstraction layer functions will benefit you in the long run. But there are platforms that are so resource/performance starved and/or have instruction set features where you really want to gamble on the volatile pointer thing. But if/when you get into working against simulations or writing code that the one module/function/library can be used both in baremetal and a kernel driver and an application wont work so well with the volatile pointer solution but is trivial with the abstraction layer/function approach.

– old_timer
Mar 9 at 4:25












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072503%2fgpio-library-importance-in-i2c-and-its-functions-explanations%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072503%2fgpio-library-importance-in-i2c-and-its-functions-explanations%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived