From: Michael Welling <mwelling@ieee.org>
To: Greg Wilson-Lindberg <GWilson@sakuraus.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: BBB IIO ADC access not working
Date: Thu, 20 Aug 2015 15:48:54 -0500 [thread overview]
Message-ID: <20150820204853.GA14530@deathstar> (raw)
In-Reply-To: <782E3A02C2EB2347BEA6DEA69DC7AB86021D3CBD452C@sfamail.SAKURAUS.LOCAL>
On Thu, Aug 20, 2015 at 01:21:17PM -0700, Greg Wilson-Lindberg wrote:
>
>
> > -----Original Message-----
> > From: Michael Welling [mailto:mwelling79@gmail.com] On Behalf
> > Of Michael Welling
> > Sent: Thursday, August 20, 2015 12:23 PM
> > To: Greg Wilson-Lindberg
> > Cc: Daniel Baluta; linux-iio@vger.kernel.org
> > Subject: Re: BBB IIO ADC access not working
> >
> > On Thu, Aug 20, 2015 at 11:41:03AM -0700, Greg Wilson-Lindberg wrote:
> > >
> > >
> > > > -----Original Message-----
> > > > From: Michael Welling [mailto:mwelling79@gmail.com] On Behalf Of
> > > > Michael Welling
> > > > Sent: Thursday, August 20, 2015 10:31 AM
> > > > To: Greg Wilson-Lindberg
> > > > Cc: Daniel Baluta; linux-iio@vger.kernel.org
> > > > Subject: Re: BBB IIO ADC access not working
> > > >
> > > > On Thu, Aug 20, 2015 at 10:27:30AM -0700, Greg
> > Wilson-Lindberg wrote:
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Greg Wilson-Lindberg
> > > > > > Sent: Thursday, August 20, 2015 9:19 AM
> > > > > > To: 'Michael Welling'
> > > > > > Cc: Daniel Baluta; linux-iio@vger.kernel.org
> > > > > > Subject: RE: BBB IIO ADC access not working
> > > > > >
> > > > > >
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Michael Welling [mailto:mwelling79@gmail.com] On
> > > > Behalf Of
> > > > > > > Michael Welling
> > > > > > > Sent: Thursday, August 20, 2015 9:14 AM
> > > > > > > To: Greg Wilson-Lindberg
> > > > > > > Cc: Daniel Baluta; linux-iio@vger.kernel.org
> > > > > > > Subject: Re: BBB IIO ADC access not working
> > > > > > >
> > > > > > > On Thu, Aug 20, 2015 at 08:50:28AM -0700, Greg
> > > > > > Wilson-Lindberg wrote:
> > > > > > > >
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: Michael Welling [mailto:mwelling79@gmail.com] On
> > > > > > Behalf Of
> > > > > > > > > Michael Welling
> > > > > > > > > Sent: Wednesday, August 19, 2015 2:43 PM
> > > > > > > > > To: Greg Wilson-Lindberg
> > > > > > > > > Cc: Daniel Baluta; linux-iio@vger.kernel.org
> > > > > > > > > Subject: Re: BBB IIO ADC access not working
> > > > > > > > >
> > > > > > > > > On Wed, Aug 19, 2015 at 02:34:39PM -0700, Greg
> > > > > > > Wilson-Lindberg wrote:
> > > > > > > > > >
> > > > > > > > > > So, in that case, can I just open it once and
> > > > leave it open?
> > > > > > > > >
> > > > > > > > > Yes.
> > > > > > > > >
> > > > > > > > > > Is it reading from a buffer, or is it reading what is
> > > > > > > > > current in the ADC?
> > > > > > > > >
> > > > > > > > > It is the current reading.
> > > > > > > > >
> > > > > > > > > > Can I just set up a timer to get readings to
> > average then?
> > > > > > > > >
> > > > > > > > > Sure.
> > > > > > > > >
> > > > > > > > > Here are some helper functions:
> > > > > > > > >
> > > > > > > > > int iio_adc_open_channel(int dev_num, int chan_num) {
> > > > > > > > > char filename[255];
> > > > > > > > >
> > > > > > > > > sprintf(filename,
> > > > > > > > > "/sys/bus/iio/devices/iio:device%d/in_voltage%d_raw",
> > > > > > > > > dev_num, chan_num);
> > > > > > > > >
> > > > > > > > > return open(filename, O_RDONLY); }
> > > > > > > > >
> > > > > > > > > int iio_adc_read_channel(int fd) {
> > > > > > > > > int count;
> > > > > > > > > char buffer[255];
> > > > > > > > > int value = -1;
> > > > > > > > >
> > > > > > > > > lseek(fd,0,SEEK_SET);
> > > > > > > > >
> > > > > > > > > count = read(fd, buffer, 255);
> > > > > > > > >
> > > > > > > > > if (count > 0)
> > > > > > > > > value = strtoul(buffer, NULL, 10);
> > > > > > > > >
> > > > > > > > > return value;
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > Example usage:
> > > > > > > > >
> > > > > > > > > int fd;
> > > > > > > > > .
> > > > > > > > > .
> > > > > > > > >
> > > > > > > > > fd = iio_adc_open_channel(0, 4); .
> > > > > > > > > .
> > > > > > > > >
> > > > > > > > > while (1)
> > > > > > > > > {
> > > > > > > > > printf("ADC = %x\n",
> > iio_adc_read_channel(fd)); }
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > > I converted to using this interface and left the
> > > > system running
> > > > > > > > overnight and the touch screen was locked up this morning.
> > > > > > >
> > > > > > > This is without any modifications to the kernel?
> > > > > > >
> > > > > >
> > > > > > This was still running the kernel modifications. I've
> > > > restarted it
> > > > > > this morning without the kernel modifications.
> > > > >
> > > > > I just dumped what I'm reading from the sys fs and all I'm
> > > > getting back is -1.
> > > >
> > > > Are you doing error checking on the file descriptor on open?
> > > > >
> > > >
> > >
> > > You were right, I had gone back to the original kernel that RCN
> > > shipped with the image and it doesn't export /sys/bus/iio.
> > >
> > > I rebuilt the 3.14.49-ti-r62 kernel, which is the same
> > release as the kernel in the image, but it does export
> > /sys/bus/iio, so that much is working better.
> > >
> > > But (there's always a but, isn't there), I'm reading three channels
> > > from the ADC, 4, 5, & 6. Channel 4 gets a good reading maybe 60% of
> > > the time I read it. Channel 5 gets a good reading maybe
> > every 40-50 tries. Channel 6 hardly ever gets a good reading.
> > >
> > > I guess I could just loop if I get a busy response,
> > although I don't
> > > know how many times I will get that return before I get a
> > good reading.
> > >
> >
> > What is the indicator that the reading is bad?
> >
>
> I get back -1 if the channel is busy.
> I just put in a loop and for channel 4 I get either 1 or 2 tries to get a good
> sample. Channels 5 & 6 are always returning a good sample on the second read.
>
> I'll have to leave this on for overnight to see if the touch screen will lock up.
You could try adding a poll to the read function to wait for readings to be ready.
int iio_adc_read_channel(int fd)
{
int count;
char buffer[255];
int value = -1;
struct pollfd pfd;
pfd.fd = fd;
pfd.events = POLLIN;
pfd.revents = POLLIN;
lseek(fd,0,SEEK_SET);
poll(&pfd, 1, -1);
count = read(fd, buffer, 255);
if (count > 0)
value = strtoul(buffer, NULL, 10);
return value;
}
next prev parent reply other threads:[~2015-08-20 20:49 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-31 21:15 BBB IIO ADC access not working Greg Wilson-Lindberg
2015-08-05 23:07 ` Greg Wilson-Lindberg
2015-08-06 7:35 ` Daniel Baluta
2015-08-06 15:42 ` Greg Wilson-Lindberg
2015-08-06 18:07 ` Michael Welling
2015-08-10 22:22 ` Greg Wilson-Lindberg
2015-08-10 22:33 ` Michael Welling
2015-08-11 16:00 ` Greg Wilson-Lindberg
2015-08-11 17:02 ` Michael Welling
2015-08-11 17:08 ` Greg Wilson-Lindberg
2015-08-11 17:43 ` Michael Welling
2015-08-13 23:00 ` Greg Wilson-Lindberg
2015-08-14 18:39 ` Michael Welling
2015-08-14 18:43 ` Greg Wilson-Lindberg
2015-08-14 20:40 ` Michael Welling
2015-08-14 23:46 ` Michael Welling
2015-08-18 16:06 ` Greg Wilson-Lindberg
2015-08-18 16:28 ` Michael Welling
2015-08-18 16:54 ` Greg Wilson-Lindberg
2015-08-18 17:37 ` Michael Welling
2015-08-18 17:40 ` Greg Wilson-Lindberg
2015-08-18 18:13 ` Michael Welling
2015-08-18 22:11 ` Greg Wilson-Lindberg
2015-08-18 22:31 ` Michael Welling
2015-08-19 16:27 ` Greg Wilson-Lindberg
2015-08-19 17:52 ` Michael Welling
2015-08-19 20:35 ` Greg Wilson-Lindberg
2015-08-19 20:48 ` Michael Welling
2015-08-19 21:13 ` Greg Wilson-Lindberg
2015-08-19 21:29 ` Michael Welling
2015-08-19 21:34 ` Greg Wilson-Lindberg
2015-08-19 21:42 ` Michael Welling
2015-08-20 15:50 ` Greg Wilson-Lindberg
2015-08-20 16:14 ` Michael Welling
2015-08-20 16:18 ` Greg Wilson-Lindberg
2015-08-20 17:27 ` Greg Wilson-Lindberg
2015-08-20 17:31 ` Michael Welling
2015-08-20 18:41 ` Greg Wilson-Lindberg
2015-08-20 19:23 ` Michael Welling
2015-08-20 20:21 ` Greg Wilson-Lindberg
2015-08-20 20:48 ` Michael Welling [this message]
2015-08-21 17:36 ` Greg Wilson-Lindberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150820204853.GA14530@deathstar \
--to=mwelling@ieee.org \
--cc=GWilson@sakuraus.com \
--cc=daniel.baluta@gmail.com \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).