Receive on byte with dual SPI using LPSPI?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Receive on byte with dual SPI using LPSPI?

818 Views
gerhard_heift
Contributor I

Hello,

I try to communicate with an SPI flash memory using the LPSPI interface. I want to send a read command, its address and a dummy byte and then read exactly one byte back. I want to read the byte back using a width of 2. My problem is, as soon as I write to the TXMSK bit to the TCR, the chip clocks as many bytes int the RX FIFO until it is full. Is it possible to only clock on byte in? I have attached a minmal example below.

Thanks,

  Gerhard

int main(void) {
    /* init board etc. */

    lpspi_master_config_t config;
    LPSPI_MasterGetDefaultConfig(&config);
    LPSPI_MasterInit(LPSPI1, &config, clock);

    /* start the frame */
    LPSPI1->TCR = LPSPI_TCR_CONT(1) | LPSPI_TCR_RXMSK(1) | LPSPI_TCR_WIDTH(0) | LPSPI_TCR_FRAMESZ(8-1);

    /* send data */
    LPSPI1->TDR = 1;
    LPSPI1->TDR = 2;
    LPSPI1->TDR = 3;
    LPSPI1->TDR = 4;
    LPSPI1->TDR = 5;

    /* this prints 0 */
    PRINTF("Rx: %d\n", (LPSPI1->FSR & LPSPI_FSR_RXCOUNT_MASK) >> LPSPI_FSR_RXCOUNT_SHIFT);

    /* now I want to receive one byte over two wires (dual SPI) */
    LPSPI1->TCR = LPSPI_TCR_CONT(1) | LPSPI_TCR_CONTC(1) | LPSPI_TCR_TXMSK(1) | LPSPI_TCR_WIDTH(1) | LPSPI_TCR_FRAMESZ(8-1);

    /* wait a little bit */
    for (size_t i = 0; i < 1000000; i++);

    /* this prints 16, means the RX fifo is full, but I want to read only one byte */
    PRINTF("Rx: %d\n", (LPSPI1->FSR & LPSPI_FSR_RXCOUNT_MASK) >> LPSPI_FSR_RXCOUNT_SHIFT);
}
Labels (1)
Tags (2)
0 Kudos
1 Reply

745 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Gerhard Heift,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
According to your statement, you'd like to stall the transmit when receive one byte from the slave device after completing transmit the set of reading command, I'd like to suggest you can use the NOSTALL feature to implement it, in further, I'd also recommend you to refer to the lpspi demo projects in the SDK library.

pastedImage_1.png

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos