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

Two SPI interfaces, compilation error

Hi,


I have the same issue as in here: https://devzone.nordicsemi.com/f/nordic-q-a/62676/2-spi-devices-nordic-nrf52382
but for me the Debug/Release-toggle does not work.

I use SDK 15.3 and Softdevice s132 with a BC832. I try to connect (in the end 3 but for now) 2 SPI devices to the BC832. Since they might send data simultaneously and I don't need the GPIO pins otherwise, I would prefer having an interface for each of them and other threads mention that it is possible.

Segger Embedded Studio (V4.52) gives this error:
‘NRF_DRV_SPI_INSTANCE_1’ undeclared here (not in a function); did you mean ‘NRF_DRV_SPI_INSTANCE_0’?
in nrf_drv_spi.h in line 120 (which reads: "#define NRF_DRV_SPI_INSTANCE_(id)   NRF_DRV_SPI_INSTANCE_ ## id")
whenever I add the second SPI instance. (I have not tried the third yet.)

code used:

#define SPI_INSTANCE_0  0
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE_0);  /**< SPI instance. */
#define SPI_INSTANCE_1  1
static const nrf_drv_spi_t spi1 = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE_1);  /**< SPI instance. */


SPI0_ENABLED, SPI1_ENABLED and SPI2_ENABLED are all set to 1. see config file: sdk_config.h

what am I doing wrong? Appreciate any suggestions/help.

(btw, if I only use SPI_INSTANCE_0 and set it to 1 or 2 and comment out the last two lines of the code above, it of cause gives the same error!)

Parents
  • Hello,

    The code snippet you included above looks all right for the purpose of creating SPI instances.

    I would prefer having an interface for each of them and other threads mention that it is possible.

    Yes, this is fine, however you will also need to make sure that you are not already using some of the SPI's shared resources someplace else in your code.

    whenever I add the second SPI instance. (I have not tried the third yet.)

    Does it work as expected when you only have 1 SPI instance, and does it change depending on which SPI instance that single instance is?

    As a side note, I would like to recommend that you use the nrfx_spim or nrfx_spis drivers directly since it seems you are intending to make use of the easyDMA feature, instead of the legacy nrf_drv SPI driver.
    If you intend to use the SPIM as demonstrated in the SPI peripheral example from the SDK, then you will need to define NRFX_SPI0_ENABLED and NRFX_SPI1_ENABLED to 1 as well.

    Looking forward to resolving this issue together,

    Best regards,
    Karl

  • Hi,

    thanks for your quick reply.


    it works, if I only use one instance and it works (separately) with all three GPIO-pinnings I want to use. However it only works with SPI_INSTANCE set to 0. As described, if I change that to 1 or 2, even if only instantiating one SPI instance, it causes the error.

    Thank you for the easyDMA hint. However, the use of easyDMA seemed to work just fine with SPI_INSTANCE == 0, SPI0_USE_EASY_DMA == 1 and NRFX_SPI0_ENABLED == 0 (and NRFX_SPI_ENABLED == 1). SPIM was disabled for all instances while doing so. (The configuration described here is the one I provided above.)

    Maybe it helps, if I provide a minimal not-working example?

    best wishes

  • Hello,

    OS Na said:
    thanks for your quick reply.

    It is no problem at all, I am happy to help!

    OS Na said:
    Thank you for the easyDMA hint. However, the use of easyDMA seemed to work just fine with SPI_INSTANCE == 0, SPI0_USE_EASY_DMA == 1 and NRFX_SPI0_ENABLED == 0 (and NRFX_SPI_ENABLED == 1). SPIM was disabled for all instances while doing so. (The configuration described here is the one I provided above.)

    Yes, if you are using the legacy spi driver with the easyDMA option set, then it will use the SPIM functionaltiy. You could see line 859 of apply_old_config for how this happens.
    The apply_old_config override of sdk_config is known to cause some confusion, but it is implemented to provide backwards compatibility.

    OS Na said:
    Maybe it helps, if I provide a minimal not-working example?

    Yes, that would be very helpful to have a look at, so that I may see how you are doing the configuration.
    Please provide a .zip file of the entire project directory you are working with. Bear in mind that I do not have a BC832 module at hand to test with, so I will work with a nRF52 DK instead.
    Since this is a compilation issue this should not matter for now.

    I may also set the case to private viewing mode so that it is only viewable to you yourself and the support staff here at Nordic, in the case that the code is sensitive - just let me know if you would like me to do this.

    Best regards,
    Karl

  • Hi,

    i prepared an example that should be free of sensitive matters, so it's fine (even took out the BLE stuff for readability). But thank you. If you really need my complete project I will come back to that offer. Figuring out what is going on should also work on this one here, though.

    When compiled, it throws the above mentioned error. If one comments out lines 150 and 151 of the main.c, then it compiles without complaining. If line 148 is set to '1' or '2' in the end, it also throws the error.

    file:nordicUpload.zip

    Let me know if you need (to know) anything else.

    best wishes

  • Hello again,

    I took a look at the project you provided, and "unfortunately" it compiled just fine in both Release and Debug configuration - without making any changes to it ( both SPI instances defined and instanciated )..
    I am also able to init both the instances, by duplicating the configuration provided and changing it to what I would assume is the SPI1 config.
    Adding the third instance is not a problem either, it compiles as expected without errors or warnings.

    Could you download the project you provided and see if you still get the error, when the project is placed in /SDK15.3/examples/peripheral/nordicUpload
    If you are seeing an error here, I would suggest that you re-download the SDK to make sure you are not working with a broken / modified SDK.

    Looking over your sdk_config it also seems appropriately configured for using the legacy SPI driver with easyDMA ( actually using the nrfx_spim driver ).
    I do not immediately see anything that needs re configuring here, intriguing!

    I look forward to hearing back from you regarding the test of the project you yourself provided.

    Best regards,
    Karl

  • Hi,

    redownloading the SDK resolved the issue and also the original project compiles with several SPI instances. Thank you very much for the tip!

    best wishes

    (and sorry for the long silence, was on vacation)

Reply Children
  • Hello,

    OS Na said:
    (and sorry for the long silence, was on vacation)

    No problem at all!  

    OS Na said:
    redownloading the SDK resolved the issue and also the original project compiles with several SPI instances. Thank you very much for the tip!

    I am happy to hear that this resolved your issue.
    To avoid this issue in the future, please make sure that you are not modifying the SDK files directly, but rather making renamed copies of the files you would like to change, and adding them to a separate location in your project directory. This way, it will also be easier for someone else to familiarize with your code in the future.

    I hope you had a great vacation, and that you are well!

    Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.

    Best regards,
    Karl

Related