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

How does the chip know if I'm sending or receiving data using spi_send_recv?

Hi, I want to know how to properly indicate for the function

spi_send_recv(...)

that I'm sending or receiving data on SPI.

On other platforms with library function/SDK, it's done by setting unused buffer to NULL. For example if I want to send data then the receiving buffer of the function is set to NULL and vice versa.

But with this function, I can't seem to do that, if I set for example the receiving buffer to NULL when trying to send certain data the program freeze and crash into error handling.

How to do that? Am I doing it right by setting unused buffer to zero but messed up somewhere else which caused the program to crash (which it isn't supposed to)?

Also, a side note: I did not use the event handler for SPI, in other words, at initialization and configuration phase, I set the event handler for SPI to NULL, which could be problematic.

  • For a start - what SDK are you using because nothing I have (12,13 and 14) even have an spi_send_recv()? Have you looked at the code, does it allow for a null buffer?

    This is SPI so you are always both sending AND receiving, that's the whole point of SPI, one byte comes in for every byte which goes out, so it's not necessarily true that the driver would be written to allow you to do only one.

    Read the code. If the code crashes into error handling, debug it and see what caused it to get there. You have all the code and all the tools to work out why it crashes.

  • Hello, you are absolutely right. The whole point of SPI is to constantly sending and reciving with 1 line of clock signal, I've fixed it, as long as you send the right sequence of 1s and 0s, the output cache will always get the correct result.

    Much obliged.

Related