SPI usage questions

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

Hi all,

 

I am using 2 atmeaga 324pa chips connected together via SPI. Micro A is the master and micro B is the slave.  Previously i have only used Micro to an SPI temp chip and requested data from the slave device, never micro to micro.

 

I would like to read the device connected to micro B every 1 second and communicate this data to micro A over SPI, but i have a question on what is the best practice to read the slave device.  I have a couple of questions below:

 

1) Can i put master micro A in constant receive mode, and just send data from slave micro B every 1 second.  Micro A would received data similar to a UART and fire and interrupt?

 

2) Or should the master micro A request data from slave micro B every 1 second, because the SPI will only receive a byte on the MISO if a byte is clocked out on the MOSI?  

 

Look forward to your reply.

 

Thanks,

 

Tuurbo46

 

 

 

 

 

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

Best bet is to define some kind of protocol where the master says some kind of "give the data" command and then the slave sees this as a "get SPDR ready with the value to return". So the master runs the timer and when he's ready he sends something like 0x01 to me "about to read". The slave then gets the latest reading, puts it in SPDR and then the master initiates another byte exchange by sending 0xFF (or something) simply to "clock out" the actual reading the slave now has ready for him.  But a word of warning maybe don't just do spi_xchg(0x01);retval = spi_xchg(0xFF); like this as the slave may need a short time to recognize and respond to the 0x01 "command".

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

Maybe you have chosen the master incorrectly?  Sounds like

micro B should be the master in this setup.

 

--Mike