SPI in LPC1317

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI in LPC1317

1,352 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Mon May 06 11:03:20 MST 2013
Hi,

How can I load received byte in lpc1317 in SPI mode? I have EEPROM memory from which to read data. When the program steps, I can see that the data arrived correctly, but if you want to store in a variable, so I only saved value 0xFF. Do you know where is the problem?
0 Kudos
Reply
4 Replies

1,317 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 07 03:21:25 MST 2013

Quote: masterboy
When I used the LPC17xx so simple functions for reading data could:
uint8_t EepromRead(uint16_t u16_address) {
    EEPROM_SSEL_ON();
    LPC_SPI->SPDR = 0b00000011;
    while (!(LPC_SPI->SPSR & (1 << 7)));
    LPC_SPI->SPDR = (u16_address >> 8);
    while (!(LPC_SPI->SPSR & (1 << 7)));    
    LPC_SPI->SPDR = (u16_address & 0xFF);    
    while (!(LPC_SPI->SPSR & (1 << 7)));    
    LPC_SPI->SPDR = 0b00000000;                
    while (!(LPC_SPI->SPSR & (1 << 7)));    
    EEPROM_SSEL_OFF();
    return LPC_SPI->SPDR;
}
But LPC13xx and LPC11xx situation is more complicated because there is no native SPI.
SSP is more complicated to setup for me


It's just luck that this code is working with your LPC17xx. You are not reading FIFO flags, you don't care what's happening. Just throwing data out and hoping that something correct is received.
It's not surprising that this method fails.
0 Kudos
Reply

1,317 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Tue May 07 02:49:24 MST 2013
When I used the LPC17xx so simple functions for reading data could:
uint8_t EepromRead(uint16_t u16_address) {
EEPROM_SSEL_ON();
LPC_SPI->SPDR = 0b00000011;
while (!(LPC_SPI->SPSR & (1 << 7)));
LPC_SPI->SPDR = (u16_address >> 8);
while (!(LPC_SPI->SPSR & (1 << 7)));
LPC_SPI->SPDR = (u16_address & 0xFF);
while (!(LPC_SPI->SPSR & (1 << 7)));
LPC_SPI->SPDR = 0b00000000;
while (!(LPC_SPI->SPSR & (1 << 7)));
EEPROM_SSEL_OFF();
return LPC_SPI->SPDR;
}


But LPC13xx and LPC11xx situation is more complicated because there is no native SPI.
SSP is more complicated to setup for me
0 Kudos
Reply

1,317 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 07 02:01:34 MST 2013

Quote: masterboy
There is output of signal


No, there's nothing.

Quote: masterboy

#define SSP_SSEL_LOW()        LPC_GPIO->CLR[0] = SSP_SSEL
#define SSP_SSEL_HIGH()        LPC_GPIO->SET[0] |= SSP_SSEL
...

    LPC_IOCON->PIO0_2 = (2 << 3) | (1 << 0);    // SSEL0
    LPC_GPIO->DIR[0] |= SSP_SSEL;    // SSEL
    SSP_SSEL_HIGH();


Either use SSEL function or GPIO function, non both.

Quote: masterboy

LPC_SSP0->DR = 0b00000011;    // Command - read
LPC_SSP0->DR = 0b00000000;    // Address - high byte
LPC_SSP0->DR = 0b00000000;    // Address - low byte
LPC_SSP0->DR = 0b00000000;    // Dummy byte
while ((LPC_SSP0->SR & (SSP_SR_BSY | SSP_SR_RNE)) != SSP_SR_RNE);
v1 = LPC_SSP0->DR;


What do you think is happening here in SSP? You are filling a FIFO.
I can't understand why you don't read a LPC13 sample, if you don't understand the timing.
void [COLOR=Red]SSPSend[/COLOR]( uint8_t *buf, uint32_t Length )
{
  uint32_t i;
  uint8_t Dummy = Dummy;
    
  for ( i = 0; i < Length; i++ )
  {
    /* Move on only if NOT busy and TX FIFO not full. */
   [COLOR=Red] while ( (LPC_SSP->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );[/COLOR]
    LPC_SSP->DR = *buf;
    buf++;
#if !LOOPBACK_MODE
   [COLOR=Red] while ( (LPC_SSP->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );[/COLOR]
    [B][COLOR=Red]/* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO 
    on MISO. Otherwise, when SSP0Receive() is called, previous data byte
    is left in the FIFO. */[/COLOR][/B]
    Dummy = LPC_SSP->DR;
#else
    /* Wait until the Busy bit is cleared. */
    while ( LPC_SSP->SR & SSPSR_BSY );
#endif
  }
  return; 
}
0 Kudos
Reply

1,317 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Tue May 07 00:49:26 MST 2013
There is my code:
#ifdef __USE_CMSIS
#include "LPC13Uxx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

__CRP const unsigned int CRP_WORD = CRP_NO_CRP;

#define SSP_SR_RNE       (1 << 2)// Receive FIFO Not Full
#define SSP_SR_BSY       (1 << 4)// Busy
#define SSP_SSEL(1 << 3) // P0.3

#define SSP_SSEL_LOW()LPC_GPIO->CLR[0] = SSP_SSEL
#define SSP_SSEL_HIGH()LPC_GPIO->SET[0] |= SSP_SSEL

int main(void) {

LPC_IOCON->PIO0_2 = (2 << 3) | (1 << 0);// SSEL0
LPC_IOCON->PIO0_6 = (2 << 3) | (2 << 0);// SCK0
LPC_IOCON->PIO0_8 = (2 << 3) | (1 << 0);// MISO0
LPC_IOCON->PIO0_9 = (2 << 3) | (1 << 0);// MOSI0

LPC_GPIO->DIR[0] |= SSP_SSEL;// SSEL
SSP_SSEL_HIGH();

LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);// SSP0 - ENABLE
LPC_SYSCON->SSP0CLKDIV = 255;
LPC_SYSCON->PRESETCTRL |= (1 << 0);
LPC_SSP0->CR0 = 7;
LPC_SSP0->CPSR = 2;
LPC_SSP0->CR1 = (1 << 1);

uint8_t v1;

SSP_SSEL_LOW();
LPC_SSP0->DR = 0b00000011;// Command - read
LPC_SSP0->DR = 0b00000000;// Address - high byte
LPC_SSP0->DR = 0b00000000;// Address - low byte
LPC_SSP0->DR = 0b00000000;// Dummy byte
[COLOR=Red]while ((LPC_SSP0->SR & (SSP_SR_BSY | SSP_SR_RNE)) != SSP_SR_RNE);[/COLOR]
v1 = LPC_SSP0->DR;
SSP_SSEL_HIGH();
while(1) {

}
return 0 ;
}



There is output of signal

Where D2 is SSEL, D3 is SCK, D4 is MOSI and D5 is MISO. Signals are alright. From the figure, it is clear that the received byte has a value 0xAA. This value can be seen in the registry LPC_SSP0->DR, when the program steps (the red line in the code). Next step, this value is deleted. The variable "v1" is a storage value 0xFF. Do you know why?
0 Kudos
Reply