Spidev guidance

Hi All,

I'm trying to write a SPI driver for the AD7793 analog to digital converter. Actually, I've written a driver using EMAC's SPI class but since I've encountered some strange problems I've decided to use spidev.

I was able to successfully create spidev1.1 in my /dev dir. Now I've written code to try and talk to my AD7793. The question I have is this:

In order to reset the A/D I have to write 32 consecutive one's to the device while mosi is high. In other words, 32 SCLK pulses need to be initiated in order to reset the device.

I'm confused on how to do this in the code. I'm using the spidev_fdx.c code as a template. Is it valid to simply do this:

uint8_t tx = 0xFFFFFFFF;

and then:

struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .rx_buf = (unsigned long)rx, .len = ARRAY_SIZE(tx), .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, };

ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);

A code snippet of how this would be done would be a tremendous help.

Thanks!

Reply to
camtech
Loading thread data ...

You'd probably want to send uint8_t tx[4] =3D {0xFF, 0xFF, 0xFF, 0xFF} and struct spi_ioc_transfer tr =3D { .tx_buf =3D tx, .rx_buf =3D rx, .len =3D ARRAY_SIZE(tx), .delay_usecs =3D delay, .speed_hz =3D speed, .bits_per_word =3D bits,

Reply to
Jeremy

also put delay=3D500us

--

Reply to
Rajkumar M

Thanks, guys! I'll give that a try and see how it goes. Any thoughts on what SPI mode should be used?

Upon looking at the AD7793 documentation I believe SPI_MODE_3 is what I need to pass in.

Reply to
camtech

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.