Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: sl33k3r on Dec 17, 2013, 06:28 pm

Title: Reading byte received on MISO
Post by: sl33k3r on Dec 17, 2013, 06:28 pm
While the circuit is not completed yet, my plans are:

A 74hc597 used for input is daisy chained behind a 74hc595 for output  .  As a byte of data is sent via SPI to the 595 for output, it pushes input data out of the 597 and into MISO on the micro controller (328p).

How do i read the data received via SPI out of the micro controller?

Also, if I send more than a byte of data at a time through MISO, how do I capture data returned via MISO?  Is it all lost but the last byte? SPI does not provide a method of returning data received via MISO?
Title: Re: Reading byte received on MISO
Post by: fungus on Dec 17, 2013, 06:33 pm
SPI.transfer() returns a value...

Title: Re: Reading byte received on MISO
Post by: retrolefty on Dec 17, 2013, 06:37 pm

SPI.transfer() returns a value...




Yes, that sends a byte and receives a byte at the same time (each bit sent and received happens on the same clock edge. What the returned byte is or means depends on the device or circuit you designed.
Title: Re: Reading byte received on MISO
Post by: sl33k3r on Dec 17, 2013, 06:54 pm
Ahhhhhhh, so .......

byte dataOut = n; // n = any number 0 (b00000000/0x00) - 255 (b11111111/0xFF);
byte dataIn;
dataIn = SPI.transfer(dataOut); // sending data gets you data....like Karma  8)

Sweet, thank you so much!!!!
Title: Re: Reading byte received on MISO
Post by: retrolefty on Dec 17, 2013, 07:19 pm

Ahhhhhhh, so .......

byte dataOut = n; // n = any number 0 (b00000000/0x00) - 255 (b11111111/0xFF);
byte dataIn;
dataIn = SPI.transfer(dataOut); // sending data gets you data....like Karma  8)

Sweet, thank you so much!!!!


Yes, SPI is a sweet comm method and can be run very fast if wanted or required, It's just not 'pin effiecent' if you have multiple devices wired to the bus as each added device requires an additional SS pin. I2C is much better in muli-device setups.