I am unable to activate the 4-wire QSPI of NRF52840

I used an oscilloscope to check the waveform and found that only the clock and IO0 had waveforms. I am using this interface to send data: 

nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer,
                           size_t       tx_buffer_length,
                           uint32_t     dst_address);
After initialization is complete, this interface call does not seem to take effect: 
nrf_qspi_ifconfig0_set();
Here is my code:
#include "qspi_app.h"
#include "nrf_gpio.h"
#include "app_error.h"
#include "nrfx_qspi.h"
#include "nrf_drv_qspi.h"
#include "all_file_header.h"
#include "nrf_qspi.h"
#include "nrf52840_bitfields.h"
#include "nrf52840.h"

uint8_t send_flag = 0;

void qspi_app_cb(nrfx_qspi_evt_t event, void *p_context)
{
    send_flag = 0;
    LOG(".\n");
}
/**
 * 配置QSPI的线模式
 */
static void qspi_app_config_line_mode(uint8_t mode)
{
    nrf_qspi_prot_conf_t prot_if = {0};

    prot_if.addrmode = NRF_QSPI_ADDRMODE_24BIT;
    prot_if.dpmconfig = false;

    if (mode == 1)
    {
        prot_if.readoc = NRF_QSPI_READOC_FASTREAD; // 单线读取
        prot_if.writeoc = NRF_QSPI_WRITEOC_PP;     // 单线写入
    }
    else if (mode == 4)
    {
        prot_if.readoc = NRF_QSPI_READOC_READ4O; // 单线读取
        prot_if.writeoc = NRF_QSPI_WRITEOC_PP4O; // 四线写入
    }
    nrf_qspi_ifconfig0_set(NRF_QSPI, &prot_if);

}

void qspi_app_hal_init(void)
{

    uint32_t err_code;
    nrf_drv_qspi_config_t qspi_lcd_config = NRF_DRV_QSPI_DEFAULT_CONFIG;

    qspi_lcd_config.phy_if.sck_freq = NRF_QSPI_FREQ_32MDIV16; // NRF_QSPI_FREQ_32MDIV8; //32MHz

    qspi_lcd_config.pins.csn_pin = DVC_QSPI_PIN_CS;
    qspi_lcd_config.pins.sck_pin = DVC_QSPI_PIN_CLK;
    qspi_lcd_config.pins.io0_pin = DVC_QSPI_PIN_D0;
    qspi_lcd_config.pins.io1_pin = DVC_QSPI_PIN_D1;
    qspi_lcd_config.pins.io2_pin = DVC_QSPI_PIN_D2;
    qspi_lcd_config.pins.io3_pin = DVC_QSPI_PIN_D3;

    qspi_lcd_config.prot_if.readoc = NRF_QSPI_READOC_READ4O;    // 单线读取
    qspi_lcd_config.prot_if.writeoc = NRF_QSPI_WRITEOC_PP4O;    // 单线写入
    qspi_lcd_config.prot_if.addrmode = NRF_QSPI_ADDRMODE_24BIT; // 根据CO5300调整
    qspi_lcd_config.prot_if.dpmconfig = false;

    qspi_lcd_config.phy_if.sck_delay = (uint8_t)40; // 100*62.5ns=6.25us

    qspi_lcd_config.irq_priority = APP_IRQ_PRIORITY_LOW_MID;

    err_code = nrf_drv_qspi_init(&qspi_lcd_config, qspi_app_cb, NULL);
    if (err_code != 0)
    {
        LOG("QSPI LCD Init Err\n");
    }

    LOG("QSPI LCD Init\n");
}

uint32_t qspi_app_writeCmd(uint8_t instruction, uint8_t address, uint8_t *param, uint16_t plen)
{

    uint8_t data[8] = {0};

    data[0] = 0x00; // 占位
    data[1] = address;
    data[2] = 0x00; // 占位

    nrf_qspi_cinstr_conf_t config = {
        .opcode = (instruction),
        .length = (NRF_QSPI_CINSTR_LEN_4B), /*opcode + byte0->byte2  = 4byte*/
        .io2_level = false,
        .io3_level = false,
        .wipwait = false,
        .wren = false}; /*先写入使能指令,必须关闭*/

    config.length = (nrf_qspi_cinstr_len_t)(NRF_QSPI_CINSTR_LEN_4B + plen); /*opcode + byte0->byte2 + param*/

    if (plen > 0 && param != NULL)
    {
        memcpy(&data[3], param, plen);
    }

    qspi_app_config_line_mode(1); // 单线模式

    uint32_t rtn = nrfx_qspi_cinstr_xfer(&config, data, NULL);

    return rtn;
}

uint32_t qspi_app_write_buffer(uint8_t *p_tx_buffer, uint32_t len, uint8_t address)
{
#if 0
    uint8_t data[8] = {0};

    data[0] = 0x00; // 占位
    data[1] = address;
    data[2] = 0x00; // 占位

    nrf_qspi_cinstr_conf_t config = {
        .opcode = (0x02),
        .length = (NRF_QSPI_CINSTR_LEN_1B), /*opcode + byte0->byte2  = 4byte*/
        .io2_level = false,
        .io3_level = false,
        .wipwait = false,
        .wren = false}; /*先写入使能指令,必须关闭*/

    // qspi_app_config_line_mode(4);

    nrfx_qspi_lfm_start(&config);

    uint32_t rtn = nrfx_qspi_lfm_xfer((void const *)data, NULL, 3, false);

    nrfx_qspi_lfm_xfer((void const *)p_tx_buffer, NULL, len, true);

#else
    uint32_t qspi_addr = 0;

    qspi_addr = address;
    qspi_addr <<= 8;

    qspi_app_config_line_mode(4);

    uint32_t rtn = nrfx_qspi_write((void const *)p_tx_buffer, len, qspi_addr);
#endif

    return rtn;
}
I hope someone can help me, thank you
Parents Reply Children
Related