π
<-
Chat plein-écran
[^]

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
Attachments
Screenshot 2019-01-13 at 21.15.11.png
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):

Re: Using GPIO22

Unread postby Adriweb » 14 Jan 2019, 05:23

Well, congrats for figuring it out :)
User avatar
AdriwebAdmin.
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 50.8%
 
Posts: 12449
Images: 1080
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
Class: (ingénieur)
Twitter: adriweb
GitHub: adriweb


Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: No registered users and 4 guests

-
Search
-
Featured topics
Offre TI-Planet/Jarrety pour avoir la TI-83 Premium CE avec son chargeur pour 79,79€ port inclus !
Offre TI-Planet/Jarrety pour avoir la TI-Nspire CX CAS à seulement 130€ TTC port inclus!
Jailbreake ta TI-Nspire avec Ndless et profite des meilleurs jeux et applications !
123
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...

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 
-
Stats.
359 utilisateurs:
>332 invités
>21 membres
>6 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)