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

SPI doesnot work on nRF52832

Hi,

I'm trying to use the nrf52832 as the SPI master to get read/write flash ic MX25L6433FM2I-08G(address - 0x00 to 0xFF).

In loopback case got data but when interfacing actual flash ic not get data. Got output as :

<info> app: Transfer completed.

<info> app: Received:

<info> app: FF FF FF FF FF FF FF |.......

I'm using nRF5_SDK_17.0.2_d674dde\examples\peripheral\spi\pca10040 (please find below code)

#include "nrf_drv_spi.h"
#include "app_util_platform.h"
#include "nrf_gpio.h"
#include "nrf_delay.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 SPI_INSTANCE 0 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
static volatile bool spi_xfer_done; /**< Flag used to indicate that SPI instance completed the transfer. */

#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. */

/**
* @brief SPI user event handler.
* @param event
*/
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
void * p_context)
{
spi_xfer_done = true;
NRF_LOG_INFO("Transfer completed.\r\n");
SEGGER_RTT_WriteString(0, "SPI transfer completed!\n");
if (m_rx_buf[0] != 0)
{
NRF_LOG_INFO(" Received:\r\n");
SEGGER_RTT_WriteString(0, "SPI received!\n");
NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
}
}

int main(void)
{
bsp_board_init(BSP_INIT_LEDS);

APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();

uint8_t adress=0x00; //The adress of the INFO register
uint8_t message= (adress<<1)+1; //Add the Read(1)/Write(0) command
m_tx_buf[0]=message;

nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = SPI_SS_PIN; //31 
spi_config.miso_pin = SPI_MISO_PIN; //30 
spi_config.mosi_pin = SPI_MOSI_PIN; //29
spi_config.sck_pin = SPI_SCK_PIN; //26 
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

NRF_LOG_INFO("SPI example started.");

while (1)
{
// Reset rx buffer and transfer done flag
memset(m_rx_buf, 0, m_length);
spi_xfer_done = false;

APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length));

while (!spi_xfer_done)
{
__WFE();
}

NRF_LOG_FLUSH();

bsp_board_led_invert(BSP_BOARD_LED_0);
nrf_delay_ms(200);
}
}

Kindly suggest solution as soon as possible if any. Waiting for reply

Parents Reply Children
Related