Content originally posted in LPCWare by nasib on Mon Dec 10 08:39:25 MST 2012
HI!
I have a little problem, i just want to send a simple data from the lpcxpresso11u14 through the SPI0. I've used this code, but when i test the signals with the osciloscope, the sck signal is always at 3V, and i send no data through the MOSI port.
do i have something wrong in the code?
Thank you so 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 LED_PORT 0// Port for led
#define LED_BIT 7// Bit on port for led
#define ON 1// Level to set port to turn on led
#define OFF 0// Level to set port to turn off led
#define CS0_PORT 1
#define CS0_BIT 21
#define CS1_PORT 0
#define CS1_BIT 13
#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 ;
uint8_t buf[SSP_BUFSIZE];
for(i=0;i<SSP_BUFSIZE;i++){
buf=(uint8_t)i*10;
}
SystemInit();
SystemCoreClockUpdate();
GPIOSetDir(0,9,ON);
SSP_IOConfig(SPI0);
SSP_Init(SPI0);
GPIOInit();
GPIOSetDir(CS1_PORT,CS1_BIT,ON); //CS0 = GPIO1_21 CS1= GPIO0_13
GPIOSetDir(CS0_PORT,CS0_BIT,ON); //CS0 = GPIO1_21 CS1= GPIO0_13
GPIOSetBitValue(CS1_PORT,CS1_BIT,OFF);
GPIOSetBitValue(CS0_PORT,CS0_BIT,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,SSP_BUFSIZE);
Delay(100);
}
return 0 ;
}