Content originally posted in LPCWare by maxve2011 on Wed Jan 18 09:38:59 MST 2012
Hello,
I got stuck into a SSP/SPI problem with the LPC1227/301 arm-cortex m0.
I'am interfacing the lpc1227 with a external SPI flash memory.
I use the GPIO0_15 (ssel) pin as a digital output pin for chip selecting the flash memory.
Every time when the first command must be transmitted the LPC_SSP->DR register receives the value 0xff and not the command! Then when transmitting the next data all went fine!
Have I made something wrong? Any help I will appreciate.
Remark: There is no SSP/SPI code example for the lpc1227, or is there a good one? Please can someone give me some hints?
I use the following code:
void SPI_MasterInit(void)
{
register uint8_t i, Dummy=Dummy;
/* set up SPI port pins */
LPC_IOCON->PIO0_14 &= ~(0x7);
LPC_IOCON->PIO0_14 |= MODE_SPI; /*SCK*/
LPC_IOCON->PIO0_16 &= ~(0x7);
LPC_IOCON->PIO0_16 |= MODE_SPI; /*MISO*/
LPC_IOCON->PIO0_17 &= ~(0x7);
LPC_IOCON->PIO0_17 |= MODE_SPI; /*MOSI*/
/* Enable SSP0 peripheral clock */
LPC_SYSCON->SSPCLKDIV = 0x01;
/* Set DSS data to 8-bit, Frame format SPI,
CPOL = 0, CPHA = 0, and SCR is 1
*/
LPC_SSP->CR0 = (SSPCR0_DSS)|(SSPCR0_CPOL)|(SSPCR0_CPHA)|(SSPCR0_SCR);
/* Enable SSP controller */
LPC_SSP->CR1 = SSPCR1_SSE;
/* SSPCPSR clock prescale register, master mode,
minimum divisor is 0x02 for master mode
*/
/* Set bitfrequency to 3 MHz */
LPC_SSP->CPSR = 0x4;
for ( ;i < FIFOSIZE;i++)
{
Dummy = LPC_SSP->DR; /* clear the RxFIFO */
}
/* Enable the SSP/SPI Interrupt */
NVIC_EnableIRQ(SSP_IRQn);
/* Device select as master, SSP/SPI Enabled */
LPC_SSP->CR1 = SSPCR1_SSE;
/* Set SSPINMS registers to enable interrupts
* enable all error related interrupts */
LPC_SSP->IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM;
return;
}
void SPI_MasterTransmit(uint8_t *buff, uint32_t Length)
{
register uint32_t i = 0;
register uint8_t Dummy = Dummy;
/* Validate parameters */
REQUIRE(buff != NULL && Length < UINT32_MAX);
for( ;i < Length;i++)
{
/* Move on only if NOT busy (=0) and TX FIFO not full (=1) */
while((LPC_SSP->SR & (SSPSR_BSY|SSPSR_TNF)) != SSPSR_TNF);
/* Put data/instruction into SSP data buffer and right justify */
LPC_SSP->DR = *buff;
buff++;
/* Wait until the Busy bit for transmission is cleared. */
while ((LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE);
Dummy = LPC_SSP->DR;
}
return;
}
void SPI_MasterReceive(uint8_t *buff, uint32_t Length)
{
register uint32_t i = 0;
/* Validate parameters */
REQUIRE(buff != NULL && Length < UINT32_MAX);
for( ;i < Length;i++)
{
/* As long as receive FIFO is not empty (=1), receiving data is always
* possible */
/* Wait with receiving data until the Busy bit is cleared */
while((LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE);
*buff = LPC_SSP->DR;
buff++;
}
return;
}
uint8_t src_addr[1] = {0};
uint8_t dest_addr[3] = {0};
uint8_t locbuffer[3] = {0};
#define WREN 0x06
a25lq_errCode A25LQ032_WREN(void)
{
/* CS active low */
SPI_SSEL_LOW;
/* SPI transmits WRITE_ENABLE instruction */
src_addr[0] = WRITE_ENABLE;
SPI_MasterTransmit(&src_addr[0],1);
/* CS active high */
SPI_SSEL_HIGH;
if(SPI_SSEL_HIGH)
{
return A25CMD_SUCCESS;
}
else return A25CMD_FAILURE;
}
When calling above function with SPI_MasterTransmit the SSP dataregister
receives the value 0xff and not 0x06!
Do I have to call SPI_MasterReceive() separately?
MV