Actually my code is just derived from classic spi example
#define SPI_DEVICE_PATH "/dev/spidev0.1"
// Open the SPI device
if ((spi_file = open(SPI_DEVICE_PATH, O_RDWR)) < 0) {
perror("Failed to open SPI device");
return -1;
}
// Configure SPI mode and bits per word
uint8_t mode = SPI_MODE_3;
uint8_t bits = 8;
if (ioctl(spi_file, SPI_IOC_WR_MODE, &mode) < 0) {
perror("Failed to set SPI mode");
close(spi_file);
return -1;
}
if (ioctl(spi_file, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
perror("Failed to set SPI bits per word");
close(spi_file);
return -1;
}
// Perform SPI transfer
struct spi_ioc_transfer transfer = {
.tx_buf = (unsigned long)tx_buffer,
.rx_buf = (unsigned long)rx_buffer,
.len = sizeof(tx_buffer),
.delay_usecs = 0,
.speed_hz = 1000000, // SPI speed in Hz
.bits_per_word = 8,
.cs_change = 1,
};
if (ioctl(spi_file, SPI_IOC_MESSAGE(1), &transfer) < 0) {
perror("Failed to perform SPI transfer");
close(spi_file);
return -1;
}
I've no glue where the problem is. Everything is ok, but not the CS.
Hi, I made some test with BBBiolib (McSPI) and CS is driven correctly. But the library doesn’t feet my requirements, so I would like to give a try to ioctl mode.
If you are referring to BBBiolib, it uses a low level approach, writes registers directly and does not work in user mode. I’ve had the BBB for a few days and to understand how it works you need to have in-depth knowledge of the AM3358 registry.
Can you see if it’s poking directly to the CS pin,
i.e. using it as a GPIO instead of letting the SPI device have direct control of it?
That could tell us if the PINMUX for it is in the wrong mode…
As an alternative, you could also consider using gpioinfo and gpioset duo to check
if you’re able to affect the CS pin with the overlay loaded (you shouldn’t).
lranders, thank you for your effort. Running spidev_test seems to works fine with spidev0.0. But I was expecting that it was on 0.1 for pins 17,18,21,22. Anyway my programs doesn’t works neither with 0.0 (CS always low) nor 0.1 (CS always hi), so I’m doing some error. I’ll recheck everything.