Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. SPI RX trouble on TI Sitara AM3358
Forum Updated to NodeBB v4.3 + New Features

SPI RX trouble on TI Sitara AM3358

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    timroberts
    wrote on last edited by
    #1

    I've been working on an app in Qt and I've run into some trouble. My program needs to use SPI to communicate with a 22 bit ADC (Microchip MCP3551) attached to a load cell. I'm running the program on a TI Sitara AM3358 processor.

    I know my system is connected to the ADC chip correctly, I can get values back from the chip in linux by using the hexdump command. I've also verified the connections using a logic analyser.

    Where I'm running into trouble is communicating to the system inside of Qt. Earlier I had done some tests using a loopback and the program responds correctly to that. When I stop using the loopback and attach my pins to the ADC chip my logic analyser displays the values that I'm expecting but my Qt program does not give me usable information on my SPI port.

    To be honest something is probably set up incorrectly, but I'm not sure where to begin looking. Relevant code snippets are below.

    Thanks for any assistance.

    @
    #ifdef SPIDEBUG
    //declare device to use
    static const char* device = "/dev/spidev1.0";
    //declare variables
    int fd;
    int ret;
    BYTE mode = 0;
    BYTE bits = 8;
    DWORD speed = 5000000;
    BYTE tx[255] = "639";
    BYTE rx[255];

    //open the SPI device
    fd = open(device, O_RDWR);
    
    //verify we opened the device properly
    if (fd < 0)
        qDebug() << "can't open device";
    
    
     //spi mode
    
    ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
    if (ret == -1)
        qDebug() << "can't set spi mode";
    
    ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
    if (ret == -1)
        qDebug() << "can't get spi mode";
    
    
     //bits per word
    
    ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
    if (ret == -1)
        qDebug() << "can't set bits per word";
    
    ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
    if (ret == -1)
        qDebug() << "can't get bits per word";
    
    
     //max speed hz
    
    ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
    if (ret == -1)
        qDebug() << "can't set max speed hz";
    
    ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
    if (ret == -1)
        qDebug() << "can't get max speed hz";
    
    //declare new instance of SPI Utilities
    SPIUtils *x = new SPIUtils;
    //send values over tx, receive data back in rx
    x->SPItransfer(fd, tx, 3, rx);
    
    qDebug() << rx;
    
    //close file
    ::close(fd);
    

    #endif

    void SPIUtils::SPItransfer(int filedescriptor, BYTE *tx, BYTE Length, BYTE *rx)
    {
    //declare variables
    int ret;
    spi_ioc_transfer tr;

    //set up SPI transfer structure
    //set up tx buffer
    tr.tx_buf = (unsigned long) tx;
    //set up rx buffer
    tr.rx_buf = (unsigned long) rx;
    //set up length of message to send
    tr.len = Length;
    //set inter-character delay
    tr.delay_usecs = 0;
    //set max speed
    tr.speed_hz = 5000000;
    //set number of bits per word
    tr.bits_per_word = 8;
    //set up chip select
    tr.cs_change = 0;
    //not sure what this is
    tr.pad = 0;
    
    //set up SPI to send message
    ret = ioctl(filedescriptor, SPI_IOC_MESSAGE(1), &tr);
    //check result from SPI port setup
    if (ret < 1)
    {
        qDebug() << filedescriptor;
        qDebug() << ret;
        qDebug() << errno;
        qDebug() << "can't send spi message";
    }
    
    return;
    

    }

    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Where/when are you calling the code in the SPIDEBUG ifdef ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        timroberts
        wrote on last edited by
        #3

        Hi,

        Its declared at the beginning of the file. I think I've figured the issue out. Turns out I'm an idiot. If you're going to use an array, you need to reference the array properly. Once I got my array issue sorted out, the rest fell into place.

        Thanks anyways.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Don't worry, missing an array initialization happened to all of use.

          However, your ifdefed code should rather be integrated into your class. Floating like that in your file it should not even compile.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved