SPI in ARM7(LPC2148)
By-
Aarav Soni
What is SPI ?
• Serial Peripheral Interface (SPI) is a synchronous serial data protocol used
by microcontrollers for communicating with one or more peripheral
devices quickly over short distances. It can also be used for
communication between two microcontrollers.
• Low power than I2C (no need of Pull ups)
• Supports Single master and multiple slaves
• No hardware slave acknowledgement
• Instrumentation & Communication Unit
• designed by Motorola
• four wire protocol
• Single complete and independent SPI controller.
• Compliant with Serial Peripheral Interface (SPI) specification.
• Synchronous, Serial, Full Duplex Communication.
• Combined SPI master and slave.
• Maximum data bit rate of one eighth of the input clock rate.
• 8 to 16 bits per transfer
• Master In Slave Out (MISO) - The Slave line for sending data to the master,
• Master Out Slave In (MOSI) - The Master line for sending data to the
peripherals,
• Serial Clock (SCK) - The clock pulses which synchronize data transmission
generated by the master, and
• Slave Select pin - the pin on each device that the master can use to enable
and disable specific devices. When a device's Slave Select pin is low, it
communicates with the master. When it's high, it ignores the master .
• The data and clock phase relationships are summarized in Table 197. This
table
• summarizes the following for each setting of CPOL and CPHA.
• When the first data bit is driven
• When all other data bits are driven
• When data is sampled
SPI Register
Read Overrun:
A read overrun occurs when the SPI block internal read buffer contains data that has
not been read by the processor, and a new transfer has completed. The read buffer
containing valid data is indicated by the SPIF bit in the status register being active.
When a transfer completes, the SPI block needs to move the received data to the
read buffer. If the SPIF bit is active (the read buffer is full), the new receive data
will be lost, and the read overrun (ROVR) bit in the status register will be activated.
Write Collision:
As stated previously, there is no write buffer between the SPI block bus interface,
and the internal shift register. As a result, data must not be written to the SPI data
register when a SPI data transfer is currently in progress. The time frame where
data cannot be written to the SPI data register is from when the transfer starts, until
after the status register has been read when the SPIF status is active. If the SPI data
register is written in this time frame, the write data will be lost, and the write
collision (WCOL) bit in the status register will be activated.
Mode Fault:
The SSEL signal must always be inactive when the SPI block is a master.
If the SSEL signal goes active, when the SPI block is a master, this
indicates another master ha selected the device to be a slave. This condition
is known as a mode fault. When a mode fault is detected, the mode fault
(MODF) bit in the status register will be activated, the SPI signal drivers
will be de-activated, and the SPI mode will be changed to be a slave.
Slave Abort
A slave transfer is considered to be aborted, if the SSEL signal goes
inactive before the transfer is complete. In the event of a slave abort, the
transmit and receive data for the transfer that was in progress are lost, and
the slave abort (ABRT) bit in the status register will be activated.
SPI Control Register (S0SPCR)
SPI Status Register (S0SPSR)
SPI Interrupt register (S0SPINT)
/********************************/
Function for initializing SPI
/********************************/
void spi_init()
{
PINSEL0=0X00001505;// Select MOSI, MISO, SCK
S0SPCCR=0X08; // clock is divided by 8
S0SPCR=0X0020; // select as master
}
/********************************/
Function for sending a char
/********************************/
void spi_master(char a)
{
S0SPDR=a;
while(!(S0SPSR & 0X80));
}
/********************************/
Function for receiving a char
/********************************/
char spi_slave(void)
{
while(!(S0SPSR & 0X80));
return S0SPDR;
}
Thanks
For any suggestion,
Please contact me on-
Mail id- a.soniarav@gmail.com
Facebook- https:www.facebook.com/arav.soni.98
Twitter- https://twitter.com/AaravSoni1

Spi in arm7(lpc2148)

  • 1.
  • 2.
    What is SPI? • Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers. • Low power than I2C (no need of Pull ups) • Supports Single master and multiple slaves • No hardware slave acknowledgement • Instrumentation & Communication Unit • designed by Motorola • four wire protocol
  • 3.
    • Single completeand independent SPI controller. • Compliant with Serial Peripheral Interface (SPI) specification. • Synchronous, Serial, Full Duplex Communication. • Combined SPI master and slave. • Maximum data bit rate of one eighth of the input clock rate. • 8 to 16 bits per transfer • Master In Slave Out (MISO) - The Slave line for sending data to the master, • Master Out Slave In (MOSI) - The Master line for sending data to the peripherals, • Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by the master, and • Slave Select pin - the pin on each device that the master can use to enable and disable specific devices. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master .
  • 8.
    • The dataand clock phase relationships are summarized in Table 197. This table • summarizes the following for each setting of CPOL and CPHA. • When the first data bit is driven • When all other data bits are driven • When data is sampled
  • 9.
  • 10.
    Read Overrun: A readoverrun occurs when the SPI block internal read buffer contains data that has not been read by the processor, and a new transfer has completed. The read buffer containing valid data is indicated by the SPIF bit in the status register being active. When a transfer completes, the SPI block needs to move the received data to the read buffer. If the SPIF bit is active (the read buffer is full), the new receive data will be lost, and the read overrun (ROVR) bit in the status register will be activated. Write Collision: As stated previously, there is no write buffer between the SPI block bus interface, and the internal shift register. As a result, data must not be written to the SPI data register when a SPI data transfer is currently in progress. The time frame where data cannot be written to the SPI data register is from when the transfer starts, until after the status register has been read when the SPIF status is active. If the SPI data register is written in this time frame, the write data will be lost, and the write collision (WCOL) bit in the status register will be activated.
  • 11.
    Mode Fault: The SSELsignal must always be inactive when the SPI block is a master. If the SSEL signal goes active, when the SPI block is a master, this indicates another master ha selected the device to be a slave. This condition is known as a mode fault. When a mode fault is detected, the mode fault (MODF) bit in the status register will be activated, the SPI signal drivers will be de-activated, and the SPI mode will be changed to be a slave. Slave Abort A slave transfer is considered to be aborted, if the SSEL signal goes inactive before the transfer is complete. In the event of a slave abort, the transmit and receive data for the transfer that was in progress are lost, and the slave abort (ABRT) bit in the status register will be activated.
  • 13.
  • 15.
  • 17.
  • 18.
    /********************************/ Function for initializingSPI /********************************/ void spi_init() { PINSEL0=0X00001505;// Select MOSI, MISO, SCK S0SPCCR=0X08; // clock is divided by 8 S0SPCR=0X0020; // select as master } /********************************/ Function for sending a char /********************************/ void spi_master(char a) { S0SPDR=a; while(!(S0SPSR & 0X80)); }
  • 19.
    /********************************/ Function for receivinga char /********************************/ char spi_slave(void) { while(!(S0SPSR & 0X80)); return S0SPDR; }
  • 20.
    Thanks For any suggestion, Pleasecontact me on- Mail id- [email protected] Facebook- https:www.facebook.com/arav.soni.98 Twitter- https://twitter.com/AaravSoni1