how to read from AIN0 pin

wanna
hye all.

im new in using mini2440 and linux. is there any example or any tutorial
that can teach me how to read signal from AIN0 pin?

let say, i want to connect sine wave to that pin and i want to read it and
appear its Vpeak. is it possible?

thanx!

wanna
hello experts.

i have problem in running my program to read from AIN0. below is my program
that i compile using fedora.


#include <stdio.h>

int main()
 {
    int value, i, fd = open ("cat /dev/adc", 0);
    unsigned int add = 0, ret;
    int LOOPS=-1;
    if (fd <0) {
        printf ("cannot open n device adc!\n");
        return -1;
    }

    for (i = 0; i <LOOPS; i ++)
    {
        char buffer [30];
        int len = read (fd, buffer, sizeof(buffer) -1);
        if (len>0)
        {
            buffer [len] = '0';
            value = -1;
            sscanf (buffer, "%d", &value);
            printf (buffer, "%d", &value);
        }    
        else
        {
            printf ("cannot read from adc device n!");
            close (fd);
            return -1;
        }
    }
    close (fd);
    return 0;
}

with using fedora, there's nothing wrong with this program. however when i
run the obj file using mini2440, an error occur. the error state :

line 1: syntax error: "(" unexpected.

please do help me! 
thnax

Dave Festing
int LOOPS=-1;

Shouldn't that be int loops = 1;

Also values like LOOPS are perhaps better done like:

#define LOOPS 1

and put it before main() for visibility and ease of changing.

Capitalising is usually done for macros, like the above.

Dave Festing
Line 1:

Another suggestion some compilers seem to prefer:
<int main (void)>

wanna
thanx Dave. i already change both. and there are 4 errors appear such as :

line 3: 4: not found
line 3: EL-:not found
line 4: syntax error: E0F in backquote

and another one error is unreadable.

is there any other ways for me to read a signal from AIN in a simple
program? cause i had tried "cat /dev/adc" but the number appears are
non-stop. 

sorry for lots of question. but i need it for my project.
thanx.

wanna
hello again.

i forgot to tell you that before this i tried to run an examples given
about the adc-test. but there are 2 error appear as below :

./adc-test: line 1:ELF4: not found
./adc-test: line 2: syntax error: "(" unexpected

this is the source code from example in mini2440 dvd:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>

int main(void)
{
  fprintf(stderr, "press Ctrl-C to stop\n");
  int fd = open("/dev/adc", 0);
  if (fd < 0) {
    perror("open ADC device:");
    return 1;
  }
  for(;;) {
    char buffer[30];
    int len = read(fd, buffer, sizeof buffer -1);
    if (len > 0) {
      buffer[len] = '\0';
      int value = -1;
      sscanf(buffer, "%d", &value);
      printf("ADC Value: %d\n", value);
    } else {
      perror("read ADC device:");
      return 1;
    }
    usleep(500* 1000);
  }
  
  close(fd);
}

is that my mini2440 had problem??or i should install something on it?

davef
About 1 year ago I modified, compiled and ran that same program ... so it
is possible.

I suspect there is a problem in the way your toolchain is set up.

Have you EXPORTed your PATH and the standard compile environment variables,
for example:

export PATH=/usr/local/arm/4.3.2/bin:$PATH

# general cross-compile
export CROSS_COMPILE=arm-none-linux-gnueabi-
export CC=${CROSS_COMPILE}gcc
export CFLAGS=-march=armv4t
# -mtune=arm920t not a valid identifier
# -O0 -msoft-float -D__GCC_FLOAT_NOT_NEEDED
export CXX=${CROSS_COMPILE}"g++" 
export AR=${CROSS_COMPILE}"ar" 
export AS=${CROSS_COMPILE}"as" 
export RANLIB=${CROSS_COMPILE}"ranlib" 
export LD=${CROSS_COMPILE}"ld"
export STRIP=${CROSS_COMPILE}"strip"

Good luck.

wanna
hi davef. thanx for answer me.

i have few question. 
where should i EXPORTed your PATH and the standard compile environment
variables? is it in fedora where i compile my source code before i run the
object file in mini2440?

sorry for asking so many question.

davef
You cross-compile your source on the fedora host.

Have you installed a cross-compile toolchain on the host?  Find gcc 4.4.1
on the downloads page.

I would suggest you read through the tutorials at this site:
http://billforums.station51.net/

and then get back with specific questions.

wanna
thanx davef!

i do have installed a cross-compiler. but when i compile the program, i
compile it using another pc. and i forgot that im not installed the
cross-compiler on that pc. im waste my time wondering why. however, its all
settle. and i succeed to run in on mini2440. thanx davef for answering my
stupid mistake!  

thanx again! :)

davef
Now, you can start some serious programming!

Good luck

wanna
thanx again davef! :D