Hi again, I tried to set the SPI communication where the Raspberry is the SPI Master and the dwm1001 is the SPI Slave.
This is the firmware code:
[code]#include “sdk_config.h”
#include “nrf_drv_spis.h”
#include “nrf_gpio.h”
#include “boards.h”
#include “app_error.h”
#include <string.h>
#include “nrf_log.h”
#include “nrf_log_ctrl.h”
#include “nrf_log_default_backends.h”
#define SPIS_INSTANCE 1 /< SPIS instance index. */
static const nrf_drv_spis_t spis = NRF_DRV_SPIS_INSTANCE(SPIS_INSTANCE);/< SPIS instance. */
#define TEST_STRING “Nordic”
static uint8_t m_tx_buf[] = TEST_STRING; /< TX buffer. */
static uint8_t m_rx_buf[sizeof(TEST_STRING) + 1]; /< RX buffer. */
static const uint8_t m_length = sizeof(m_tx_buf); /**< Transfer length. */
static volatile bool spis_xfer_done; /**< Flag used to indicate that SPIS instance completed the transfer. */
/**
- @brief SPIS user event handler.
-
@param event
*/
void spis_event_handler(nrf_drv_spis_event_t event)
{
if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
{
spis_xfer_done = true;
NRF_LOG_INFO(" Transfer completed. Received: %s",(uint32_t)m_rx_buf);
}
}
int main(void)
{
// Enable the constant latency sub power mode to minimize the time it takes
// for the SPIS peripheral to become active after the CSN line is asserted
// (when the CPU is in sleep mode).
NRF_POWER->TASKS_CONSTLAT = 1;
bsp_board_leds_init();
NRF_LOG_INIT(NULL);
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("SPIS example");
nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
spis_config.csn_pin = 29;
spis_config.miso_pin = 26;
spis_config.mosi_pin = 27;
spis_config.sck_pin = 28;
spis_config.mode = NRF_DRV_SPIS_MODE_1;
nrf_drv_spis_init(&spis, &spis_config, spis_event_handler);
while (1)
{
memset(m_rx_buf, 0, m_length);
spis_xfer_done = false;
nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length);
while (!spis_xfer_done)
{
__WFE();
}
NRF_LOG_FLUSH();
bsp_board_led_invert(BSP_BOARD_LED_0);
}
}
[/code]
And from Raspberry’s side I have:
[code]// spin.c
//
// Example program for bcm2835 library
// Shows how to interface with SPI to transfer a number of bytes to and from an SPI device
//
// After installing bcm2835, you can build this
// with something like:
// gcc -o spin spin.c -l bcm2835
// sudo ./spin
//
// Or you can test it before installing with:
// gcc -o spin -I …/…/src …/…/src/bcm2835.c spin.c
// sudo ./spin
#include <bcm2835.h>
#include <stdio.h>
#define PIN RPI_GPIO_P1_12
int main(int argc, char **argv)
{
if (!bcm2835_init())
{
printf(“bcm2835_init failed. Are you running as root??\n”);
return 1;
}
if (!bcm2835_spi_begin())
{
printf(“bcm2835_spi_begin failed. Are you running as root??\n”);
return 1;
}
bcm2835_spi_begin();
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_write(PIN, LOW);
//bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_DOWN);
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE1); // The default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default
bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default
// Send a byte to the slave and simultaneously read a byte back from the slave
// If you tie MISO to MOSI, you should read back what was sent
uint8_t send_data = 0x23;
uint8_t read_data = bcm2835_spi_transfer(send_data);
printf("Sent to SPI: 0x%02X. Read back from SPI: 0x%02X.\n", send_data, read_data);
bcm2835_gpio_write(PIN, HIGH);
bcm2835_spi_end();
bcm2835_close();
return 0;
}[/code]
I installed the firmware into the dwm1001 module and executed in debug mode.
Then executer the “spi” code from Raspberry.
But I cannot see any message from dwm module.
Do I made mistakes?