SPI promblem

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

SPI promblem

377 Views
lpcware
NXP Employee
NXP Employee
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 ;
}
0 Kudos
6 Replies

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Mon Dec 10 20:32:48 MST 2012

Quote: researchinnovation
Have you gone through datasheet and its protocol.


Have you gone through datasheet....!!!
0 Kudos

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nasib on Mon Dec 10 05:20:58 MST 2012

Quote: researchinnovation
Hi...!!!

Go to SSP.h and SSP.c files and change the settings, master mode, set the clock, mode, CPOL, CPHA and all.
And do little modification in your send function.
Check on  this also
SSP_IOConfig(SPI0);
    SSP_Init(SPI0)
Is this function able to set your SS pin
GPIOSetBitValue(CS0_PORT,CS0_BIT,CS0_OFF);
Check this also, that how are you sending data, check the parameters you are passing
SSP_Send(SPI0,(uint8_t *)buf,Lenght);
And find out the correct pins on Schematic diagram on board for SPI and then connect with OSCILLOSCOPE.


Thanks & Regards....  :-)




What do you mean with change master mode, set the clock, mode, CPOL, CPHA and all.?

I just know how to change master mode, but i don't know what are you meaning with the others.

do i have to use another special function ? 

i use this "GPIOSetBitValue(CS0_PORT,CS0_BIT,CS0_OFF);" to set the CS. It change its value correctly but the program doesn't send the information !

have you got any example code?
0 Kudos

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Mon Dec 10 00:42:47 MST 2012
User Manual UM10462
0 Kudos

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Sun Dec 09 20:27:59 MST 2012

Quote: nasib
Thank you so much for your reply!

Do anyone know where could i find any book, handbook or exhaustive tutorial where i'll can find all the parameters, commands, variables and basic functions used in the libraries (lpc11U14)?

Or i'll have to learn about this just finding into the libraries?

thank you so much!



Have you gone through datasheet and its protocol.
0 Kudos

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nasib on Sun Dec 09 17:52:55 MST 2012
Thank you so much for your reply!

Do anyone know where could i find any book, handbook or exhaustive tutorial where i'll can find all the parameters, commands, variables and basic functions used in the libraries (lpc11U14)?

Or i'll have to learn about this just finding into the libraries?

thank you so much!
0 Kudos

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Sun Dec 02 21:49:54 MST 2012
Hi...!!!

Go to SSP.h and SSP.c files and change the settings, master mode, set the clock, mode, CPOL, CPHA and all.
And do little modification in your send function.
Check on  this also
SSP_IOConfig(SPI0);
    SSP_Init(SPI0)
Is this function able to set your SS pin
GPIOSetBitValue(CS0_PORT,CS0_BIT,CS0_OFF);
Check this also, that how are you sending data, check the parameters you are passing
SSP_Send(SPI0,(uint8_t *)buf,Lenght);
And find out the correct pins on Schematic diagram on board for SPI and then connect with OSCILLOSCOPE.


Thanks & Regards....  :-)
0 Kudos