[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Controlling pins



I wrote two small C-Programms for reading and seting the pins.

When i read the pins i get the value 118, setting this value is no problem. When i set the value 115 the system stands and i must reset.

Why does this happen? 
Can I controll all pins or only specific pins?
What are right arguments to use with ioctl()?

/******************/
/** setting bits **/
/******************/
int main (int argc, char* argv[])
{
  int gpioa; // filedescriptor for /dev/gpioa
  long bits = atol (argv[1]);

  gpioa = open("/dev/gpioa", O_RDWR);

  if (ioctl (gpioa, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), bits) == -1)
  {
    fprintf (stderr, "error setting pins: %s\n", strerror(errno));
    exit (1);
  }
  else
  {
    printf ("set: %d\n", bits);  
  }
  return 0;
}

/******************/
/** reading bits **/
/******************/
int main (int argc, char* argv[])
{
  int gpioa; // filedescriptor for /dev/gpioa
  long bits = -222;
  
  gpioa = open("/dev/gpioa", O_RDWR);
  
  bits = ioctl (gpioa, _IO(ETRAXGPIO_IOCTYPE, IO_READBITS), NULL);
  
  if (bits == -1)
  {
    fprintf (stderr, "error reading pins: %s\n", strerror (errno));
    exit (1);
  }
  else
  {
    printf ("read: %d\n", bits);
  }
  return 0;
}

Thank you.

yours Martin

On Fri, 8 Nov 2002 15:41:37 +0100 
Mikael Starvik <mikael.starvik@xxxxxxx.com> wrote:

> Yes, you can control the value on each pin individually.
> The direction of the pins is changed in groups (e.g. all
> 8 data  pins on parallel port 0 must be in the same
> direction).
> 
> If you want to control the pins from user space you can
> do so by writing to the gpio driver that exists in the
> 2.4.19 kernel (refer to the thread about this a few days
> ago).
> 
> If you want to control them from a driver you will find 
> hints in the device driver example on www.axis.com.
> 
> /Mikael
> 
> -----Original Message-----
> From: owner-dev-etrax@xxxxxxx.com]On">mailto:owner-dev-etrax@xxxxxxx.com]On
> Behalf Of Martin Oberhammer
> Sent: Friday, November 08, 2002 3:20 PM
> To: dev-etrax
> Subject: Controlling pins
> 
> 
> There exists 2 parallel ports on the developer board (ETRAX 100LX). Is it possible to controll each of the 52 pins serparately? For example sending a signal over pin 8, 10, 20 and 48. 
> 
> yours Martin
> 
> ----------------------------
> Martin Oberhammer
> ARS Electronica Futurelab
> Hauptstrasse 2-4
> 4040 Linz
> AUSTRIA


----------------------------
Martin Oberhammer
ARS Electronica Futurelab
Hauptstrasse 2-4
4040 Linz
AUSTRIA

Web: http://www.aec.at