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

SPI Slave problems with nRF51822

Hi, I can't get SPI slave mode working on nRF51822. I'm using the Core51822 module with a BLE400 board from Waveshare and up to date mbed. SPISlave::receive() always returns 0, no matter what I pump into SCLK. NSS is connected to GND, that shouldn't be a problem. Checked all wires, the Core51822 module does receive SCLK on P0_25. Here's my main.cpp code:

#include <mbed.h>

SPISlave spi(P0_23, P0_24, P0_25, P0_30);
DigitalOut led(P0_22);

int main(void) {
    spi.reply(0);
    while(1) {
        if(spi.receive()) {
            spi.read();
            spi.reply(0);
            led = !led;
        }
    }
    return 0;
}

If I'm right, just putting a square wave on P0_25 should make the LED blink (at of 1/8 the frequency of course), but it doesn't happen. I can run other code on the board without problem. Am I missing something? Thanks!

Parents
  • So it works now. Lessons learned:

    • On the slave side you have to call SPISlave::reply() for each transaction before receive() and read() would work.
    • On the master side you have to pulse the NSS signal for every transaction (set to low before sending and high afterwards). Just connecting it to GND will not work.
    • SPISlave::frequency() has no use. No surprise, since the clock is generated by the master.
Reply
  • So it works now. Lessons learned:

    • On the slave side you have to call SPISlave::reply() for each transaction before receive() and read() would work.
    • On the master side you have to pulse the NSS signal for every transaction (set to low before sending and high afterwards). Just connecting it to GND will not work.
    • SPISlave::frequency() has no use. No surprise, since the clock is generated by the master.
Children
No Data
Related