SPI in ARM7(LPC2148) By- Aarav Soni

Spi in arm7(lpc2148)

Embed Size (px)

Citation preview

Page 1: Spi in arm7(lpc2148)

SPI in ARM7(LPC2148)

By-Aarav Soni

Page 2: Spi in arm7(lpc2148)

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

Page 3: Spi in arm7(lpc2148)

• 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 .

Page 4: Spi in arm7(lpc2148)
Page 5: Spi in arm7(lpc2148)
Page 6: Spi in arm7(lpc2148)
Page 7: Spi in arm7(lpc2148)
Page 8: Spi in arm7(lpc2148)

• 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

Page 9: Spi in arm7(lpc2148)

SPI Register

Page 10: Spi in arm7(lpc2148)

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.

Page 11: Spi in arm7(lpc2148)

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.

Page 12: Spi in arm7(lpc2148)
Page 13: Spi in arm7(lpc2148)

SPI Control Register (S0SPCR)

Page 14: Spi in arm7(lpc2148)
Page 15: Spi in arm7(lpc2148)

SPI Status Register (S0SPSR)

Page 16: Spi in arm7(lpc2148)
Page 17: Spi in arm7(lpc2148)

SPI Interrupt register (S0SPINT)

Page 18: Spi in arm7(lpc2148)

/********************************/ Function for initializing SPI/********************************/void spi_init(){ PINSEL0=0X00001505;// Select MOSI, MISO, SCKS0SPCCR=0X08; // clock is divided by 8S0SPCR=0X0020; // select as master}/********************************/ Function for sending a char /********************************/void spi_master(char a){S0SPDR=a;while(!(S0SPSR & 0X80));}

Page 19: Spi in arm7(lpc2148)

/********************************/ Function for receiving a char /********************************/char spi_slave(void){while(!(S0SPSR & 0X80));return S0SPDR;}

Page 20: Spi in arm7(lpc2148)


For any suggestion,Please contact me on-Mail id- [email protected] https:www.facebook.com/arav.soni.98Twitter- https://twitter.com/AaravSoni1