lpcware

[SOLVED] lpc11u14 spi problem

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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

Outcomes