nRF9160 Modify SPI speed when reading and writing

Hi,

I use nRF9160 SPI to drive Epson's screen, The screen MAX writing apeed is 6M,But reading apeed is only 1M,So I need to switch SPI speed between read and write。

I have tried the following methods

1、Modify spi_nrfx_spim.c at about line 115
In the function "configure(....)", comment out the "return 0" when it checks if (spi_context_configured(ctx, spi_cfg)).
So that the SPI can be forced to re-configure.

static int configure(const struct device *dev,

    const struct spi_config *spi_cfg)

{

    struct spi_context *ctx = &get_dev_data(dev)->ctx;

    const nrfx_spim_t *spim = &get_dev_config(dev)->spim;

    nrf_spim_frequency_t freq;

 

    if (spi_context_configured(ctx, spi_cfg)) {

        /* Already configured. No need to do it again. */

        //return 0;      <--------------------

    }
    .......
}

2、change the SPI frequency when calling spi_transceive() 

static struct spi_config spi_cfg = {

    .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA,

    .frequency = 4000000,

    .slave = 0,

};

bool read = true;
spi_cfg.frequency = read ? 1000000 : 6000000;
err = spi_transceive(spi_dev, &spi_cfg, &tx, &rx);

But the hardware error will be reported as bellow:

Can you help provide a demo。

Thanks!

Related