lpcware

SPI promblem

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by nasib on Fri Nov 30 11:13:39 MST 2012
Hi!, i've used keil's examples for 11u14 lpcxpresso prototipe board.
And i'm using the NXP IDE compiler.

I'm tried to program  SPI applications, it compile ok and i can run it into the board, but when i sense the MOSI signal with the osciloscope it is always 0.

I've used the code bellow, where CS is the GPIO1_21.

There is any error in the code?  could anyone help me please?

thank you very 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 CS0_PORT 1
#define CS0_BIT 21
#define CS0_ON 1
#define CS0_OFF 0
#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 ;
    uint32_t Lenght = 8;
    uint8_t buf[Lenght];

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


    SystemCoreClockUpdate();

    //SSP0_IRQHandler();
    SSP_IOConfig(SPI0);
    SSP_Init(SPI0);
    GPIOInit();
    GPIOSetDir(CS0_PORT,CS0_BIT,1);
    GPIOSetBitValue(CS0_PORT,CS0_BIT,CS0_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,Lenght);
         Delay(100);
        
    }
    return 0 ;
}

Outcomes