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

SPI master RX problem with reception

Hi,

I use SPI Master driver to communicate with a flash memory.

I use SDK 12 and i use nrf_drv_spi_transfer(...); to write and read over SPI.

My problem is the following : I write 4 bytes of command and 2 bytes of reception. I received 6bytes with the two last bytes with my answer.

So my RX buffer have some useless data.

How can i only received usefull data ?

write on spi write on spi

TX buffer init TX buffer init

SPI configuration SPI configuration

SPI handler & buffer init SPI handler & buffer init

Result of the spi write/read Result of the spi write/read

As you can see, the case 0 to 3 are useless data. I dont want it.

regards,

Parents
  • Hey Jean,

    This is a feature of the SPI protocol. SPI is a simple generic full-duplex serial protocol. There are no preamble, headers or error correction mechanisms built in. There is only a Rx buffer and a Tx buffer which is accessed one SPI word at a time, usually one byte.

    For every SPI clock cycle, one bit is transmitted from the Tx buffer, and one bit is received in the Rx buffer. The HW SPI peripheral or the SPI driver does not know that while you are transmitting, for instance, a control byte followed by a couple of address bytes, you are actually not interested in what you receive, they care only that you DO receive something, even if its 0x00.

    You will have to implement a method for reading the Rx buffer yourself. You can either get the data you want by directly accessing m_rx_buf[4] or[5], or you can create an array pointer and point to the address of m_rx_buf[4]. Then your data would start in element 0 of the array pointer.

    Cheers, Håkon

Reply
  • Hey Jean,

    This is a feature of the SPI protocol. SPI is a simple generic full-duplex serial protocol. There are no preamble, headers or error correction mechanisms built in. There is only a Rx buffer and a Tx buffer which is accessed one SPI word at a time, usually one byte.

    For every SPI clock cycle, one bit is transmitted from the Tx buffer, and one bit is received in the Rx buffer. The HW SPI peripheral or the SPI driver does not know that while you are transmitting, for instance, a control byte followed by a couple of address bytes, you are actually not interested in what you receive, they care only that you DO receive something, even if its 0x00.

    You will have to implement a method for reading the Rx buffer yourself. You can either get the data you want by directly accessing m_rx_buf[4] or[5], or you can create an array pointer and point to the address of m_rx_buf[4]. Then your data would start in element 0 of the array pointer.

    Cheers, Håkon

Children
No Data
Related