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

Change Polarity of Chip Select line for SPI devices

Hi,

I would like to know the correct way to change the polarity of the CS line for SPI devices. The SHARP memory display is opposite of most SPI slave devices so I need to use the CSNPOL register so the SPI subsystem can correctly handle the line.  I have the Sharp display and an RTC on the same bus, each one requiring different polarity for its operation.

Currently I am using SDK 15.2 with the SPI manager, and am following the SPI manager example from the SDK. I would prefer it to be a part of the SPI configuration structure so I can use multiple configurations.

Any insight would be appreciated.

Thank you and happy new year!

-Ben

  • Take a look into nrfx_spim.c, you will see that the 'ss' pin (slave select) can be programmed to be active high or low. This is part of the struct spim_control_block_t declared line 116.

    To set this polarity, assuming that you are setting the 'ss' pin and using it as an integrated part of driver (it sounds like you are) then when you call the nrfx_spim_init() function with the nrfx_spim_config_t stuct you need to be setting the configuration fields as:

    nrfx_spim_config_t spim_config = {

    ...

        .ss_pin = (the pin you are using - keep this the same),

        .ss_active_high = true,

    ...

    };

    I think that should do it.

    Note to Nordic: A very nice job on the SPIM and SPIS hardware. It is very well thought out, easy to use, and DMA everywhere. This is how life should be.

  • Yes, I had seen this.  However, the SPI manager takes in the  nrf_drv_spi_config_t for its nrf_spi_mngr_init(). As far as I can tell, the init function does not recognize the .ss_active_high config element. 

    Also, from what i can tell, nrf_spi_mngr_init() calls nrf_drv_spi_init() which isnt the nrfx version.   Do I need to modify  nrf_spi_mngr.c to have it use the nrfx version?

    Thanks!

  • Oh, well. I don't know why Nordic has the SPI manager added as a layer in the first place.

    And why is it calling into legacy code in their SDK? Perhaps they will reply.

    Their motivation may be that the 'manager' code is part of their attempt to port all things for all people (like FreeRTOS?).My advice is to work with nrfx_spim.c, .h directly. And not use the 'manager'.

    A good reference is the nrf52xxx product specification. It is easy to read and helps you understand what is going on in the driver. It is in their docs/lib https://www.nordicsemi.com/DocLib under nrf52832 core documentation.

    Direct link: https://www.nordicsemi.com/-/media/DocLib/Other/Product_Spec/nRF52832PSv14.pdf?la=en

  • Hi,

    It is because SPI manager has been implemented before NRFX ;)

    It is very good idea to migrate it to NRFX, I will try to do it for next SDK release.

  • Thanks Jakub!It turns out that the ability to transmit larger datablocks is more valuable to me than the 'management' aspect.  I did have some difficulty setting up the NRFX-only version of this driver. To use SPI_INSTANCE 3, I had to set both NRFX_SPIM2_ENABLED and NRFX_SPIM3_ENABLED. Also I had to enable the legacy layer SPI_ENABLED (all of this in sdk_config.h of course)

    I took a look at the sdk_config.h for the nrfx_spim example, and all of the NRFX_SPIMx_ENABLED elements are enabled. Is the new mode of thinking for the NRFX drivers is to enable everything in the subsystem?

    Thanks! 

Related