AnsweredAssumed Answered

Can't send spi message in imx6 with qt

Question asked by emmanuel perea on Aug 15, 2018
Latest reply on Sep 4, 2018 by emmanuel perea

Hello I am devolping a Qt app for a imx6 freescale microprocessor. I am using qtcreator 4.2.1.
I need to use the SPI module of imx6. At firs I build a 3.14 kernel version and I made a program bassed of spidev_test example. My program is:


First SPI configuration:


    int ret = 0;
    device = "/dev/spidev0.0";
    bits = 8;
    speed = 4500000;
    mode = 0;
    delay = 0;
    fd = open(device, O_RDWR);
    if (fd < 0){
        pabort("can't open device");
        qDebug("Open device");
     * spi mode
    ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
    if (ret == -1){
        pabort("can't set spi mode");


    ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
    if (ret == -1){
        pabort("can't get spi mode");
     * bits per word
    ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
    if (ret == -1){
        pabort("can't set bits per word");


    ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
    if (ret == -1){
        pabort("can't get bits per word");
     * max speed hz
    ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
    if (ret == -1){
        pabort("can't set max speed hz");
    ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
    if (ret == -1){
        pabort("can't get max speed hz");
    qDebug("spi mode: %d\n", mode);
    qDebug("bits per word: %d\n", bits);
    qDebug("max speed: %d Hz (%d KHz)\n", speed, speed/1000);


Then the transfer function:


void SpiCom::transfer(int fd, unsigned char word){


    int ret;
    uint8_t rx[] = {0, };


    spi_ioc_transfer tr;
    unsigned char data[] = {word};
    tr.tx_buf = (unsigned long)data;
    tr.rx_buf = (unsigned long)rx;
    tr.len = 1;
    tr.delay_usecs = delay;
    tr.speed_hz = speed;
    tr.bits_per_word = bits;


    ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
    if (ret < 1)
        pabort("can't send spi message");


    dataReaded = (unsigned char)rx[0];


With 3.14 version kernel my program works well but I had to update to a 4.9 kernel version and then my program doesn't work. When I want to transfer data always show "can't send spi message" message error.
If I compile this part of program with gcc compiler works but when I use qt compiler and execute the app It shows message error.
I am searching for everywhere but I couldn't find nothing.
If someone can help me.