This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How spi communication is done

1. Suppose i am having a spi master and spi slave (both are lpc2468 based)what is the procedure to read some bytes from a particular address of spi slave i.e what we all need to do like send some commands, data, some opcodes. how is request sent to read particular number of bytes

2.I went trough arduino website (arduino.cc/.../SPIEEPROM) and studied about spi communication between master and eeprom acting as slave.I came across opcodes over there but i was not able to understand what basically opcodes are and what is there significance.

  • If communicating between two processors, then it's up to you to invent a protocol.

    Just remember that the slave can only send the data to the master if the master is at the same time sending data to the slave. So it's common to invent a "NULL" word that the master can send out a number of when retrieving the answer to a query.

    So the master might send a fictive query by activating the slave-select line on the intended target and then send:

    0x01 = READ
    0x06 = 6 BYTES
    0x01,0x00 = FROM Adress 0x0100 = 256

    Then it has to send 6 NULL bytes - let's assume 0xFF - to clock out the 6 bytes of answer from the slave:
    0xFF
    0xFF
    0xFF
    0xFF
    0xFF
    0xFF

    The slave on the other hand will synchronize the SPI device when the slave select line got activated.
    But since it doesn't know what is expected from it, it will have to send out "null" characters - 0xFF - while it receives the read request (0x01, 0x06, 0x01, 0x00).

    0xFF
    0xFF
    0xFF
    0xFF

    After that it will have figured out that it received a read request, how much data to respond with and what data that was requested.
    Then it can prepare the requested 6 bytes of data and send out.
    0x48 'H'
    0x45 'E'
    0x4C 'L'
    0x4C 'L'
    0x4F 'O'
    0x21 '!'

    So the master sends
    0x01 0x06 0x01 0x00 0xff 0xff 0xff 0xff 0xff 0xff
    and receives
    0xff 0xff 0xff 0xff 0x48 0x45 0x4c 0x4c 0x4f 0x21

    The slave decodes the first 4 bytes received and then throws away the next 6 that are just fillers.
    The master throws away the first 4 bytes received and then then pick up the following 6 that represents the answer to the read request.

    If looking at code that talks with a EEPROM, you need to retrieve the datasheet for the EEPROM, so you can read up on the protocol it supports. How many bits each transfer is (SPI isn't limited to 8-bit characters but might just as well send 12-bit or 16-bit words) and how read and write commands are defined. You need this information when reading the microcontroller code that performs the reads and writes.

  • Thanks sir. I just wanted the same information as provided by u. Thanks a lot

  • @Per Westermark sir can u please give similar explaination for i2c. that how communication is started and what the master need to send to devices for communication as you explained for spi.it helped me a lot

  • Can I take it that you don't much like books or using Google?

  • sir the thing which u told me in case of spi, i was not able to find it anywhere on google.
    i studied too much tutorials on google about spi but none mentioned this thing.I nowhere found that master also needs to send same number of dummy bytes as the number of bytes it is reading.After researching a lot i thought of taking help from keil support.

    i am aware of i2c but just asked thinking that i might get some new thing to learn about i2c. as i got in case of spi