Hello,
I started development on a NRF52832 board couple of days ago. I want to get sensor's data via SPI (with the NRF52 as a master). However I've got weird linking issue...
C:\NRF52\nrf52-ble-battery\src\spi.cpp(47): error : undefined reference to
nrf_drv_spi_init
VisualGDB/Debug/spi.o: In function
SPI::send(unsigned char*, unsigned short)
:
C:\NRF52\nrf52-ble-battery\src\spi.cpp(97): error : undefined reference to
nrf_drv_spi_transfer
VisualGDB/Debug/spi.o: In function
SPI::recv(unsigned char*, unsigned short)
:
C:\NRF52\nrf52-ble-battery\src\spi.cpp(111): error : undefined reference to
nrf_drv_spi_transfer
#include "include/sdk_config.h"
#include "nrf_drv_common.h"
#include "nrf_drv_spi_dox_config.h"
#include "nrf_drv_spi.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "app_util_platform.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "boards.h"
#include "app_error.h"
#include "include/spi.h"
bool SPI::m_transfer_completed = false;
SPI::SPI(uint8_t id)
{
switch (id)
{
case 0:
m_spi_master = NRF_DRV_SPI_INSTANCE(0);
break;
case 1:
m_spi_master = NRF_DRV_SPI_INSTANCE(1);
break;
case 2:
m_spi_master = NRF_DRV_SPI_INSTANCE(2);
break;
default:
m_spi_master = NRF_DRV_SPI_INSTANCE(0);
break;
}
uint32_t err_code;
nrf_drv_spi_config_t config = NRF_DRV_SPI_DEFAULT_CONFIG;
config.frequency = NRF_DRV_SPI_FREQ_1M;
config.mode = NRF_DRV_SPI_MODE_3;
config.bit_order = NRF_DRV_SPI_BIT_ORDER_LSB_FIRST;
config.mosi_pin = SPIM0_MOSI_PIN;
config.miso_pin = SPIM0_MISO_PIN;
config.sck_pin = SPIM0_SCK_PIN;
config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
//err_code = nrf_drv_spi_init(&m_spi_master, &config, NULL);
err_code = nrf_drv_spi_init(&m_spi_master, &config, spi_master_event_handler);
APP_ERROR_CHECK(err_code);
}
/**@brief Function for SPI master event callback.
*
* Upon receiving an SPI transaction complete event, checks if received data are valid.
*
* @param[in] spi_master_evt SPI master driver event.
*/
void SPI::spi_master_event_handler(nrf_drv_spi_evt_t const * p_event)
{
switch (p_event->type) {
case NRF_DRV_SPI_EVENT_DONE:
// Inform application that transfer is completed.
m_transfer_completed = true;
break;
default:
// No implementation needed.
break;
}
}
uint8_t* SPI::send_recv(uint8_t * const tx_data, const uint16_t tx_len, uint8_t * rx_data, const uint16_t rx_len)
{
m_transfer_completed = false;
// Start transfer.
nrf_drv_spi_transfer(&m_spi_master,
tx_data,
tx_len,
rx_data,
rx_len);
while (!m_transfer_completed);
return rx_data;
}
void SPI::send(uint8_t * const data,
const uint16_t len)
{
m_transfer_completed = false;
// Start transfer.
nrf_drv_spi_transfer(&m_spi_master,
data,
len,
NULL,
0);
while (!m_transfer_completed);
}
void SPI::recv(uint8_t *data,
const uint16_t len)
{
m_transfer_completed = false;
// Start transfer.
nrf_drv_spi_transfer(&m_spi_master,
NULL,
0,
data,
len);
while (!m_transfer_completed);
}
I'm using VisualGDB + Visual Studio and running with the SDK12.0.
Thanks for the help.