Hello all,
I try to send a command to read device ID (0x9F) of a micron memory device (N25Q064A) using SPI protocol. I have the following hardware configuration :
NRF_SPI_CLK --> N25_CLOCK
NRF_SPI_MOSI --> N25_DQ0
N52_SPI_MISO <----------- N25_DQ1
N52_SPI_SS <----------- N25_SS
N25 is set in the high impedance (set as input + no pull up ). And there is my code:
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#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>
#define NRF_LOG_MODULE_NAME "APP"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nordic_common.h"
#include "app_uart.h"
#define INT_DQ3 24
#define INT_DQ2 20
#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. */
#define SPI_TEST_MOSI_PIN 22
#define SPI_TEST_MISO_PIN 19
#define SPI_TEST_SCK_PIN 23
/**
* @brief SPI user event handler.
* @param event
*/
void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
{
spi_xfer_done = true;
NRF_LOG_INFO("Transfer completed.\r\n");
if (m_rx_buf[0] != 0)
{
NRF_LOG_INFO(" Received: \r\n");
NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
}
}
void initSPI()
{
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.frequency = NRF_DRV_SPI_FREQ_8M ;
spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi_config.miso_pin = SPI_TEST_MISO_PIN;
spi_config.mosi_pin = SPI_TEST_MOSI_PIN;
spi_config.sck_pin = SPI_TEST_SCK_PIN;
nrf_drv_spi_init(&spi, &spi_config, spi_event_handler);
}
int main(void)
{
NRF_LOG_INFO("SPI example\r\n");
initSPI();
nrf_gpio_cfg_output(INT_DQ3);
nrf_gpio_pin_set(INT_DQ3);
nrf_gpio_cfg_input(INT_DQ2, NRF_GPIO_PIN_NOPULL);
uint8_t tx_read[1] = {0x03};
while (1)
{
// Reset rx buffer and transfer done flag
memset(m_rx_buf, 0, m_length);
spi_xfer_done = false;
nrf_drv_spi_transfer(&spi, tx_read, 1, m_rx_buf,20);
nrf_delay_ms(1);
while (!spi_xfer_done)
{
__WFE();
}
NRF_LOG_FLUSH();
}
}