---------Device tree code ---------------
Code: Select all
&spi0 {
status = "okay";
spi-slave;
slave {
compatible ="rockchip,spidev";
reg = <0>;
id = <0>;
};
};
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
#include <string.h>
#define SPI_DEVICE_PATH "/dev/spidev0.0"
int main() {
int spi_file,ret;
uint8_t tx_buffer[50];
uint8_t rx_buffer[255];
/* 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_0;
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(rx_buffer),
.delay_usecs = 0,
.speed_hz = 49000000, // SPI speed in Hz
.bits_per_word = 8,
};
while(1)
{
/* Clear buffer */
memset(rx_buffer,0,sizeof(rx_buffer));
/* Waiting for data */
do {
ret = ioctl(spi_file, SPI_IOC_MESSAGE(1), &transfer);
} while (ret < 0);
/* Print rx_buffer*/
printf("---------Receive %d bytes of data max speed:%d Hz---------\n",ret,transfer.speed_hz);
printf("SPI RX: 0x%08X:", 0);
for (int i = 0; i < ret; i++) {
printf(" %02X",rx_buffer[i] );
if ((i + 1) % 16 == 0){
printf("\nSPI RX: 0x%08X:", i+1);
}
}
printf("\n");
}
/* Close the SPI device */
close(spi_file);
return 0;
}
1. User mode SPI device driver support = Y
2. SPI slave protocol handlers = Y
Can you please help regarding the matter i am following the procedure from the WIKI but still not able to generate device file.