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

spi problem

Hi:

I use spi0(0x40003000) to wirte data to external flash(W25Q64) with SD8.0(sdk8.0.if I write data without sd, it is OK), and when program run to rx_data[number_of_txd_bytes]=(uint8_t)spi_base->RXD in spi_master.c.and program can't continue running normally. and if the SD make the mistake? or other reasons?

  • @jerly: I can't find this code rx_data[number_of_txd_bytes]=(uint8_t)spi_base->RXD in our spi_master.c in SDK v8.0. I dont think reading spi_base->RXD would cause any trouble. Could you attach your code ?

    spi_master.c

  • Hi Hung Bui: following the code: bool spi_master_tx_rx(uint32_t *spi_base_address, uint32_t transfer_size, const uint8_t *tx_data, uint8_t *rx_data) { uint32_t counter = 0; uint16_t number_of_txd_bytes = 0; /*lint -e{826} //Are too small pointer conversion */ NRF_SPI_Type *spi_base = (NRF_SPI_Type *)spi_base_address;

    while(number_of_txd_bytes < transfer_size)
    {
        spi_base->TXD = (uint32_t)(tx_data[number_of_txd_bytes]);
    
        /* Wait for the transaction complete or timeout (about 10ms - 20 ms) */
        while ((spi_base->EVENTS_READY == 0U) && (counter < TIMEOUT_COUNTER))
        {
            counter++;
        }
    
        if (counter == TIMEOUT_COUNTER)
        {
            /* timed out, disable slave (slave select active low) and return with error */
            return false;
        }
        else
        {   /* clear the event to be ready to receive next messages */
            spi_base->EVENTS_READY = 0U;
        }
    
    
        rx_data[number_of_txd_bytes] = (uint8_t)spi_base->RXD;
    
    
        number_of_txd_bytes++;
    };
    
    /* disable slave (slave select active low) */
    
    return true;
    

    }

  • @jerly: Are you sure you are testing with SDK 8.0 and the code is from the file spi_master.c in \components\drivers_nrf\spi_master ? I can't find the same code in my SDK 8.0.

    The code looks like it's from SDK v5.2.0 which is very old and should not be used with S110 v8.0 I attached the spi_master.c in SDK 8.0 in my answer for your reference.

  • Hi Hung Bui: yes. it is from sdk6.0.but i have used spi from sdk8.0,and the code run away when CS was pulled up.so i revised sdk6.0

  • @jerly: No, it's from SDK v5.2 not SDKv6.0. As I mentioned it's too old.

    Please let me now what's the issue you had with SDK v8.0 ? Also which chip revision are you using ? Please read the laser mark on top of the chip to find the chip revision.

Related