lpcware

LPC1764 Using SSP1 for EEPROM SPI communication at 10MHz help

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by micro9000 on Sun Aug 18 16:32:08 MST 2013
Hey guys, I could use some help. I am using LPCexpresso 5.2.6, LPC-Link 2, and an LPC1764 microcontroller. The problem is I cannot get my LED to blink when I am reading a value that should be in address 0 (if what I am doing is correct) of the EEPROM. I am attempting to do this using SSP1 working as SPI at 10MHz. Here is the code I am using:

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

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

#include <cr_section_macros.h>
#include <NXP/crp.h>

#include "leds.h"
#include "timer.h"
#include "Systemtick_Delay.h"

#include "lpc17xx_ssp.h" // added for eeprom

//Defines for spi
#define SSP_CHANNEL LPC_SSP1
#define PORT_CSLPC_GPIO2
#define PIN_MASK_CS (1<<2)

//Define instructions of 25LC512 EEPROM
#define WREN    0x06    // write enable
#define WRDI    0x04    // write disable
#define WRITE   0x02    // initialize start of write sequence
#define READ    0x03    // initialize start of read sequence
#define CE      0xc7    // erase all sectors of memory
#define RDSR    0x05    // read STATUS register


// NOTE: #define PLL0CFG_Val 0x00090063 ensure this is the case in CMISvp00_17xx under system_LPCxx.c
//  see user manual section 4.5 for more information

int main(void) {

led2_init();// Setup GPIO for LED2
led2_on();
SysTick_Init();

unsigned char readSPIvalue=0;

//Initialize timer
//init_timer( 0, TIMER0_INTERVAL );
//enable_timer( 0 );

//eeprom spi set up
SSP_CFG_Type sspChannelConfig;

// see pg 108/840 in datasheet, Pin Function Select register 0
LPC_PINCON->PINSEL0 |= 0x2<<14; //SCK1
LPC_PINCON->PINSEL0 |= 0x2<<18;//MOSI1
LPC_PINCON->PINSEL0 |= 0x2<<16;//MISO1

PORT_CS->FIODIR |= 1<<2;//P2.2 as CSn


SSP_ConfigStructInit(&sspChannelConfig);
SSP_Init(SSP_CHANNEL, &sspChannelConfig);
SSP_Cmd(SSP_CHANNEL, ENABLE);



// config EEPROM to enable writing
PORT_CS->FIOCLR |= PIN_MASK_CS;//CS low
SSP_SendData(SSP_CHANNEL,WREN); // write enable command
PORT_CS->FIOSET |= PIN_MASK_CS; //CS High


PORT_CS->FIOCLR |= PIN_MASK_CS;//CS low
SSP_SendData(SSP_CHANNEL,WRITE);// write command
SSP_SendData(SSP_CHANNEL,0x00); // write address
SSP_SendData(SSP_CHANNEL,0x00); // write address
SSP_SendData(SSP_CHANNEL,100); // Data to send
PORT_CS->FIOSET |= PIN_MASK_CS; //CS High


//------------------------ Main Loop---------------------------
while(1) {


if(readSPIvalue==100) // initially it is 0
{
//make LED blink if eeprom read
led2_invert();// Toggle state of LED2
}
else
{
//checkEEPROM_Busy();
PORT_CS->FIOCLR |= PIN_MASK_CS;//CS low
SSP_SendData(SSP_CHANNEL,READ); // read command
SSP_SendData(SSP_CHANNEL,0x00); // byte 1 16bit address to read
SSP_SendData(SSP_CHANNEL,0x00); // byte 2 16bit address to read

SSP_SendData(SSP_CHANNEL,0x00); // clock data out for reading
readSPIvalue=SSP_ReceiveData(SSP_CHANNEL);
PORT_CS->FIOSET |= PIN_MASK_CS; //CS High
}

systick_delay(200); // wait 2 seconds (2000ms)
//led2_invert();// Toggle state of LED2
}


return 0 ;
}


NOTE: This is based off of the ssp_spi example provided.

Also, here are the connections I am using:
[IMG]http://i188.photobucket.com/albums/z265/fac7orx/eepromARMpic_zpsdc524e83.png[/IMG]

And here is the datasheet for the EEPROM:
http://ww1.microchip.com/downloads/en/devicedoc/22065a.pdf

In addition, I have set the clock rate in the function SSP_ConfigStructInit:

void SSP_ConfigStructInit(SSP_CFG_Type *SSP_InitStruct)
{
SSP_InitStruct->CPHA = SSP_CPHA_FIRST;
SSP_InitStruct->CPOL = SSP_CPOL_HI;
SSP_InitStruct->ClockRate = 1000000;
SSP_InitStruct->Databit = SSP_DATABIT_8;
SSP_InitStruct->Mode = SSP_MASTER_MODE;
SSP_InitStruct->FrameFormat = SSP_FRAME_SPI;
}


So, judging from the code I have posted above is something missing? I have included the necessary files such as lpc_17xx_clkpwr.c and .h, lpc17xx_ssp.c and .h, as well as lpc17xx_libcfg_Default.c. 


Outcomes