Hi all!
I'm currently trying to communicate with the CR95HF (on the BM019) chip over SPI with the DK52 board.
I'm using SDK 15.0
According to their datasheet, the CR95HF SPI works in 3 steps:
1. send command
2. poll with 0x03 until SPI return bit 3 to 1
3. send command 0x02 to read
A Control byte is used to specify a communication type and direction:
-
0x00: Send command to the CR95HF
-
0x03: Poll the CR95HF
-
0x02: Read data from the CR95HF
-
0x01: Reset the CR95HF
The SPI_SS line is used to select a device on the common SPI bus. The SPI_SS pin isactive low.
My SPI config is as follows:
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG; spi_config.ss_pin = NRF_SPI_PIN_NOT_CONNECTED; spi_config.miso_pin = SPI_MISO_PIN; spi_config.mosi_pin = SPI_MOSI_PIN; spi_config.sck_pin = SPI_SCK_PIN; spi_config.orc = 0xFF; spi_config.mode = NRF_DRV_SPI_MODE_0; spi_config.frequency = NRF_DRV_SPI_FREQ_1M; spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST; APP_ERROR_CHECK(nrf_drv_spi_init(&m_spi_master_0, &spi_config, spi_event_handler, NULL)); nrf_gpio_pin_set(IRQ_PIN); nrf_gpio_pin_set(SPI_SS_PIN); // CR95HF Wake-Up Pulse nrf_delay_ms(10); // send a wake up nrf_gpio_pin_clear(IRQ_PIN); // pulse to put the nrf_delay_us(100); nrf_gpio_pin_set(IRQ_PIN); // mode nrf_delay_ms(10);
I know it might be overkill configuring SS manually but I'm porting code from arduino and it is done like that over there.
The corresponding arduino code of step 1 and 2 is:
// step 1 send the command digitalWrite(SSPin, LOW); SPI.transfer(0x00); // SPI control byte to send command to CR95HF SPI.transfer(0x02); // Set protocol command SPI.transfer(0x02); // length of data to follow SPI.transfer(0x01); // code for ISO/IEC 15693 SPI.transfer(0x0D); // Wait for SOF, 10% modulation, append CRC digitalWrite(SSPin, HIGH); delay(1); // step 2, poll for data ready digitalWrite(SSPin, LOW); while(RXBuffer[0] != 8) { RXBuffer[0] = SPI.transfer(0x03); // Write 3 until RXBuffer[0] = RXBuffer[0] & 0x08; // bit 3 is set } digitalWrite(SSPin, HIGH); delay(1);
So my ported code looks like this:
uint8_t invcommand[5] = {0x00, 0x02, 0x02, 0x01,0x0D};
nrf_gpio_pin_clear(SPI_SS_PIN); spi_xfer_done = false; APP_ERROR_CHECK(nrf_drv_spi_transfer(&m_spi_master_0, &invcommand, 5, m_rx_buf, 5)); while (!spi_xfer_done) { __WFE(); } nrf_gpio_pin_set(SPI_SS_PIN); nrf_delay_ms(1); nrf_gpio_pin_clear(SPI_SS_PIN); while(m_rx_buf[0] != 8) { spi_xfer_done = false; m_tx_buf[0] = 0x03; APP_ERROR_CHECK(nrf_drv_spi_transfer(&m_spi_master_0, m_tx_buf, 1, m_rx_buf, 1)); while (!spi_xfer_done) { __WFE(); } m_rx_buf[0] = m_rx_buf[0] & 0x08; } nrf_gpio_pin_set(SPI_SS_PIN); nrf_delay_ms(1);
But it never gets out of the STEP 2 while loop and the SPI keeps returning 0x06
I'm hoping to get my hands on a logic analyser and see how the signals on arduino vs DK52 look like.
As for the sdk_config.h SPI data:
NRFX_SPIM_ENABLED 1 NRFX_SPI_ENABLED 1 SPI_ENABLED 1 SPI0_ENABLED 1 SPI0_USE_EASY_DMA 1
This is strongly related to: https://devzone.nordicsemi.com/f/nordic-q-a/29253/using-the-spi-example-to-communicate-with-a-cr95hf/132887#132887