Spidev file not generated for slave

  • Okay understood hereby sending you the boot.img for SPI master that i created which does not seem to work please check and revert what is the issue with the same
    boot.zip (2.93 MiB)
    SPI Master BOOT image
    Downloaded 124 times
  • I burned the boot.img image you provided. The /dev/spidev0.0 device it created is functioning properly. I connected MISO and MOSI together for a loopback test (refer to https://wiki.luckfox.com/Luckfox-Pico/L ... on-program). Using an oscilloscope, I could also observe the SCLK as a clock output. Please try to remove /etc/luckfox.cfg and restart the system for the test. First, make sure the loopback test is error-free.
  • As per your recommendations i tried with the loopback test and it is working okay and then tried to establish master and slave communication between two different devices and with partial success i was able to initiate communication but the data is not received properly at slave hereby sharing the output and logs and programs for master and slave

    Master output and logs :

    Code: Select all

    [root@luckfox maprograms]# ./spi
    Send 50 bytes of data  max speed: 100000 Hz.
    [root@luckfox maprograms]# ./spi
    Send 50 bytes of data  max speed: 100000 Hz.
    [root@luckfox maprograms]# cat /var/log/messages  | grep "spi"
    Jan  1 00:00:00 luckfox kern.warn kernel: [    0.087828] rockchip-spi ff500000.spi: no high_speed pinctrl state
    Jan  1 00:00:00 luckfox kern.err kernel: [    0.088819] rockchip-spi ff500000.spi: chipselect 0 already in use
    Jan  1 00:00:00 luckfox kern.err kernel: [    0.088848] spi_master spi0: spi_device register error /spi@ff500000/fbtft@0
    Jan  1 00:00:00 luckfox kern.warn kernel: [    0.088867] spi_master spi0: Failed to create SPI device for /spi@ff500000/fbtft@0
    Jan  1 00:00:00 luckfox kern.err kernel: [    0.088890] rockchip-spi ff500000.spi: chipselect 0 already in use
    Jan  1 00:00:00 luckfox kern.err kernel: [    0.088903] spi_master spi0: spi_device register error /spi@ff500000/spi_test@00
    Jan  1 00:00:00 luckfox kern.warn kernel: [    0.088916] spi_master spi0: Failed to create SPI device for /spi@ff500000/spi_test@00
    Jan  1 00:00:00 luckfox kern.info kernel: [    0.088926] rockchip-spi ff500000.spi: probed, poll=0, rsd=0
    Jan  1 00:00:00 luckfox kern.info kernel: [    0.090398] spi-nand spi2.0: Winbond SPI NAND was found.
    Jan  1 00:00:00 luckfox kern.info kernel: [    0.090423] spi-nand spi2.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
    Jan  1 00:00:00 luckfox kern.notice kernel: [    0.091790] 7 cmdlinepart partitions found on MTD device spi-nand0
    Jan  1 00:00:00 luckfox kern.notice kernel: [    0.091812] Creating 7 MTD partitions on "spi-nand0":
    
    Slave output and logs :

    Code: Select all

    [root@luckfox slprograms]# ./spislave
    ---------Receive 50 bytes of data  max speed:100000 Hz---------
    RX BUFFER : $�1! IE*(Q*�������
    ---------Receive 50 bytes of data  max speed:100000 Hz---------
    RX BUFFER :"b
     �(H��_�������
    ^C
    [root@luckfox slprograms]# cat /var/log/messages  | grep "spi"
    Jan  1 00:00:00 luckfox kern.warn kernel: [    0.088930] rockchip-spi ff500000.spi: no high_speed pinctrl state
    Jan  1 00:00:00 luckfox kern.err kernel: [    0.089405] spi_slave spi0: /spi@ff500000/spidev@0 is not called 'slave'
    Jan  1 00:00:00 luckfox kern.warn kernel: [    0.089440] spi_slave spi0: Failed to create SPI device for /spi@ff500000/spidev@0
    Jan  1 00:00:00 luckfox kern.err kernel: [    0.089462] spi_slave spi0: /spi@ff500000/fbtft@0 is not called 'slave'
    Jan  1 00:00:00 luckfox kern.warn kernel: [    0.089474] spi_slave spi0: Failed to create SPI device for /spi@ff500000/fbtft@0
    Jan  1 00:00:00 luckfox kern.info kernel: [    0.090008] rockchip-spi ff500000.spi: probed, poll=0, rsd=0
    Jan  1 00:00:00 luckfox kern.info kernel: [    0.091528] spi-nand spi2.0: Winbond SPI NAND was found.
    Jan  1 00:00:00 luckfox kern.info kernel: [    0.091555] spi-nand spi2.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
    Jan  1 00:00:00 luckfox kern.notice kernel: [    0.092919] 7 cmdlinepart partitions found on MTD device spi-nand0
    Jan  1 00:00:00 luckfox kern.notice kernel: [    0.092941] Creating 7 MTD partitions on "spi-nand0":
    Jan  1 00:00:07 luckfox kern.err kernel: [    7.549680] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/status
    Jan  1 00:00:07 luckfox kern.err kernel: [    7.549729] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/pinctrl-0
    Jan  1 00:00:07 luckfox kern.err kernel: [    7.549747] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/spidev@0/status
    Jan  1 00:00:07 luckfox kern.err kernel: [    7.549766] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/spidev@0/spi-max-frequency
    Jan  1 00:03:59 luckfox kern.err kernel: [  239.836645] rockchip-spi ff500000.spi: state=0
    Jan  1 00:03:59 luckfox kern.err kernel: [  239.836700] rockchip-spi ff500000.spi: tx_left=0
    Jan  1 00:03:59 luckfox kern.err kernel: [  239.836724] rockchip-spi ff500000.spi: rx_left=32
    Jan  1 00:03:59 luckfox kern.err kernel: [  239.836908] spi_slave spi0: failed to transfer one message from queue
    
    Master c program :

    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>
    
    #define SPI_DEVICE_PATH "/dev/spidev0.0"
    
    int main() {
        int spi_file;
        uint8_t tx_buffer[50] ="Hello world";
        uint8_t rx_buffer[50];
    
        /* 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(tx_buffer),
            .delay_usecs = 0,
            .speed_hz = 100000,  // SPI speed in Hz
            .bits_per_word = 8,
        };
    
        /* Send Data */
        for (int i = 0; i < transfer.len; i++)
            tx_buffer[i] = i;
        sleep (1);
    
        if (ioctl(spi_file, SPI_IOC_MESSAGE(1), &transfer) < 0) {
            perror("Failed to perform SPI transfer");
            close(spi_file);
            return -1;
        }
    
        printf("Send %d bytes of data  max speed: %d Hz.\n",transfer.len,transfer.speed_hz);
    
        /* Close the SPI device */
        close(spi_file);
    
        return 0;
    }
    
    Slave c program :

    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[50];
    
        /* 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 = 100000,  // 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("%s",rx_buffer);
           // printf("SPI RX: 0x%08X:", 0);
           printf("RX BUFFER : %s",rx_buffer);
        /*   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;
    }
    
    Hereby sending a photo of the hardware connection for your reference.
    Hardware_connection.jpg
    Please suggest a suitable solution to rectify this issue
    Last edited by Samip_veer on 2025-05-21 12:33, edited 1 time in total.
  • Your connection is still lacking the connection of the GND of the two boards. Refer to the GND of different values may cause abnormal data reception. Please first test it using the example routine from the wiki. Providing testing and debugging for the user's project does not fall within the scope of technical support.