LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-29-2010, 05:32 AM   #1
raulapati
Member
 
Registered: May 2010
Posts: 51

Rep: Reputation: 0
Question driver for ADE7758 ADC


I am interfacing ADE7758 to At91sam9261 spi interface. Linux 2.6.28 is running on my custom board. Does anyone have driver for this 12-bit ADC (ADE7758) on linux ?
 
Old 09-29-2010, 05:40 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Please use better thread titles than "help!" it's not informative or useful in any way at all.

I've updated your title.
 
Old 09-29-2010, 05:52 AM   #3
raulapati
Member
 
Registered: May 2010
Posts: 51

Original Poster
Rep: Reputation: 0
thank u...iam new to this forum....iam doinga project in which i have to measure currents and voltages from ADE7758..It is a energy mesuring IC...i have to interface it with at91sam9261 usin SPI protocol.the basic idea is to read the registers of ADE7758 and display them...how i have to perform this task..please give me som basic steps...
 
Old 09-29-2010, 03:50 PM   #4
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
If the CPU is well supported, linux kernel certainly have a SPI driver ready for it. So just do a library of functions that open, read, write and close the SPI port to configure and get data from the adc. What to write and how to read the adc must be explained in its datasheet.
 
Old 09-29-2010, 11:38 PM   #5
raulapati
Member
 
Registered: May 2010
Posts: 51

Original Poster
Rep: Reputation: 0
actually this ADC has several registers in it..when we give input current the value is stored in those registers and we have to send the address of that register from processor...iam not able to send the address via MOSI to device.this is a hexa format address...please any body over ther explain me...
 
Old 10-04-2010, 12:25 AM   #6
raulapati
Member
 
Registered: May 2010
Posts: 51

Original Poster
Rep: Reputation: 0
please anybody help mee....
 
Old 10-04-2010, 01:39 AM   #7
raulapati
Member
 
Registered: May 2010
Posts: 51

Original Poster
Rep: Reputation: 0
Question

please any body help me...



#include <linux/init.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/spi/spi.h>
#include <asm/gpio.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <asm/uaccess.h>
#include <linux/clk.h>
#include <linux/errno.h>
#include <linux/irq.h>
#include <linux/list.h>
#include <asm/io.h>
#include <mach/hardware.h>
#include <mach/at91_pio.h>
#include <mach/gpio.h>
#include <linux/gpio_keys.h>
#include <asm/delay.h>




struct adc_bus{
struct spi_message adc_msg;
struct spi_transfer adcxfer;
};




struct spi_device *adc_spi;
struct adc_bus *adc_bus;


#define NULL_TERM '\0'




#if 0
#define CS_CHANGE(adcxfer) ((adcxfer).cs_change = 1)
#else
#define CS_CHANGE(adcxfer) ((adcxfer).cs_change = 0)
#endif


int kernel_buf,user_buf;
unsigned char CharCnt;
unsigned int i=10;
int wevents;
int status;
int Buf1Cnt;
int lCnt=0;
int buf;


/************************ADC DRIVER FUNCTIONS******************************/

static int __devinit ADE7758_probe(struct spi_device *spi)
{
adc_spi=spi;
//Format_spi_write_data(&adc_spi->dev);
return 0;
}



/****************************WRITE TO ADC******************/

void Format_spi_write_data(struct device *dev)
{
struct spi_device *spi = to_spi_device(dev);
struct adc_bus *bus = kzalloc(sizeof *bus,GFP_KERNEL);
printk("******inwrite***********\n\n");

spi_message_init(&bus->adc_msg);
kernel_buf=1;
printk("\n -------------after spi_message_init------>\n");
bus->adcxfer.tx_buf = kernel_buf;
bus->adcxfer.len = 1;
CS_CHANGE(bus->adcxfer);
spi_message_add_tail(&bus->adcxfer,&bus->adc_msg);
printk("\nAfter msg add---------------->");
// status = spi_sync(spi,&bus->adc_msg);
printk("\n***************After spi_sync--%d------->\n",bus->adcxfer.tx_buf);

}




/*static int user_adc_write(struct file *file,char *buf,unsigned int count, loff_t *loft)
{
unsigned int data;
memset(kernel_buf,NULL_TERM,sizeof(kernel_buf));
//copy_from_user(kernel_buf,buf,count);
//sscanf(&buf[count],"%04d",&data);
printk("\n\n data =%d ",data);
return 0;
}*/


/****************************READ FROM ADC **************************/

void Format_spi_read_data(struct device *dev)
{
struct spi_device *spi = to_spi_device(dev);
struct adc_bus *bus = kzalloc(sizeof *bus,GFP_KERNEL);
spi_message_init(&bus->adc_msg);
buf= bus->adcxfer.rx_buf;
bus->adcxfer.len = 1;
CS_CHANGE(bus->adcxfer);
spi_message_add_tail(&bus->adcxfer,&bus->adc_msg);
// status=spi_sync(spi,&bus->adc_msg);
printk("**********in read function*********\n\n");
printk("%d volts",bus->adcxfer.rx_buf);
printk("%d status",status);
printk("**********out of read************\n\n");
}



/*static int user_adc_read(struct file *file,char *buf,unsigned char count, loff_t *ppos)
{
// wait_event_interruptible(prin_queue,wevent!=0);
// copy_to_user(buf,"001",3);
return 0;
}*/

/*********************************READ/WRITE COMPLETE*************************/



static struct spi_driver adcDriver = {
.driver = {
.name = "ADE7758",
.bus = &spi_bus_type,
.owner = THIS_MODULE,
},
.probe = ADE7758_probe,
};

static const struct file_operations user_adc_file_fops = {
.owner = THIS_MODULE,
// .read = user_adc_read,
// .write = user_adc_write,
};

static struct miscdevice ADE7758 = { /* creating a misc device called ADE7758 */
MISC_DYNAMIC_MINOR,
// 66,
"AdEDEV", /* NAme sets here, will be shown in /dev*/
&user_adc_file_fops
};

static int __init ADE7758_init(void)
{
int ret;
spi_register_driver(&adcDriver);
printk("\n ADC spi Driver is registered\n");

ret=misc_register(&ADE7758);
printk("\n Misc driver for ADC is registered\n");

Format_spi_write_data(&adc_spi->dev);
__udelay(2000);
Format_spi_read_data(&adc_spi->dev);
return ret;
}


module_init(ADE7758_init);

static void __exit ADE7758_exit(void)
{
spi_unregister_driver(&adcDriver);
misc_deregister(&ADE7758); /*Unregistering the device */
}

module_exit(ADE7758_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("xxx");
MODULE_DESCRIPTION("ADC Driver for ADE7758");





the above is the code with which iam trying to read adc ic but iam not able get the sck high at the adc chip...

dout -0
din- 1
cs -1
sck -0
this is the status of the ports at ic side..please help me to establish comunication between adc and processor

Last edited by raulapati; 10-11-2010 at 08:33 AM.
 
Old 10-11-2010, 05:51 AM   #8
raulapati
Member
 
Registered: May 2010
Posts: 51

Original Poster
Rep: Reputation: 0
adc driver for ade7758

iam still unable to get the data...can any body please help me to interface ade7758 to at91sam9261...
 
Old 10-11-2010, 05:54 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
TBH, I would suggest that this is not really a suitable forum for such information.
 
Old 10-12-2010, 06:51 AM   #10
raulapati
Member
 
Registered: May 2010
Posts: 51

Original Poster
Rep: Reputation: 0
iam trying to interface ade7758(adc) to at91sam9261...i have written a sample code which registers an spi driver and sends an address to ade7758 and receives a data...every thing is fine.My device is registered but kernel is giving a crash message....below is the message....



pl2303: Prolific PL2303 USB to serial adaptor driver
USB Serial support registered for TI USB 3410 1 port adapter
USB Serial support registered for TI USB 5052 2 port adapter
usbcore: registered new interface driver ti_usb_3410_5052
ti_usb_3410_5052: v0.9:TI USB 3410/5052 Serial Driver
udc: at91_udc version 3 May 2006
mice: PS/2 mouse device common for all mice
gpio-keys: failed to configure input direction for GPIO 0, error -22
gpio-keys: probe of gpio-keys failed with error -22
ads7846 spi0.2: touchscreen, irq 29
input: ADS784x Touchscreen as /class/input/input0
i2c /dev entries driver
input: adp5588-keys as /class/input/input1
adp5588-keys 0-0034: Rev.2 keypad, irq 46
i2c-gpio i2c-gpio: using pins 39 (SDA) and 40 (SCL)
rx8025 0-0032: a power voltage drop was detected, you may have to readjust the clock
loaded driver for RX-8025 SA/NB on addr 50
**********
ADC spi Driver is registered
******************************
Misc driver for ADC is registered
***********RBuf[0]= 00TBuf[0]= 48

RBuf[0]=00----------********************


***********************************inwrite***********


-------------after spi_message_init------>

After msg add----------------><2>kernel BUG at arch/arm/mm/dma-mapping.c:495!
Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = c0004000
[00000000] *pgd=00000000
Internal error: Oops: 805 [#1] PREEMPT
Modules linked in:
CPU: 0 Not tainted (2.6.28-ATIL-H10 #109)
PC is at __bug+0x20/0x2c
LR is at vprintk+0x360/0x3b4
pc : [<c002e98c>] lr : [<c0043a8c>] psr: 20000013
sp : c3817da0 ip : c3817cf8 fp : c3817dac
r10: ffffffff r9 : 00000000 r8 : c3a46e00
r7 : c39f1540 r6 : c3a41360 r5 : 00000048 r4 : c3a4138c
r3 : 00000000 r2 : c3816000 r1 : c3816000 r0 : 00000030
Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: 0005317f Table: 20004000 DAC: 00000017
Process swapper (pid: 1, stack limit = 0xc3816268)
Stack: (0xc3817da0 to 0xc3818000)
7da0: c3817dbc c3817db0 c0030518 c002e97c c3817de4 c3817dc0 c01df8bc c00304bc
7dc0: c3a41360 c3817dec 00000000 00000000 00000000 00000000 c3817e14 c3817de8
7de0: c01de968 c01df828 c0043b08 00000000 c3817df0 c3817df0 c3817e34 c3a41360
7e00: c05fb750 c3a46e00 c3817e34 c3817e18 c0218908 c01de930 c3817e64 c05fb774
7e20: c05fb76c c05fb748 c3817e64 c3817e38 c001efcc c0218878 00000001 c0025758
7e40: c3817e64 c03ddba4 c0025758 00000000 c001ef28 00000001 c3817fdc c3817e68
7e60: c002a318 c001ef38 00000104 00000104 c3817eb4 c3817e80 c3817ecc 00000000
7e80: c38035a4 a0000013 c3817edc 00000000 c38035a4 a0000013 c3817ec4 c3817ea8
7ea0: c008faf8 c01626d8 c38035a4 0000010e c38035a0 00000000 c3817f24 c3817ec8
7ec0: c01591f4 c008fae4 c3817ef4 c3817f44 00000000 00000000 000000d0 c3811e30
7ee0: 00000000 a0000013 c3817f1c c3817ef8 c0159454 c02eea0c 000000d0 c3816000
7f00: c38345c0 c38336e0 c03e5f90 c3817f44 00000000 00000000 c3817f34 c3817f28
7f20: c0159228 00000000 c3817f6c c3817f38 c00d105c c02eea0c c3834618 c00d0e20
7f40: c03c0584 0000010e c3817f96 c38345c0 c03c0584 0000007f c03e5f90 00000000
7f60: c3817f8c c3817f70 c00d11c4 c00d0ea8 c3817f8c c38336e0 c00d1200 c3817f96
7f80: c3817fbc c3817f90 c006d7ec c00d1154 c3817fac 32312060 00000037 00000000
7fa0: 000000c0 c03c14c0 c03be7bc 00000000 c3817fdc c3817fc0 c006d858 c002567c
7fc0: c0025758 00000000 00000000 00000000 c3817ff4 c3817fe0 c00088d8 c002a2c8
7fe0: 00000000 00000000 00000000 c3817ff8 c0045bd8 c0008874 ffffffff ffffffff
Backtrace:
[<c002e96c>] (__bug+0x0/0x2c) from [<c0030518>] (dma_cache_maint+0x6c/0x98)
[<c00304ac>] (dma_cache_maint+0x0/0x98) from [<c01df8bc>] (atmel_spi_transfer+0xa4/0x1b0)
[<c01df818>] (atmel_spi_transfer+0x0/0x1b0) from [<c01de968>] (spi_sync+0x48/0x6c)
[<c01de920>] (spi_sync+0x0/0x6c) from [<c0218908>] (Format_spi_write_data+0xa0/0xd8)
r6:c3a46e00 r5:c05fb750 r4:c3a41360
[<c0218868>] (Format_spi_write_data+0x0/0xd8) from [<c001efcc>] (ADE7758_init+0xa4/0xec)
r6:c05fb748 r5:c05fb76c r4:c05fb774
[<c001ef28>] (ADE7758_init+0x0/0xec) from [<c002a318>] (__exception_text_end+0x60/0x190)
r8:00000001 r7:c001ef28 r6:00000000 r5:c0025758 r4:c03ddba4
[<c002a2b8>] (__exception_text_end+0x0/0x190) from [<c00088d8>] (kernel_init+0x74/0xdc)
r8:00000000 r7:00000000 r6:00000000 r5:c0025758 r4:c002567c
[<c0008864>] (kernel_init+0x0/0xdc) from [<c0045bd8>] (do_exit+0x0/0x79c)
r5:00000000 r4:00000000
Code: e1a01000 e59f000c eb005455 e3a03000 (e5833000)
---[ end trace 03c78116ca73337f ]---
Kernel panic - not syncing: Attempted to kill init!






can any body please help meeeee..........
 
Old 10-12-2010, 08:41 AM   #11
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Again, I really think you need to find an alternative forum that's specifically about this sort of stuff
 
Old 10-12-2010, 11:59 PM   #12
raulapati
Member
 
Registered: May 2010
Posts: 51

Original Poster
Rep: Reputation: 0
can u tell me in which forum i have to post it.....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ADC configuration in rhel 5.3 abhijeetdutta Red Hat 0 08-21-2009 03:45 PM
LTC1861 ADC driver... ramesh6056 Linux - Software 8 02-16-2009 02:19 AM
Can samba 3 act as ADC or not ? marozsas Linux - Networking 1 09-10-2008 01:59 PM
Device driver (ADC) knockout_artist General 0 01-06-2006 01:06 PM
Anyone good with ADC or DSP's? illiniguy3043 Programming 0 10-07-2004 11:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration