Hello,
I am trying to set the external ADC MAX197. Right now i am just
configuring only one channel.But i haven't been able to get any
output.Infact it seems like the 0x10f00000 is not getting intialized.
the code i am using is:
#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include<assert.h>
#include<time.h>
#include<stdlib.h>
#define Result 0x10f00000
#define Busy 0x10800000
#define Extern_ADC 0x22400000
#define Channel_0 0x51
int main(int argc, char **argv)
{
volatile unsigned short *complete;
volatile unsigned char *lsb, *msb, *IO;
unsigned char *regval;
int res;
int n, cntlByte;
int fd=open("/dev/mem",O_RDWR|O_SYNC);
assert(fd != -1);
setvbuf(stdout, NULL, _IONBF, 0);
/* lets initialize our pointers*/
lsb=(unsignedchar*)mmap(0,getpagesize(),PROT_WRITE|PROT_READ,MAP_SHARED,fd,Result);
assert(lsb != MAP_FAILED);
msb=lsb + 1;
complete=(unsignedshort*)mmap(0,getpagesize(),PROT_READ|PROT_WRITE,MAP_SHARED,fd,Busy);
assert(complete != MAP_FAILED);
IO=mmap(0,getpagesize(),PROT_READ|PROT_WRITE,MAP_SHARED,fd,Extern_ADC);
assert(IO != MAP_FAILED);
printf("debug IO:%s\n",IO);
assert(IO != MAP_FAILED);
regval=(unsigned char*)IO;
if(*regval & 0x01){
printf("OK\n");
}
else{
printf("fail\n");
}
printf("IO:%d\n",*IO);
/*ch.1*/
cntlByte =Channel_0;
printf("cntlByte:%d\n",cntlByte);
*lsb = cntlByte;
printf("debug lsb:%d\n",*lsb);
n=0;
while(n<<14 && (*complete & 0x80)!=0x0);
{
usleep(1<<n);
n++;
}
if(n == 14){
printf("FAIL, timed out\n");
return 1;
}
else {
printf("ok\n");
}
printf("reading result...");
res=*lsb;
printf("debug:%d\n",res);
res|=*msb<<8;
printf("result1:%d\n",res);
return 0;
}
The result that i get is:
$ ./test3
debug IO:.
OK
IO:1
cntlByte:81
debug lsb:0
ok
reading result...debug:0
result1:2048
What is going wrong here??
any help is appreciated.
thanks
Sonia
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|