GPIO problem

Started by TVC, April 01, 2013, 11:00:37 PM

Previous topic - Next topic

TVC

Dear

I use the IMX233 micro. I am trying to use every GPIO pin on the system board.

First of all, you can find my code below my post. I based my code on the gpio_mmap.h, which you can find on https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/iMX233.
So, I was trying to make LED's blinking. I wanted to attach the LED's on the first 8 pin's of the CON1 (3-10. 1 and 2 are GND and VDD). When I look in the datasheets (IMX23RM.pdf and IMX233Micro.pdf), I found that these CON1-pins are attached to the processor pins 2-9. I found on page 1426 in the datasheet that these pins are on bank1 pin 0-7. I tried it, but it didn't work. What am I doing wrong?

Thanks!


#include "gpio-mmap.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <unistd.h>
#include <sched.h>

//using namespace std;

int main(){
int pin30 = 27;
int pin31 = 28;
int i, j;

gpio_map();
gpio_output(2, pin30);
gpio_output(2, pin31);

gpio_output(1, 0);
gpio_output(1, 1);
gpio_output(1, 2);
gpio_output(1, 3);
gpio_output(1, 4);
gpio_output(1, 5);
gpio_output(1, 6);
gpio_output(1, 7);


for(i=0;i<1000;i++){
GPIO_WRITE(1,1,0);
GPIO_WRITE(1,2,0);
GPIO_WRITE(1,3,0);
GPIO_WRITE(1,4,0);
GPIO_WRITE(1,5,0);
GPIO_WRITE(1,6,0);
GPIO_WRITE(1,7,0);

GPIO_WRITE(2,pin30,0);
GPIO_WRITE(2,pin31,0);
usleep(20000);

GPIO_WRITE(2,pin30,1);
GPIO_WRITE(2,pin31,1);

GPIO_WRITE(1,1,0);
GPIO_WRITE(1,2,1);
GPIO_WRITE(1,3,1);
GPIO_WRITE(1,4,1);
GPIO_WRITE(1,5,1);
GPIO_WRITE(1,6,1);
GPIO_WRITE(1,7,1);

usleep(20000);
}
}

micign

On micro board con1 pins 3-10 map to GPIO numbers 32-39.

Have a look at updated olinuxino micro pinout (i'm not the author, it comes from yahoo mailing list):
https://docs.google.com/spreadsheet/ccc?key=0AiOLYi_8hDyCdGF1cG5xTHRYU2wtUEd4Y0RuQU45OFE&usp=sharing

TVC

I have found a solution to control all gpio for the olimex imx233-micro:

I based my solution on gpio_map.h which you can find here:
https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/iMX233
Secondly I included the IMX233.h header which contains the values of all registers.
You can find this file for example at the bottom of this page:
http://www.ozbotz.org/chumby-pwm-outputs/

First I write my own function to change the register values:

gpio_wr_value(long offset,  long value){
   offset=offset - GPIO_BASE;
   gpio_mmap[offset/4] = value;
}

The offset will be the macro's for the registers listed in imx233.h.

Next I looked in the reference manual for the imx233 (imx233RM.pdf)
http://www.freescale.com/files/dsp/doc/ref_manual/IMX23RM.pdf

Look at page 1431. There you find the registers you have to write for controlling gpio as output.
Here are some examples for LCD0 - LCD4.

The code in gpio_mmap.h only writes in de HW_PINCTRL_DOEx and HW_PINCTRL_DOUTx registers, in stead of my code: first I use the pin multiplexer because every pin has the possibility to do multiple functions.
My code has also 1 difference to the method presented in the reference manual: I clear the HW_PINCTRL_DINx register. When I didn't do this, my program didn't work and I wasn't able to control all gpio-pins.
/***************************************

LCD0

***************************************/
void initLCD0(){
   gpio_wr_eigen(HW_PINCTRL_MUXSEL2_SET, 0b00000000000000000000000000000011);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_SET,  0b00000000000000000000000000000001);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_CLR,  0b00000000000000000000000000000010);
   //gpio_wr_eigen(HW_PINCTRL_PULL2_SET,   0b00000000000001000000000000000000);
   gpio_wr_eigen(HW_PINCTRL_DIN1_CLR,    0b00000000000000000000000000000001);
   gpio_wr_eigen(HW_PINCTRL_DOE1_SET,    0b00000000000000000000000000000001);
}

void setLCD0(){
   gpio_wr_eigen(HW_PINCTRL_DOUT2_SET,   0b00000000000000000000000000000001);
}

void clrLCD0(){
   gpio_wr_eigen(HW_PINCTRL_DOUT2_CLR,   0b00000000000000000000000000000001);
}

/***************************************

LCD1

***************************************/
void initLCD1(){
   gpio_wr_eigen(HW_PINCTRL_MUXSEL2_SET, 0b00000000000000000000000000001100);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_SET,  0b00000000000000000000000000010000);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_CLR,  0b00000000000000000000000000100000);
   //gpio_wr_eigen(HW_PINCTRL_PULL1_SET,   0b00000000000001000000000000000000);
   gpio_wr_eigen(HW_PINCTRL_DIN1_CLR,    0b00000000000000000000000000000010);
   gpio_wr_eigen(HW_PINCTRL_DOE1_SET,    0b00000000000000000000000000000010);
}

void setLCD1(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_SET,   0b00000000000000000000000000000010);
}

void clrLCD1(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_CLR,   0b00000000000000000000000000000010);
}

/***************************************

LCD2

***************************************/
void initLCD2(){
   gpio_wr_eigen(HW_PINCTRL_MUXSEL2_SET, 0b00000000000000000000000000110000);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_SET,  0b00000000000000000000000100000000);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_CLR,  0b00000000000000000000001000000000);
   //gpio_wr_eigen(HW_PINCTRL_PULL1_SET,   0b00000000000001000000000000000000);
   gpio_wr_eigen(HW_PINCTRL_DIN1_CLR,    0b00000000000000000000000000000100);
   gpio_wr_eigen(HW_PINCTRL_DOE1_SET,    0b00000000000000000000000000000100);
}

void setLCD2(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_SET,   0b00000000000000000000000000000100);
}

void clrLCD2(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_CLR,   0b00000000000000000000000000000100);
}

/***************************************

LCD3

***************************************/
void initLCD3(){
   gpio_wr_eigen(HW_PINCTRL_MUXSEL2_SET, 0b00000000000000000000000011000000);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_SET,  0b00000000000000000001000000000000);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_CLR,  0b00000000000000000010000000000000);
   //gpio_wr_eigen(HW_PINCTRL_PULL1_SET,   0b00000000000001000000000000000000);
   gpio_wr_eigen(HW_PINCTRL_DIN1_CLR,    0b00000000000000000000000000001000);
   gpio_wr_eigen(HW_PINCTRL_DOE1_SET,    0b00000000000000000000000000001000);
}

void setLCD3(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_SET,   0b00000000000000000000000000001000);
}

void clrLCD3(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_CLR,   0b00000000000000000000000000001000);
}

/***************************************

LCD4

***************************************/
void initLCD4(){
   gpio_wr_eigen(HW_PINCTRL_MUXSEL2_SET, 0b00000000000000000000001100000000);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_SET,  0b00000000000000010000000000000000);
   gpio_wr_eigen(HW_PINCTRL_DRIVE4_CLR,  0b00000000000000100000000000000000);
   //gpio_wr_eigen(HW_PINCTRL_PULL1_SET,   0b00000000000001000000000000000000);
   gpio_wr_eigen(HW_PINCTRL_DIN1_CLR,    0b00000000000000000000000000010000);
   gpio_wr_eigen(HW_PINCTRL_DOE1_SET,    0b00000000000000000000000000010000);
}

void setLCD4(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_SET,   0b00000000000000000000000000010000);
}

void clrLCD4(){
   gpio_wr_eigen(HW_PINCTRL_DOUT1_CLR,   0b00000000000000000000000000010000);
}