LPC1764 Using SSP1 for EEPROM SPI communication at 10MHz help

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC1764 Using SSP1 for EEPROM SPI communication at 10MHz help

1,550 次查看
lpcware
NXP Employee
NXP Employee
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. 


标签 (1)
0 项奖励
回复
3 回复数

1,441 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Mon Aug 26 08:46:02 MST 2013
The same question and already some (same) answers here in lpc2000 yahoo mailing list:
http://tech.groups.yahoo.com/group/lpc2000/message/58980
0 项奖励
回复

1,441 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Mon Aug 26 08:34:37 MST 2013
The positions of the delay() in your source code makes no sense for me.

The only place in the code a delay() makes sense is after CD low.

I am using SPI to serial nand flash @20Mhz clock, and I don't have to use any delay for CS low/high.
(I am using bit banding for CS handling, doing the read-modify-write in hardware).

Note: the *best* way to do small amount of delay is to read an IO register.

regards
Wolfgang
0 项奖励
回复

1,441 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micro9000 on Thu Aug 22 14:53:41 MST 2013
I managed to figure it out. I needed a delay after and before the /CS pin was asserted low and high. Here is what the read statement look like within the main while loop now:

else
{

systick_delay(1); // wait 1ms
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);
systick_delay(1); // 1ms
PORT_CS->FIOSET |= PIN_MASK_CS; //CS High
}

I have to find out how to use timers as delays, for milliseconds using system tick isn't going to cut it. From the datasheet, the delay has to be about 100ns, but it still works with 1ms. I think I can use the match register to do this I just have to configure the PCLK to be system clock divided by 2 instead of 4.
0 项奖励
回复