This is the area to clarify hardware specification if there's anything unclear from the datasheet. If the specification is software related, please ask in the related software section.

UP2 SPI speed

nukularnukular Posts: 68New Member ✭✭✭

Hi,

I was wondering what the max speed of SPI on the UP2 is. In the wiki it says it's 25 MHz, in the MRAA docs it says 10 MHz, but when I use SPI via MRAA, 1 MHz is the maximum (anything higher gets lowered to 1 MHz automatically).

I am using Ubuntu 16.04 with the 4.9.45-upboard kernel.

What am I doing wrong? Can I set the max speed for SPI somewhere?

Tagged:

Comments

  • Nicola LunghiNicola Lunghi Posts: 131Emutex mod

    Hi
    the maximum speed aaccording on the datasheet is 25mhz but due to a bug in the Intel SPI driver the speed over 10Mhz are incorrectly set in the controller so the maximum usable speed is 10Mhz.

    have you try to set the frequency in mraa like here?

    https://github.com/intel-iot-devkit/mraa/blob/master/examples/spi_max7219.c#L43

    please share your code so we can test it

  • nukularnukular Posts: 68New Member ✭✭✭

    Yes, that's how I set the speed. And it works for everything <= 1MHz, but for anything higher libmraa says "spi: Selected speed reduced to max allowed speed". I also verified that the actual speed is 1 MHz by looking at the clock pin with a logic analyzer.

    I did find out that MRAA checks the max allowed speed in spi.c by reading SPI_IOC_RD_MAX_SPEED_HZ which is defined in spidev.h in the linux kernel.
    But I didn't really get any further.

    Is the value there read from actual hardware or is that maybe some setting you can configure when compiling the linux kernel or something like that?

    The code I used for testing is just taken from an example:
    void test_spi(){

    uint8_t buf[4096];
    memset(buf, 0xAA, sizeof(buf));
    
    printf("Testing SPI...\n");
    mraa_spi_context spi;
    spi = mraa_spi_init(1);
    if (spi == NULL) {
        printf("Initialization of spi failed, check syslog for details, exit...\n");
        exit(1);
    }
    
    printf("SPI initialised successfully\n");
    
    mraa_spi_frequency(spi, 4000000);
    mraa_spi_lsbmode(spi, 0);
    
    // The MAX7219/21 Chip needs the data in word size
    if (mraa_spi_bit_per_word(spi, 16) != MRAA_SUCCESS) {
        printf("Could not set SPI Device to 16Bit mode, exit...\n");
        exit(1);
    };
    
    mraa_spi_write_buf(spi, buf, sizeof(buf));
    
    mraa_spi_write_word(spi, 0x0900); // Do not decode bits
    mraa_spi_write_word(spi, 0x0a05); // Brightness of LEDs
    mraa_spi_write_word(spi, 0x0b07); // Show all Scan Lines
    mraa_spi_write_word(spi, 0x0c01); // Display on
    mraa_spi_write_word(spi, 0x0f00); // Testmode off
    
    mraa_spi_stop(spi);
    
    printf("SPI Test Done!\n");
    

    }

  • Nicola LunghiNicola Lunghi Posts: 131Emutex mod
    edited January 16

    Hi
    thanks for reporting the issue we will look at it.
    In the meantime you can try to comment those lines on mraa

    https://github.com/intel-iot-devkit/mraa/blob/master/src/spi/spi.c#L258

    // if (ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) {
    // if (speed < hz) {
    // dev->clock = speed;
    // syslog(LOG_WARNING, "spi: Selected speed reduced to max allowed speed");
    // }

    recompile it and see if you can achieve higher SPI speed.
    I suggest to report the bug also on mraa bug list there's a similar issue there

    https://github.com/intel-iot-devkit/mraa/issues/255

    Best Regards
    Nicola Lunghi

  • nukularnukular Posts: 68New Member ✭✭✭
    edited January 16

    Thanks for your help.

    Disabling the speed check worked. I will also report this on mraa as you have suggested.

    Interesting side note: I tested some speeds >10 MHz and that worked well, too. Not all of them, but that's normal I guess because of the base clock and divider that is used.
    I could get the full 25 MHz and even 50 MHz! The waveform does not really look good anymore at 50 MHz, but I don't know if that is normal at such speeds, since I have never used SPI devices at anything higher than a few MHz.
    50 MHz really seems to be the maximum, though. I also tried 100 MHz but it stayed at 50 MHz.
    25 MHz:

    50 MHz:

Sign In or Register to comment.