Discussion in 'Embedded Systems and Microcontrollers' started by balamanikandan, Mar 5, 2013.

  1. balamanikandan

    Thread Starter New Member

    May 15, 2012

    A SPI interface is available in a processor.

    Will the interface support both the EEPROM and FLASH device?

    i.e Can we connect SPI-EEPROM as well as SPI- FLASH?
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Yes. Each slave needs it's own chip select line so it knows when to activate or sit mute.
  3. JMac3108

    Active Member

    Aug 16, 2010
    You will need to allocate a GPIO pin (port pin) for the chip select on each SPI device. You simply set the appropriate CS to the active state to select a particular device.

    One thing to be aware of is that the GPIO pin is asynchronous to the SPI controller. Lets say you write some code like this to transimitt over SPI ...
      • set CS active
      • check to see if the SPI TX buffer is empty
      • place byte into SPI TX buffer
      • set CS inactive
    This may not work because you do not know when the data in the SPI TX buffer is actually clocked out. You need to code it like this ...

      • set CS active
      • check to see if the SPI TX buffer is empty
      • place byte in SPI TX buffer
      • wait until flag is set indicating data has been sent
      • set CS inactive
    Another thing to be aware of is that different SPI devices run at different maximum speeds - check your datasheets. For example the SPI interface on a flash may run at up to 50MHZ, while the SPI interface on a temperature sensor may have a maximum speed of 3MHz. If speed is important, you may have to change the SPI bus clock speed differently depending on which device you are communicating with.

    One more thing that often trips up new SPI users ...
    To receive a byte of SPI data, you must transmit a dummy byte of data. This is because the SPI clock comes from the SPI master (micro-controller in this case). The dummy transmit produces the clocks necessary for the SPI device to send out a byte for the micro-controller to receive.

    And one more thing ...
    Check your datasheets closely (micro-controller and SPI device). There are things in the micro-controller registers like SPI master, SPI mode, clock polarity, and MSB first/last that have to be setup.