AnsweredAssumed Answered

Receive on byte with dual SPI using LPSPI?

Question asked by Gerhard Heift on Sep 18, 2019
Latest reply on Sep 18, 2019 by jeremyzhou

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);
}

Outcomes