This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use NRFX_TWIM and NRFX_SPIM together

Hi,

I have started a new project that will use I2C and SPI devices. As a starter I took the example at /examples/peripheral/gfx/pca10040 since I am using a ST7735 based TFT.

I've seen that GFX library uses nrfx_spim driver under the hood. So far everything has gone great until I try to use also nrfx_twim.

I get a compiler error for an IRQ_Handler redefinition:

/nRF5_SDK_17.0.2_d674dde/modules/nrfx/drivers/src/nrfx_twim.o: in function `SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler':

/nRF5_SDK_17.0.2_d674dde/modules/nrfx/drivers/src/nrfx_twim.c:847: multiple definition of `SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler';

/nRF5_SDK_17.0.2_d674dde/modules/nrfx/drivers/src/nrfx_spim.o: /nRF5_SDK_17.0.2_d674dde/modules/nrfx/hal/nrf_spim.h:560: first defined here

I guess TWIM defines one handler, but SPIM another.

Which is the way of being able to use both ?

  • Okay so I answer my own question.

    in /nRF5_SDK_17.0.2_d674dde/modules/nrfx/soc/nrfx_irqs_nrf52832.h

    I can see that

    SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler

    and

    SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler

    So as long as I don't define the shared resource box

    NRFX_PRS_BOX_0_ENABLED or NRFX_PRS_BOX_1_ENABLED
    I won't be able to use the peripherals that share that IRQ Handler.
    I opted to use SPI2 which has its own IRQ_Handler.
    My question now is, If I want to use 2 TWIM instances and 2 SPI instances, what is the best way to approach it ?
    I would have other SPI devices and I would like to leave just one SPI instance for the TFT only.
    What are the penalties of using NRFX_PRS_BOX vs having a dedicated IRQ_Handler per instance ?
  • Hi Pablo

    Indeed, a few peripherals use the same instances. You can see an overview here of peripherals with shared IDs in the nRF52832. As you can see, there are only 3 SPI instances in total, and two of them are shared with the TWI instances as well, so it won't be possible to use 2 SPI instances and 2 TWIM instances on the nRF52832. You will need to move to the nRF52833 or nRF52840 to do more than 2+1.

    Best regards,

    Simon

  • Hi Simon, thanks for your answer ! I'll try to make it work with 1 TWI and 2 SPI then otherwise I will consider changing to the other propposed nRFs. Cheers!

Related