This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51 dk 16 bit spi runtime error

Hi guys I'm sending data from an nexys 4 fpga through an spi to my nRF51 (pca10028) I have the fpga set as the master and I'm able to read data sent to the nRF51 through my tera term when I have my spi.format set to (8,2)... but for some reason when I set the format to (16,2) I'm getting a runtime error. Or at least the (led1,led3) and (led2,led4) are flashing in an alternating pattern which I think is a runtime error. I have my fpga actually set to 16 bits and running on mode 2 as well so I find it odd that it's giving me this error. They also are running at the same frequency as well.

////////// Here's the simple code I have on my Nordic 

// Reply to a SPI master as slave
 
#include "mbed.h"
 
SPISlave spi(P0_16, P0_15, P0_14, P0_13); // mosi, miso, sclk, ssel
Serial pc(USBTX, USBRX);

int main() {
    
    spi.format(8,2);
    spi.frequency(100000);
    pc.baud(9600);
    spi.reply(0x00);              // Prime SPI with first reply
  
    while(1) { 
        if(spi.receive()) {
            int v = spi.read();   // Read byte from master
           // v = (v + 1) % 0x100;    
            spi.reply(v);         // Make this the next reply
       pc.printf("Received Data = 0x%X\n\r",v);
       }
    }
}

Has anyone run into something similar?

Parents
  • As mentioned, I'm not very familiar with mbed, but if you look in "/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/" in the repository you linked to you will find spi_api.c. This file contains the function definitions that are actually being used. In the function spi_format() you will find the following check:

    if (bits != 8) {
        error("Only 8bits SPI supported");
    }
    

    prohibiting you from using any other bit widths than 8 bits.

    The SPI library in mbed tries to cover many MCUs, but not all MCUs have similar SPI capabilities. Some of them support various bit widths, but unfortunately nRF51 is one of those who don't. I was not able to find this documented in the mbed drivers, but as you can see in the function definition in spi_format() you will get an error if you use something else than 8 bit.

  • Thanks for the help again. I already looked but there are no Nordic modules that support 16 bit frames correct?

Reply Children
No Data
Related