Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 3 months ago.
SPI init problem
I am trying to run the following simple code:
#include "mbed.h" int main() { DEBUG("Initializing...\r\n"); SPI device(p5, p6, p7); DEBUG("Initialized SPI master\r\n"); while(1) { wait(0.5); } }
It prints "Initializing...", but afterwards I get the LED error pattern (LED1 and LED2 turning on and off intermittently) and the second message is never printed. I am using Nordic nRF51822
Any thoughts? I tried with other pins as well.
1 Answer
10 years, 3 months ago.
Refer to: https://mbed.org/platforms/Nordic-nRF51822/ for possible SPI pins (it should also print a message that it couldn't use those pins). (P0_1 is p1 on the default nRF pinnames, etc).
Which is an example originally for another target. Those pins are simply NOT SPI pins on the NRF. You will always need to use the correct pins for your situation.
posted by 28 Aug 2014Does this restriction on SPI pins apply also to our own boards built with the nrf51822, or only the mbed kit?
I'm trying to load a .hex file compiled using mbed onto my production board which uses pins 1,2,3 for SPI, and it won't initialise. If I use software SPI (SWSPI library), it does. As far as I understand the nrf51822 hardware is capable of using any pin configuration for SPI. Does the mbed SPI implementation for the nordic chip have a software restriction on the pins that can be used?
posted by 24 Sep 2014The SPI code is here: http://mbed.org/users/mbed_official/code/mbed-src/file/c80ac197fa6a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/spi_api.c
Those names for the pins in the pinmap structure can be found in the target subfolders (http://mbed.org/users/mbed_official/code/mbed-src/file/c80ac197fa6a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822), and then the PinNames.h file. Those are possible with the mbed lib.
Now I don't have this target, but if as you say it is capable of using any pin for SPI, then the code should be pretty much completely rewritten, because currently it doesn't come close to supporting that.
However in the meantime, unless you run at very high speeds the downsides of SWSPI compared to hardware SPI are very small.
posted by 24 Sep 2014
I'm having this exact problem. We have removed everything except the pin assignment and we are using pin 5,6,7 which, according the the document (referenced in the answer below) are acceptable for SPI. Does anyone have any suggestions with this?
posted by Thaddeus Fortenberry 28 Aug 2014