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

Parents
  • 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!

  • 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! 

  • You should not have to enable NRFX_SPIM2 to use NRFX_SPIM3, but you might have to remove the legacy config entirely from the sdk_config.h file to avoid that the NRFX config will be overwritten in the legacy layer apply_old_config.h. Please reference the sdk_config.h file in nrfx_spim example in SDK 15.2.0, where only NRFX_SPIM3_ENABLED is set.

  • Ah yes, I see. Thank you. 

    Is it possible to have 2 seperate NRFX SPI configurations exist simultaneously for the same instance?    I have 2 slave devices attached to the same SPI bus. I would like to define a specific configuration for each device ( CS Pin and CS behavior). I would prefer the CS line for each to be handled by the SPI subsystem. Is this possible?

  • Unfortunately, this is not possible with the SPI driver, and it is exactly why we have implemented the SPI transaction manager. If you are using the driver, you need to handle this manually in your application.

Reply Children
No Data
Related