SPI code for LPC1114/301

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

SPI code for LPC1114/301

839 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Nov 22 00:23:55 MST 2012
Hi..!!

I need working code on SPI for LPC1114/301 for Master and Slave separately(On LPCXpresso).
Following code is not able to generate the clock on SPI.
Pin configurations are:


PIO0_2 = SPI SS
PIO0_6 = SPI clock
PIO0_8 = SPI MISO
and PIO0_9 = SPI MOSI.
0 Kudos
Reply
2 Replies

746 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Mon Nov 26 03:53:24 MST 2012
Why, following code is checking for only one if condition, it is not checking all the conditions. Why so.

#include "driver_config.h"
#include "target_config.h"

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

#if SSP_DEBUG
#include "uart.h"

#endif
#include <stdio.h>
#define SSP_NUM            0
uint8_t i=0;
uint16_t buff[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

uint16_t mm;
int main (void)
{


  SystemInit();
  SSP_IOConfig( 0 );    /* initialize SSP port, share pins with SPI1
                        on port2(p2.0-3). */
  //SSP_Init( SSP_NUM );
  //GPIOSetDir(PORT0,2,0);
  LPC_IOCON->PIO0_8           &= ~0x07;    /*  SSP I/O config */
  LPC_IOCON->PIO0_8           |= 0x01;        /* SSP MISO */
  LPC_IOCON->PIO0_9           &= ~0x07;
  LPC_IOCON->PIO0_9           |= 0x01;
  LPC_IOCON->SCK_LOC = 0x02;
  LPC_IOCON->PIO0_6 = 0x02;
  LPC_IOCON->PIO0_2 &= ~0x07;
  LPC_IOCON->PIO0_2 |= 0x01;

  if ( LPC_SSP0->CR1 & SSPCR1_SSE )
    {
      /* The slave bit can't be set until SSE bit is zero. */
        LPC_SSP0->CR1 &= ~SSPCR1_SSE;
    }
      LPC_SSP0->CR1 = SSPCR1_MS;        /* Enable slave bit first */
      LPC_SSP0->CR1 |= SSPCR1_SSE;

  LPC_SSP0->CR0 = 0x04CF;
  LPC_SSP0 ->CR1 = 0x06;

while(1)
{
    while ( !(LPC_SSP0->SR & SSPSR_RNE) );
    {//printf(" I am in buff loop buff");
     buff = (uint16_t)LPC_SSP0->DR;
           i++;
           mm = buff;

           if( mm = 0x0400)
           {
               while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
                   LPC_SSP0->DR = 0x4567;

           }
           if( mm = 0x0600)
                    {
                        while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
                            LPC_SSP0->DR = 0x1234;

                    }
            if( mm = 0x0800)
                    {
                        while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
                            LPC_SSP0->DR = 0x9875;

                    }
            if( mm = 0x0A00)
                             {
                                 while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
                                     LPC_SSP0->DR = 0x45FF;

                             }
    }

}

  return 0;
}
0 Kudos
Reply

746 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Nov 22 20:53:11 MST 2012

Quote: researchinnovation
Hi..!!

I need working code on SPI for LPC1114/301 for Master and Slave separately(On LPCXpresso).
Following code is not able to generate the clock on SPI.
Pin configurations are:


PIO0_2 = SPI SS
PIO0_6 = SPI clock
PIO0_8 = SPI MISO
and PIO0_9 = SPI MOSI.



void SSP_IOConfig( uint8_t portNum )
{
  if ( portNum == 0 )
{
  LPC_SYSCON->PRESETCTRL |= (0x1<<0);
    LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<11);
[B] [COLOR=Red]  LPC_SYSCON->SSP0CLKDIV = 0x0a; [/COLOR] [/B]          /* This will give you desired frequency right now it is 300KHz */
  LPC_IOCON->PIO0_8           &= ~0x07;    /*  SSP I/O config */
  LPC_IOCON->PIO0_8           |= 0x01;        /* SSP MISO */
  LPC_IOCON->PIO0_9           &= ~0x07;   
  LPC_IOCON->PIO0_9           |= 0x01;        /* SSP MOSI */
#ifdef __JTAG_DISABLED
    LPC_IOCON->SCK_LOC = 0x00;
    LPC_IOCON->SWCLK_PIO0_10 &= ~0x07;
    LPC_IOCON->SWCLK_PIO0_10 |= 0x02;        /* SSP CLK */
#else
0 Kudos
Reply