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

hardware CS not working when using BLE with nRF5340DK

Hello,

I'm using NCS 1.4.99 with a nRF5340DK and want to use the hardware CS of the SPI and also use BLE.

Here is a simple code that work on a nRF5340PDK but only work on a nRF5340DK when CONFIG_BT is not defined.

/* Includes ------------------------------------------------------------------*/

#include <assert.h>
#include <stdint.h>

#include <nrfx_spim.h>

/* Private define ------------------------------------------------------------*/

#define SPI_TRANSFER_SIZE 2
#define TX_DATA 0x1234

#define SCLK_PIN NRF_GPIO_PIN_MAP(1, 5)
#define MOSI_PIN NRF_GPIO_PIN_MAP(1, 4)
#define MISO_PIN NRF_GPIO_PIN_MAP(1, 6)
#define CSN_PIN  NRF_GPIO_PIN_MAP(1, 1)

/* Private variables ---------------------------------------------------------*/

static uint8_t rx_buffer[SPI_TRANSFER_SIZE];
static uint8_t tx_buffer[SPI_TRANSFER_SIZE];

static const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(4);
static const nrfx_spim_xfer_desc_t xfer = NRFX_SPIM_XFER_TRX(tx_buffer, SPI_TRANSFER_SIZE, rx_buffer, SPI_TRANSFER_SIZE);

/* Public functions ----------------------------------------------------------*/

void main(void)
{
    nrfx_err_t err_code;

    nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG(
            SCLK_PIN,
            MOSI_PIN,
            MISO_PIN,
            NRFX_SPIM_PIN_NOT_USED);
    spi_config.frequency = NRF_SPIM_FREQ_8M;
    spi_config.mode = NRF_SPIM_MODE_0;

    err_code = nrfx_spim_init(&spi, &spi_config, NULL, NULL);
    assert(err_code == NRFX_SUCCESS);
    spi.p_reg->PSEL.CSN = CSN_PIN; // workaround, if set in spi_config, the CS pin is set/clear by software

    tx_buffer[0] = (TX_DATA >> 8) & 0xFF;
    tx_buffer[1] = TX_DATA & 0xFF;

    while(1) {
        nrfx_spim_xfer(&spi, &xfer, NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER);
    }
}
7077.prj.conf.

Parents
  • Hi,

    I tested your code and I see that the CS pin toggles as expected when CONFIG_BT is set to n but not when set to y. I am not able to explain this right now though so I need to get back to you tomorrow.

    Edit: I just noticed that this issue only occurs when building for secure mode (nrf5340dk_nrf5340_cpuapp). Building for non-secure (nrf5340dk_nrf5340_cpuappns) CS works as expected.

Reply
  • Hi,

    I tested your code and I see that the CS pin toggles as expected when CONFIG_BT is set to n but not when set to y. I am not able to explain this right now though so I need to get back to you tomorrow.

    Edit: I just noticed that this issue only occurs when building for secure mode (nrf5340dk_nrf5340_cpuapp). Building for non-secure (nrf5340dk_nrf5340_cpuappns) CS works as expected.

Children
Related