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

Transmitting 16 bit at once over SPI on nRF51-DK

Forgive me if this is a stupid question, but I am new to programming microcontrollers other than Arduino and SPI in general.

I have a DAC that has a 16-bit register and I need to write to it using SPI. If I try to transfer 16 bits, only the second byte is transferred. For example, if I transfer 0xAAFF, 0xFF will be transferred and the second byte transferred is always 0x05, so the payload read off my oscilloscope is 0xFF05. Even if I transfer 0x0000, the total payload transferred will be 0x0005.

Everything works as expected if I set the buffer length to 1 and only send one byte.

How can I transmit 16 bit without this 0x05 coming up?

Here is my code

uint32_t err_code;
static const nrf_drv_spi_t m_spi_master_0 = NRF_DRV_SPI_INSTANCE(0);
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = slave_select;
spi_config.miso_pin = -1;
spi_config.mosi_pin = sdo;
spi_config.sck_pin  = serial_clock;
nrf_gpio_pin_write(slave_select, LOW);
spi_config.frequency = NRF_DRV_SPI_FREQ_500K;
spi_config.mode = NRF_DRV_SPI_MODE_0;
err_code = nrf_drv_spi_init(&m_spi_master_0, &spi_config, NULL);
uint8_t test_payload = 43775; //  0xAAFF
err_code =  nrf_drv_spi_transfer(&m_spi_master_0, &test_payload, 2, NULL, 2); 
// results in 0xFF05 and err_code is NRF_SUCCESS
Related