lpcware

Stop SPI "Framing" on LPC11C24

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by brik2k on Tue Dec 25 21:48:59 MST 2012
Hi  everyone,
First, let me admit to being a little wet behind the ears here. I've just started playing around with the Xpresso board and the C programming language.

Anyway...on to my problem.  Long story short I'm trying to use the spi controller to accomplish a makeshift version of bit timing to control a ws2811 chip that does not use a clock signal. The problem is that the LPC spi controller seems to transmit the data in frames with a substantial delay between each frame. I've done quite a bit of searching and reading through the user manual and I'm unable to find any way remove the framing so the FIFO transmit bytes are sent in a continuous stream. Does anyone know if it's possible to get rid of the framing and the delay ? I do realize the framing/delay is not normally an issue for spi communication.

My code is below. It's a trimmed and modified version of the ssp example code. I've tried a number of register settings as well as taking out the busy and FIFO full checks.

Thanks for your help.


Name        : main.c
Author      :
Version     :
Copyright   : Copyright (C)
Description : main definition
===============================================================================
*/

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


/* SSP Status register */
#define SSPSR_TFE       (0x1<<0)
#define SSPSR_TNF       (0x1<<1)
#define SSPSR_RNE       (0x1<<2)
#define SSPSR_RFF       (0x1<<3)
#define SSPSR_BSY       (0x1<<4)

/* SSP CR0 register */
#define SSPCR0_DSS      (0x1<<0)
#define SSPCR0_FRF      (0x1<<4)
#define SSPCR0_SPO      (0x1<<6)
#define SSPCR0_SPH      (0x1<<7)
#define SSPCR0_SCR      (0x1<<8)

/* SSP CR1 register */
#define SSPCR1_LBM      (0x1<<0)
#define SSPCR1_SSE      (0x1<<1)
#define SSPCR1_MS       (0x1<<2)
#define SSPCR1_SOD      (0x1<<3)

/* SSP Interrupt Mask Set/Clear register */
#define SSPIMSC_RORIM   (0x1<<0)
#define SSPIMSC_RTIM    (0x1<<1)
#define SSPIMSC_RXIM    (0x1<<2)
#define SSPIMSC_TXIM    (0x1<<3)

/* SSP0 Interrupt Status register */
#define SSPRIS_RORRIS   (0x1<<0)
#define SSPRIS_RTRIS    (0x1<<1)
#define SSPRIS_RXRIS    (0x1<<2)
#define SSPRIS_TXRIS    (0x1<<3)

/* SSP0 Masked Interrupt register */
#define SSPMIS_RORMIS   (0x1<<0)
#define SSPMIS_RTMIS    (0x1<<1)
#define SSPMIS_RXMIS    (0x1<<2)
#define SSPMIS_TXMIS    (0x1<<3)

/* SSP0 Interrupt clear register */
#define SSPICR_RORIC    (0x1<<0)
#define SSPICR_RTIC     (0x1<<1)


/*****************************************************************************
** Function name:        SSP_IOConfig
**
** Descriptions:        SSP port initialization routine
**
** parameters:            None
** Returned value:        None
**
*****************************************************************************/
void SSP_IOConfig( uint8_t portNum )
{
  if ( portNum == 0 )
{
  LPC_SYSCON->PRESETCTRL |= (0x1<<0);
  LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<11);

  LPC_SYSCON->SSP0CLKDIV = 0x0A;            /* Divided by 2 */

  LPC_IOCON->PIO0_9           &= ~0x1f;
  LPC_IOCON->PIO0_9           |= 0x9;        /* SSP MOSI */

  }

  return;
}

/*****************************************************************************
** Function name:        SSP_Init
**
** Descriptions:        SSP port initialization routine
**
** parameters:            None
** Returned value:        None
**
*****************************************************************************/
void SSP_Init( uint8_t portNum )
{


  if ( portNum == 0 )
  {
  /* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and SCR is 15 */
    LPC_SSP0->CR0 = 0x000F;

  /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */
    LPC_SSP0->CPSR = 0x0A;


  /* Set SSPINMS registers to enable interrupts */
  /* enable all error related interrupts */
    LPC_SSP0->IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM;

     /* Device select as master, SSP Enabled */

      /* Master mode */
        LPC_SSP0->CR1 = SSPCR1_SSE;

  }

  return;
}

/*****************************************************************************
** Function name:        SSP_Send
**
** Descriptions:        Send a block of data to the SSP port, the
**                        first parameter is the buffer pointer, the 2nd
**                        parameter is the block length.
**
** parameters:            port #, buffer pointer, and the block length
** Returned value:        None
**
*****************************************************************************/
void SSP_Send(  )
{

     uint8_t Dummy = Dummy;

  while(1)
  {

    /* Move on only if NOT busy and TX FIFO not full. */
     while ( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );



      LPC_SSP0->DR = 0xAA; //Manually coded output byte




      while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
    /* 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. */
      Dummy = LPC_SSP0->DR;

  }
  return;
}


/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{

    SSP_IOConfig(0);
    SSP_Init(0);

while (1)
{

  SSP_Send();

}
  return 0;
}

/******************************************************************************
**                            End Of File
******************************************************************************/

Outcomes