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

SPI example code for nRF51822 Eval Kit

Hi, I tried uploading the example code from \nrf6310\spi_master_example to nRF51822 evaluation kit board, but no matter what I do, I always get SPI error. Not compile or upload code error, but the actual SPI error.

I've set the ERROR_PIN_SPI0 to LED0 and ERROR_PIN_SPI0 to LED1, and both LED turns on when I run the code, which leads me to believe that the code is successfully compiled and uploaded, but the SPI is not working.

I've already changed the pin numbers on the spi_master_config.h for SS, MISO, MOSI and CLK to match the pins that connect to my SPI device (in my case, it's ADXL362 accelerometer, made by Analog Devices)

Also, I find it strange that there isn't any code for PCA10001 board regarding SPI. This makes me wonder if the code in \nrf6310\spi_master_example is actually usable or not for eval kit.

  • Hi,

    The spi_master_example in the SDK is a loopback example, meaning that it will send a sequence of data and expect the same data in return. If it does not receive the same data in return, it will return false and set the error LED. There's another SPI master example (spi_master_example_with_spi_slave) that works with the SPI Slave example in the SDK, if that is of interest.

    The SPI-examples will not work out-of-the-box with that sensor. You'll have to map up the register definitions for your specific accelerometer and use the SPI init/send/receive functions to communicate with the external sensor, as we do not have any examples for that specific accelerometer.

    Best regards Håkon

  • I see, I'm currently using that example code (spi_master_example_with_spi_slave). However, my RXD always returns zero even though it was supposed to read a register with value of non-zero.

    I've made sure to read the accelerometer datasheet (if you are interested here's the link: www.analog.com/.../ADXL362.pdf, page 19 onwards)

    I've also made sure that I'm using the correct SPI Mode, correct clock, correct pin numbers and tried reversing the bits, but to no avail. I'm truly confused now, because I strongly believe this code should work, unless there is something else I need to do in that example code that I need to change to enable RXD to receive data? I don't think the component is broken either, although there is no indicator or such, so it is a hard to say in that regard.

    Here is my code, if you don't mind checking: SPI Accel.zip

  • Hi David,

    1. If you're using the eval-kit, the pins 8/9/10/11 are connected directly to the SEGGER chip, and it will drive some those lines high. Try changing them to other GPIOs.

    2. You're using printf. Have you mapped printf to something? If not, it will crash the program.

    3. Have you tried scoping the SPI lines to see if the data going over the bus is sensible?

    4. It is good practice to never let a embedded program return from main. add a while(1) in main.

  • Hi, How you configured SPI master to use ADXL362? i use \pca10001 example but i have an error if i take a SPI master example files from /nrf6310

Related