[SOLVED] lpc11u14 spi problem

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

[SOLVED] lpc11u14 spi problem

1,716 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sophio on Fri Apr 20 03:44:51 MST 2012
Hi everyone

I connect two lpc11u14 boards, one is configured as master, the other one as slave.
Slave send two byte data to master, however master can only receive one byte from slave.
What's the problem it might be?
Any advice is precious!


/******************************************************************************
**  Master Main Function  main()
******************************************************************************/
int main (void)
{
  uint32_t i;

  SystemInit();

  SSP_IOConfig( SSP_NUM );/* initialize SSP port */
  SSP_Init( SSP_NUM );

  /* Initialize GPIO (sets up clock) */
  GPIOInit();

   if (SysTick_Config(SystemCoreClock / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */
    while (1);                                  /* Capture error */
  }

  for ( i = 0; i < SSP_BUFSIZE; i++ )
  {
dest_addr = 0;
pre_addr = 0;
  }

  CS_enable();
//  Delay(1);  // Give slave some time to respond
  /*Receive the command*/
  SSP_Receive( SSP_NUM, (uint8_t *)dest_addr, SSP_BUFSIZE );// Read response from slave
  CS_disable() ;


   /*Store the command*/
   for ( i = 0; i < SSP_BUFSIZE; i++ )
   {
   pre_addr = dest_addr;
   }

  return 0;
}

/*****************************************************************************
** Function name:SSP_Receive
** Descriptions:the module will receive a block of data from
**the SSP, the 2nd parameter is the block
**length.
** parameters:port #, buffer pointer, and block length
** Returned value:None
**
*****************************************************************************/
void SSP_Receive( uint8_t portNum, uint8_t *buf, uint32_t Length )
{
  uint32_t i;

  for ( i = 0; i < Length; i++ )
  {

if ( portNum == 0 )
{
#if !LOOPBACK_MODE
#if SSP_SLAVE
  while ( !(LPC_SSP0->SR & SSPSR_RNE) );
#else
  LPC_SSP0->DR = 0xFF;
/* Wait until the Busy bit is cleared */
  while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
#endif
#else
  while ( !(LPC_SSP0->SR & SSPSR_RNE) );
#endif
  *buf = LPC_SSP0->DR;
  buf++;
}
else
{
#if !LOOPBACK_MODE
#if SSP_SLAVE
  while ( !(LPC_SSP1->SR & SSPSR_RNE) );
#else
  LPC_SSP1->DR = 0xFF;
  /* Wait until the Busy bit is cleared */
  while ( (LPC_SSP1->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
#endif
#else
  while ( !(LPC_SSP1->SR & SSPSR_RNE) );
#endif
  *buf = LPC_SSP1->DR;
buf++;
}
  }
  return;
}
#endif
Labels (1)
0 Kudos
Reply
6 Replies

1,594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Daniel Widyanto on Mon Dec 10 20:38:38 MST 2012
Please don't hijack other people's thread. Post you problem under new thread.
0 Kudos
Reply

1,594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nasib on Mon Dec 10 08:39:25 MST 2012
HI!

I have a little problem, i just want to send a simple data from the lpcxpresso11u14 through the SPI0. I've used this code, but when i test the signals with the osciloscope, the sck signal is always at 3V, and i send no data through the MOSI port.

do i have something wrong in the code?

Thank you so much!





#ifdef __USE_CMSIS
#include "LPC11Uxx.h"
#endif

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

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "gpio.h"
#include "ssp.h"

#define LED_PORT 0// Port for led
#define LED_BIT 7// Bit on port for led
#define ON 1// Level to set port to turn on led
#define OFF 0// Level to set port to turn off led
#define CS0_PORT 1
#define CS0_BIT 21
#define CS1_PORT 0
#define CS1_BIT 13
#define SPI0 0


volatile uint32_t msTicks;                            /* counts 1ms timeTicks */
/*----------------------------------------------------------------------------
  SysTick_Handler
*----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
  msTicks++;                        /* increment counter necessary in Delay() */
}
/*----------------------------------------------------------------------------
  Delay
*----------------------------------------------------------------------------*/
__INLINE static void Delay (uint32_t dlyTicks) {
  uint32_t curTicks;
  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks);
}



int main(void) {

volatile static int i = 0 ;
uint8_t buf[SSP_BUFSIZE];

for(i=0;i<SSP_BUFSIZE;i++){
buf=(uint8_t)i*10;
}

SystemInit();
SystemCoreClockUpdate();
GPIOSetDir(0,9,ON);
SSP_IOConfig(SPI0);
SSP_Init(SPI0);

    GPIOInit();
    GPIOSetDir(CS1_PORT,CS1_BIT,ON);               //CS0 = GPIO1_21  CS1= GPIO0_13
    GPIOSetDir(CS0_PORT,CS0_BIT,ON);               //CS0 = GPIO1_21  CS1= GPIO0_13
    GPIOSetBitValue(CS1_PORT,CS1_BIT,OFF);
    GPIOSetBitValue(CS0_PORT,CS0_BIT,OFF);

    if (SysTick_Config(SystemCoreClock / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */
        while (1);                                  /* Capture error */
    }

while(1) {

SSP_Send(SPI0,(uint8_t *)buf,SSP_BUFSIZE);
Delay(100);
}
return 0 ;
}
0 Kudos
Reply

1,594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sophio on Mon Jun 18 06:05:43 MST 2012
After i changing the CPHA = 0 to CPHA = 1, this problem was solved. I think the reason may be the slave could not react fast enough to get the first byte~~~
0 Kudos
Reply

1,594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu May 24 04:00:38 MST 2012
You are not showing much of your code.

But of course CPOL=0 and CPHA=0 is an usual setup and my LPC1114 is reading data without problems as master(SPI0) from slave (SPI1).
0 Kudos
Reply

1,594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sophio on Thu May 24 03:13:19 MST 2012
Thanks for reply.
But I think the only difference between CPHA = 0 and CPHA = 1 is: when the CPHA =0, data is captured on the first clock edge  transition. If the CPHA=1, data is captured on the second clock edge transition.

So i do not think when CPHA = 0, i can only get the first frame.

Am i wrong?
0 Kudos
Reply

1,594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Karl on Thu Apr 26 17:04:01 MST 2012
Just a wild guess: Looks like you are using GPIO for the SPI chip select. This only works for CPHA=1. With CPHA=0 you only get the first frame after SSEL activation, all others are lost until you pull up SSEL high again.
0 Kudos
Reply