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

Slower SPI working on all GPIO pins?

I am interfacing nrf52840DK to a SPI module soldered by myself on a custom PCB adapter, connected by wires. This is the init code:

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = SPI_SS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    spi_config.mode = NRF_DRV_SPI_MODE_1;
    spi_config.frequency=NRF_DRV_SPI_FREQ_125K;

    // blocking mode
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL));

I have two issues with the default spi driver from Nordic (the one working with function nrf_drv_spi_transfer):

1. I'm using FREQ_125K but it still seems too fast (responses from slave doesn't contain expected data) and I can't find a way to decrease frequency lower than 125Kbps, given that it can only be one of these:

typedef enum
{
NRF_DRV_SPI_FREQ_125K = NRF_SPI_FREQ_125K, ///< 125 kbps.
NRF_DRV_SPI_FREQ_250K = NRF_SPI_FREQ_250K, ///< 250 kbps.
NRF_DRV_SPI_FREQ_500K = NRF_SPI_FREQ_500K, ///< 500 kbps.
NRF_DRV_SPI_FREQ_1M = NRF_SPI_FREQ_1M, ///< 1 Mbps.
NRF_DRV_SPI_FREQ_2M = NRF_SPI_FREQ_2M, ///< 2 Mbps.
NRF_DRV_SPI_FREQ_4M = NRF_SPI_FREQ_4M, ///< 4 Mbps.
NRF_DRV_SPI_FREQ_8M = NRF_SPI_FREQ_8M ///< 8 Mbps.
} nrf_drv_spi_frequency_t;

2. I can't use other GPIO pins to work as CSN,SCK,MISO and MOSI

How can I decrease speed lower than 125kbps?

How can I use other GPIO pins?

Do I need a software spi implementation?

Can you suggest a one working with nrf52?

Thank you in advance!

Parents
  • What is the SPI slave?

    it still seems too fast (responses from slave doesn't contain expected data)

    There are plenty of other things - apart from speed - which could cause that.

    What do the slave specifications say about speed, and any other timing requirements?

    Are you sure that your expectations are correct?

    Have you looked at the wires with a scope to confirm that the signals are OK ?

    EDIT

    Also:

    SPI module soldered by myself

    Are you sure your soldering is all good and correct, and the connections are correct, and nothing has been damaged in the process?

    These kinds of things are where the scope test comes in ...

  • The slave accepts maximum speed of 10Mhz, but there is no minimum speed declared.

    The slave is a SPI mode 1 (CPOL=0, CPHA=0)

    I'm trying to read R/W registers after writing, even after some time, but there is not the value sent.

    The response for a same register is always the same, does not change, but it is isn't neither the default value, neither the written value. So I thought to a SPI problem.

    Checking with a scope on MOSI I can see correct bits are sent to the connector soldered on the custom PCB adapter where module is soldered. PCB adapter traces have 0.25mm width. Is it enough?

    Checking MISO with a scope at connector soldered on PCB adapter, bits are the same for the same registers, but they are neither the default value expected after module reset, neither the written value after spi_write register operation.

    So I was thinking to decrease speed.

    In any case I need spi on different gpio pins from Hardware SPI pins.. 

    EDIT: Yes, I checked with multimeter that all pins are connected and no short circuits are present.

    EDIT2: I tried with 3 modules of the same type soldered on different version of a same PCB adapter: same behaviour

  • You still haven't said what this mystery device is!

    The slave accepts maximum speed of 10Mhz

    So speed should not be an issue!

    Again, are there any other timing requirements; eg, time from asserting SS to clock starting? time between reads/writes? etc ...

    I'm trying to read R/W registers after writing

    Is that valid?

    Not all registers will necessarily read-back what was written to them.

    Have you checked the manufacturer's documentation and examples?

    different gpio pins from Hardware SPI pins

    There are no "Hardware SPI pins"; the functions can be configured to any pin - see the Product Specification.

  • Opps sorry.

    module is this: 

    https://www.st.com/en/wireless-transceivers-mcus-and-modules/spsgrf.html 

    Datasheet of IC with serial specification is here:

    https://www.st.com/en/wireless-transceivers-mcus-and-modules/spirit1.html

    Is that valid?

    I'm trying with R/W registers. Given the name, I assumed I can read back what I have just written. In any case even the default value after reset can't be read correctly.

    Again, are there any other timing requirements; eg, time from asserting SS to clock starting? time between reads/writes? etc ...

    Do you know of other spi parameters that I can change in nrf52 spi drivers, besides frequency and spi_mode?

    There are no "Hardware SPI pins"; the functions can be configured to any pin - see the Product Specification.

    Ok great, thanks a lot!

  • Given the name, I assumed I can read back what I have just written

    No, that's not a valid assumption: "R/W" just indicates that both read and write are possible - not (necessarily) that a read after a write will read-back what you just wrote.

    You need to check that specifically in the documentation.

    Do you know of other spi parameters that I can change in nrf52 spi drivers

    Not off-hand, but that's not the point - the point is, does the slave require it ... ?

Reply
  • Given the name, I assumed I can read back what I have just written

    No, that's not a valid assumption: "R/W" just indicates that both read and write are possible - not (necessarily) that a read after a write will read-back what you just wrote.

    You need to check that specifically in the documentation.

    Do you know of other spi parameters that I can change in nrf52 spi drivers

    Not off-hand, but that's not the point - the point is, does the slave require it ... ?

Children
  • Datasheet says timing requirements are only 2: 

    - SCLK frequency: max 10 MHz

    - CSn low to positive edge on SCLK: min 2 μs

    Also documentation says:

    There are three types of registers:
    • Read and write (R/W), which can be completely managed by SPI using READ and
    WRITE operations
    • Read-only (R)
    • Read-and-reset (RR), is automatically cleared after a READ operation.

    There is no mention of "read after writing" :(

Related