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?

Parents
  • @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;
    

    }

Reply
  • 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;
    

    }

Children
No Data
Related