Hi NXP team,
I am working on iMX8QXP SPI. I need to know the supported modes for SPI in iMX8QXP. I understand from the manual that it supports both master and slave mode. So I am using spidev to communicate with the SPI interface. When I tried to set the 3-wire mode(which is half-duplex), I was not able to set it. Please find below the test code used and the output
=========================SPI Test Code BEGIN==============================
#include <fcntl.h>
#include <sys/ioctl.h>
int main(int argc, char *argv[])
{
int fd;
int ret = 0;
char mode;
fd = open("/dev/spidev0.0", O_RDWR);
if (fd >= 0)
{
/* write mode */
mode = SPI_MODE_0;
ret = ioctl(fd,SPI_IOC_WR_MODE,&mode);
if (ret == -1)
perror("mode0:");
/* read mode */
ioctl(fd,SPI_IOC_RD_MODE,&mode);
printf("mode0 = %u\n",mode);
/* write mode */
mode = SPI_MODE_1;
ret = ioctl(fd,SPI_IOC_WR_MODE,&mode);
if (ret == -1)
perror("mode1:");
/* read mode */
ioctl(fd,SPI_IOC_RD_MODE,&mode);
printf("mode1 = %u\n",mode);
/* write mode */
mode = SPI_MODE_2;
ret = ioctl(fd,SPI_IOC_WR_MODE,&mode);
if (ret == -1)
perror("mode2:");
/* read mode */
ioctl(fd,SPI_IOC_RD_MODE,&mode);
printf("mode2 = %u\n",mode);
/* write mode */
mode = SPI_MODE_3;
ret = ioctl(fd,SPI_IOC_WR_MODE,&mode);
if (ret == -1)
perror("mode3:");
/* read mode */
ioctl(fd,SPI_IOC_RD_MODE,&mode);
printf("mode3 = %u\n",mode);
/* write mode */
mode = SPI_3WIRE;
ret = ioctl(fd,SPI_IOC_WR_MODE,&mode);
if (ret == -1)
perror("mode-3wire:");
/* read mode */
ioctl(fd,SPI_IOC_RD_MODE,&mode);
printf("mode16 = %u\n",mode);
if (ret == -1)
perror("mode3:");
/* read mode */
ioctl(fd,SPI_IOC_RD_MODE,&mode);
printf("mode3 = %u\n",mode);
/* write mode */
mode = SPI_3WIRE;
ret = ioctl(fd,SPI_IOC_WR_MODE,&mode);
if (ret == -1)
perror("mode-3wire:");
/* read mode */
ioctl(fd,SPI_IOC_RD_MODE,&mode);
printf("mode16 = %u\n",mode);
}
close(fd);
return 0;
}
=========================SPI Test Code ENDS==============================
The output I have got is below which shows that 3-wire(half-duplex) is not supported:
mode0 = 4[ 1162.005031] spidev spi0.0: setup: unsupported mode bits 10
mode1 = 5
mode2 = 6
mode3 = 7
mode-3wire:: Invalid argument
mode16 = 7
Queries:
- In iMX8 QXP, below modes are supported? Please let me know
- Full Duplex Master
- Full Duplex Slave
- Half Duplex(3-wire) Master
- Half Duplex(3-wire) Slave
- Does any driver configurations need to be done to enable all the above modes?
- In the above sample code, reading back the SPI modes give 4,5,6 & 7 instead of 0,1,2,3. What is the reason for this?
- Please share some example or reference codes if any for the SPI
Thank you,
Vijay.