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:
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.