Hello I am currently using an ADS1118evm hooked up to a Beagleboard
I just need to make sure I can get voltage readings from the ADC to the beagleboard.
For thw interface I am using SpiMode1 and connecting the ADS1118evm chip select, clck, mosi and miso to the appropriate ports (or at least I hope so)
Here is the code I am using
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
static const char *device = "/dev/spidev3.0";
static void pabort(const char *s)
{
perror(s);
abort();
}
//ReadADCADS1118(int fd, float &voltage)
int main()
{
int fd;
int ret;
uint8_t tx_buf[] = { 0x81, 0x83 };
uint8_t rx_buf[2];
struct spi_ioc_transfer spi_tr;
uint8_t mode = SPI_MODE_1;
uint32_t spi_speed = 4000000;
unsigned long Volts;
fd = open(device, O_RDWR);
if (fd < 0)
pabort("can't open device");
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
pabort("can't set spi mode");
spi_tr.tx_buf = (unsigned long)tx_buf;
spi_tr.rx_buf = (unsigned long)rx_buf;
spi_tr.len = 2;
spi_tr.delay_usecs = 10;
spi_tr.speed_hz = spi_speed;
spi_tr.bits_per_word = 8;
printf("Test 1:");
if( ioctl(fd, SPI_IOC_MESSAGE(1), &spi_tr) < 0 )
pabort("can't open device");
for (ret = 0; ret < 2; ret++) {
if (!(ret % 6))
puts("");
printf("%.2X ", rx_buf[ret]);
}
puts("");
printf("\n\nTest 2:");
if( ioctl(fd, SPI_IOC_MESSAGE(1), &spi_tr) < 0 )
pabort("can't open device");
for (ret = 0; ret < 2; ret++) {
if (!(ret % 6))
puts("");
printf("%.2X ", rx_buf[ret]);
}
puts("");
return 0;
}
I am doing a one shot mode read so that I can see how to interpret my raw voltage.
But I don't think I am doing it correctly, is there anything wrong with my code?
Thank you,
Alonzo