Using: nrf51822, SDK 10.
My application needs to use TWI0 and SPIS1 at the same time. However if I enable TWI0 and then SPIS1, when I run nrf_drv_spis_init() I get NRF_ERROR_INVALID_STATE, ie, spis_cb_t.state != NRF_DRV_STATE_UNINITIALIZED. However, as far as I understand from the doc, it should be possible to use both at the same time because they are in different base addresses/IDs.
My nrf_drv_config.h looks:
/* SPI1 */
#define SPIS1_INSTANCE_INDEX 1
#define SPI_POWER_UP_PIN 21
#define SPIS1_CONFIG_SEL_PIN 22
#define SPIS1_CONFIG_MOSI_PIN 23
#define SPIS1_CONFIG_MISO_PIN 24
#define SPIS1_CONFIG_SCK_PIN 25
#define SPIS1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPI_AUX_PIN 26
// Number of enabled SPI slaves.
#define SPIS_COUNT 1
/* TWI0 */
#define TWI0_CONFIG_FREQUENCY NRF_TWI_FREQ_100K
#define TWI0_CONFIG_SCL_PIN 7
#define TWI0_CONFIG_SDA_PIN 30
#define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TWI0_INSTANCE_INDEX 0
#define TWI_COUNT 1
The TWI0 is initialized with:
// TWI master instance with default values.
static const nrf_drv_twi_t twi_master = NRF_DRV_TWI_INSTANCE(0);
And:
nrf_drv_twi_config_t const config = {
.scl = TWI0_CONFIG_SCL_PIN,
.sda = TWI0_CONFIG_SDA_PIN,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_LOW
};
retval = nrf_drv_twi_init(&twi_master, &config, NULL, NULL);
Then the SPIS is configured with:
static const nrf_drv_spis_t slave1 = NRF_DRV_SPIS_INSTANCE(SPIS1_INSTANCE_INDEX);
static const nrf_drv_spis_config_t slave1_config =
{
.miso_pin = SPIS1_CONFIG_MISO_PIN,
.mosi_pin = SPIS1_CONFIG_MOSI_PIN,
.sck_pin = SPIS1_CONFIG_SCK_PIN,
.csn_pin = SPIS1_CONFIG_SEL_PIN,
.miso_drive = NRF_GPIO_PIN_S0S1,
.csn_pullup = NRF_GPIO_PIN_NOPULL,
.orc = 0xaa, //< ORC character.
.def = 0x55, //<< DEF character.
.mode = NRF_DRV_SPIS_MODE_0, //< CPOL = 0, CPHA = 0.
.bit_order = NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST,
.irq_priority = SPIS1_CONFIG_IRQ_PRIORITY,
};
And:
retval = nrf_drv_spis_init(&slave1, &slave1_config, &spi_event_handler);
At this point I'm kind of lost, because I'm pretty sure I'm overseeing something here, as others seemed to have been successful in using both at the same time.
So, what am I missing here?