SPI revieve flag check.

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm unclear on something here. In the event the SPI does not receive data from its master, how does one know?

 

for example if I have this

 

 

unsigned char Spi_read( unsigned char data)
{
    SPDR = data;
    while(!(SPSR & (1<<SPIF)));
    return(SPDR);
}

 

and I need to wait for a 1 from the master I might do

 

if (Spi_read(1, 0xff) == 1)

{

...

}

 

 

but that is only good if the master replied with a 1 or other data. If the master does not reply I get my one back (apparently since that was put in) or that is what I see. So I almost need a if no reply SPDR =0; or return 0;
 

 

EDIT: hmm, I guess I can look at the enable line?

 

 

 

 

 

 

Last Edited: Sun. Jul 28, 2019 - 09:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don’t know if nothing is connected apart from hopefully getting a response you expect.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can you distinguish data from no data? A series of 8 1's on SPI MOSI is undistinguishable from a pin that is pulled high with a resistor. 

 

Even if the master just manages /SS and clocks the clock line to shift data out of the slave on MISO, there must still be SOMETHING on MOSI (it has to be either high or low - "nothing" is not possible). 

 

So, if you are concerned about spurious SPI messages, then YOU need to provide the error detection mechanism.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SPI is not much more than a few simultaneous shift registers forming a loop...while the master is shifting bits out, the slave is shifting them in, while shifting out its own bits to the master.  So the  master is also shifting in bits while sending out its own, just like the slave.  Master gets to determine when it all occurs & which slave (if more than one available) is to be involved.

 

In terms of what these bits particularly mean (if anything), its up the the peripheral chip designers to assign them commands, functionality, modes, etc--when it is desirable to do so for hardware purposes.

 

You could define a software command mode, such that receiving 0x6E enters burger command mode, with the following byte indicating how much ketchup to apply (say 0x00-0x2F).

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Mon. Jul 29, 2019 - 12:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

there is not.....

 

as said it is just a simple shift register that is clocked.

If you can make up your own master+slave you can say that you never want to be seeing either a 0x00 or 0xFF on the bus and if you do you have a problem, but in general there is no way to detect a missing link both MISO and MOSI are the same in that respect......one on the master side and the other on the slave.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

but in general there is no way to detect a missing link

Of course for many chips (such as I/O expander, PLL, led controller,etc) you can write some values and read back some values (such as settings)

...if the expected values (such as settings) don't appear, you can assume a problem & initiate the self-destruct sequence.

https://www.youtube.com/watch?v=oUx5JkerHZ0

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
unsigned char Spi_read( unsigned char data)
if (Spi_read(1, 0xff) == 1)

Umm I don't think so - the function definition has one parameter, the invocation has two ?!?!