User manual

LPCXpresso Experiment Kit - User’s Guide
Page 81
Copyright 2013 © Embedded Artists AB
dummy = LPC_SSP0->DR;
}
}
/*****************************************************************************
** Function name: SSP0Receive
** Descriptions: the module will receive a block of data from
** the SSP, the 2nd parameter is the block length.
** parameters: buffer pointer, and block length
** Returned value: None
**
*****************************************************************************/
void SSP0Receive( uint8_t *pBuf, uint32_t length )
{
uint32_t i;
for ( i = 0; i < length; i++ )
{
/* Write dummy output byte (0xFF) to shift in new byte */
LPC_SSP0->DR = 0xFF;
/* Wait until the Busy bit is cleared */
while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE )
;
*pBuf = LPC_SSP0->DR;
pBuf++;
}
}
Place the SPI related functions in file spi.c.
7.12.1 Lab 11a: Access Shift Register
In this experiment a shift register, the 74HC595 chip, shall be connected to the SPI bus. A byte will be
transmitted to the shift register and then read back. The external shift register can be seen as a one-
byte memory. Not very cost effective or high performance but in this experiment focus is on the
principles and getting to know the SPI bus and the SSP peripheral block.
As a first part in this exercise, update the SSP0Init() function to take an input parameter to control the
SCLK frequency. This can be done more, or less, complicated. To keep it simple, just calculate the
SCR bits in the CR0 register. It will not give full coverage, but at least some range.
Create an application the send one byte (8 bits) and then reads it back. Verify that the read-back byte
is correct. Use GPIO_4-LED-SSEL (PIO0_2) as SSEL signal and do not forget to initialize this GPIO
signal as an output and to also control the signal levels during SPI communication. It shall be high
when no communication takes place. Pull the signal low before transmitting the byte and then pull it
high after the transmission.
Rebuild the breadboard circuit in Lab 8e: Control 7-segment Display via Shift Register (on page 68).
The 7-segment display is not needed but as preparation for the next experiment it is simplest to rebuild
it all. The breadboard setup is repeated below with one extra wire the MISO signal.