[BBB] SPIdev1 communcations

Hi,

I’m back again with another IO question for the BeagleBone Black.

I’ve been trying to configure the SPI 1 (specifically spidev1:0) to communicate with an ADC that uses SPI Mode 3 and has a max speed of 10kHz.

My general code knowledge exists in C/C++, and so I am attempting to use ioctl() to set up the bus and communicate.

My steps thus far have been using the bbb-universal-cape (all other capes disabled except for a UART cape) with the config-pin utility to set the related pins to their correct values, shown below:

image

Additionally, I can confirm the pins are part the the pinmux groups found by:

cat /sys/kernel/debug/pinctrl/pinctrl-maps

and that /dev/spidev1.0 exists.

From here, things go off the rails. My code to try to set the config is as follows:

    const char *SPI_DEV_1 = "/dev/spidev1.0";   /* ADC128S102CIMT is on SPI1, CS0 */
    int     spi_adc;

    /* Open the SPI device connected to ADC */
    spi_adc = open(SPI_DEV_1, O_RDWR);
    if(spi_adc < 0)
    {
        perror("open");
    }
    else printf("Opened SPI ADC\n");
	if(ioctl(spi_adc, SPI_IOC_WR_MAX_SPEED_HZ, 10000)==-1)
		printf("Could not set Speed\n");
	if(ioctl(spi_adc, SPI_IOC_RD_MAX_SPEED_HZ, 10000)==-1)
		printf("Could not set Speed\n");

    if(ioctl(spi_adc, SPI_IOC_WR_MODE, 3)==-1) // According to the ADC datasheet, Clk Polarity and Clk Phase are high
		printf("Could not set Mode\n");
	if(ioctl(spi_adc, SPI_IOC_RD_MODE, 3)==-1)
		printf("Could not set Mode\n");

This code snippet returns errors for each ioctl(), indicating something is failing with the ioctl() of the spidev1.

In my debugging, I’ve attempted to do as describied on the elinux enable SPIDEV. Hilariously, the dts file there completely removes the spidev1, so I’ve disabled it for the time being.

Addtionally, I am unable to find the spidev_test util that the elinux page says exists.

Side note: running the install.sh for the capes seems to compile and install the old .sh config-pin utility.

I’ve found this utility to be a good replacment for the missing spidev test applicaiton:

sudo ./spidev_test -v --device /dev/spidev1.0

Other then calling config-pin, to setup the pins, spidev should just work out of the box…

Regards,

Confirmed, your linked spidev test works when I short TX/RX. I think I can go through this and begin to determine what the issue is.

Side note: Not sure if this is a limitation of the BBB, but it seems I get some junk on the RX line if I set the maxspeed to 10k. I’m hopeful this will resolve when I plug into the ADC.

Thanks for the help so far.

Ok, I’m a bit embarrassed. Looks like it was my own mistake in passing args into ioctl. I do appreciate the help in getting me a spidev-test though!