π
<-

Using GPIO22

C, C++, ASM...

Using GPIO22

Unread postby wodz94 » 13 Jan 2019, 00:48

Hello all!

(Scroll down for the answer! :) )

I'm trying to understand the logic behind the mapping of the GPIO sections and bits, so I can do some fancy shizzle with them.
In this post, the master vogtinator wrote a short snippet of code controlling the GPIO4 on pin 6 of the dock connector.

Here's the code:

Code: Select all
*(volatile uint32_t*)(0x90000010) &= ~(1<<4);
while(!any_key_pressed()) {
    *(volatile uint32_t*)(0x90000014) &= ~(1<<4);
    sleep(2000);
    *(volatile uint32_t*)(0x90000014) |= 1<<4;
    sleep(2000);
}


Now that works a dream with me in the c++ app that I'm writing, but as soon as I leave the application, the pin voltage reverts to 2.75v.

That's mildly inconvenient, because I'm looking to have a pin at 0v until I use the app to set it to 3.3v
Through measuring, I realised that on pin 18 of the dock connector, where GPIO22 sits, there isn't a voltage by system-default.
Exactly what I'm looking for.

Now I've been trying to understand how to set GPIO22 to 1 but maybe I've blown one braincell too many over christmas...I just can't figure it out.

Any suggestions would be greatly appreciated.
Warm regards from Switzerland!

____________________________________________________________________________
EDIT:

So after another long day of staring at hex numbers, I've just figured it out.
I'll try and explain it, so even I would understand it... and please correct me if I'm wrong.

So the GPIO registers are split into a few sections (Hackspire):

Section 0: 0x90000000-0x9000003F
Section 1: 0x90000040-0x9000007F
Section 2: 0x90000080-0x900000BF
Section 3: 0x900000C0-0x900000FF
Section 5: 0x90000140-0x9000017F


Each GPIO has a corresponding bit in one of those sections.
Here's the allocation table for all the GPIOs attached to this post.(Hackspire).

Say you want to write to GPIO22 (which happens to be pin 18 on the dock connector), this is what needs doing:

1) Find your GPIO in the table. For me it's Section 2, bit 6.

2) Set your GPIO as an output.
To do this, you find the start of the section. - for me it's 0x90000080
Now the i/o bits are allocated at +0x10 from the start of the section. - for me: 0x90000090
In there we want to set the 6th bit to our desired state (false).

Code: Select all
*(volatile uint32_t*)(0x90000090) &= ~(1<<6);


3) Now let's set the Output to true.
These bits lie at the start address +0x14 - for me: 0x90000094
Here we also want to set the 6th bit.

Code: Select all
*(volatile uint32_t*)(0x90000094) |= 1<<6;



There's probably a sleaker way to implement the code but here's a small method:

Code: Select all
void setGPIO22(bool value){
  *(volatile uint32_t*)(0x90000090) &= ~(1<<6);
  if(value == TRUE){
    *(volatile uint32_t*)(0x90000094) |= 1<<6;
  }

  if(value == FALSE){
    *(volatile uint32_t*)(0x90000094) &= ~(1<<6);
  }
}



Many thanks to all who do the good work and write the documentation allowing ndless to happen so well!

Best,
wodz
You do not have the required permissions to view the files attached to this post.
User avatar
wodz94
Niveau 0: MI (Membre Inactif)
Niveau 0: MI (Membre Inactif)
Level up: 0%
 
Posts: 1
Joined: 13 Jan 2019, 00:33
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Using GPIO22

Unread postby Adriweb » 14 Jan 2019, 05:23

Well, congrats for figuring it out :)

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.7%
 
Posts: 14820
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb


Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: ClaudeBot [spider] and 1 guest

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1019 utilisateurs:
>1005 invités
>7 membres
>7 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)