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

SPI Master initialization with BLE

Hi,

I've been trying to implement a SPI master module in the example ble_app_hrs_c_s120 on the nRF51 DK with nRF51422 (I copied the code of the example of spi_master in the BLE example).

It compiles without error nor warnings but doesn't work. After debugging, I found out that it's the configuration of the SPIM that causes a HardFault at the exact line :

// Configure SPI master.
spi_master_config_t spi_config = SPI_MASTER_INIT_DEFAULT;

The symbol is defined as :

#define SPI_MASTER_INIT_DEFAULT                                             \
{                                                                           \
    SPI_FREQUENCY_FREQUENCY_M1, /**< Serial clock frequency 1 Mbps. */      \
    SPI_PIN_DISCONNECTED,       /**< SCK pin DISCONNECTED. */               \
    SPI_PIN_DISCONNECTED,       /**< MISO pin DISCONNECTED. */              \
    SPI_PIN_DISCONNECTED,       /**< MOSI pin DISCONNECTED. */              \
    SPI_PIN_DISCONNECTED,       /**< Slave select pin DISCONNECTED. */      \
    APP_IRQ_PRIORITY_LOW,       /**< Interrupt priority LOW. */             \
    SPI_CONFIG_ORDER_LsbFirst,  /**< Bits order LSB. */                     \
    SPI_CONFIG_CPOL_ActiveHigh, /**< Serial clock polarity ACTIVEHIGH. */   \
    SPI_CONFIG_CPHA_Leading,    /**< Serial clock phase LEADING. */         \
    0                           /**< Don't disable all IRQs. */             \
};

I really can't figure out why it doesn't find the symbol. It's defined in spi_master.h that I included in the main.

The SD S120 is downloaded on the board and I use uvision 5.14 with the SDK 8.0.

Do you have any idea?

Thank you so much for your help, I'm stuck.

Yann

  • edit your question and in that you get an option to attach files, you can attach your project there as a zip file. I made you wait for three days, i could wait for few hours ;)

  • Please find the project in my reply to this question from Jun 17.

  • This question is confusing because you're talking about two different issues and you've given the impression they are the same but I think they aren't. Firstly, as far as I can tell, the one you've discussed most is the crash on the sd_nvic_EnableIRQ() function inside the init. And that crash only occurs if you put the spi_master_open() before the ble_stack_init(). It's obviously going to crash if you do that because you can't call sd_* functions before you initialise the softdevice.

    If, by the way, you'd answered this question which Aryan asked

    can you check what is the error returned by sd_nvic_ClearPending?

    and told him the answer was '2' he could have told you that. 2 is NRF_ERROR_SOFTDEVICE_NOT_ENABLED. You just told him you'd checked the IRQ, which wasn't what he asked. The documentation gives the API-specific error codes, any SD function can also return a generic SD error code.

    Then it seems you have another error later when calling the send_recv() function. But you don't say what it is. The implication is that it's the same error but I rather doubt that. So what's that error, is it an error returned from a function, an APP_ERROR_CHECK() error, a hardfault, what is the actual error there?

    Ignoring for now that the spi code doesn't do anything useful, just receives a byte into a location in stack memory and then throws it away again and the wisdom of waiting synchronously for the SPI master to write in the middle of a timer timeout.

Related