SPI EEPROM - configuration problem ?

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

SPI EEPROM - configuration problem ?

523 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Fri Mar 01 00:57:43 MST 2013
Hi all,

I have a problem with configuration and function of SPI on my LPCXpresso LPC1769. I would like to load data from EEPROM (Michrochip 25LC256) to MCU, but I can not load basic command LOAD STATUS REGISTER.
My code:

#ifdef __USE_CMSIS
#include "LPC17xx.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 ;

int main(void) {

LPC_SC->CLKSRCSEL = (1 << 0);            // SOURCE OF CLK (EXT 12 MHz)
LPC_SC->PLL0CFG = (0 << 16) | (11 << 0); // N = 1 a M = 12 (PLL0 = 288 MHz)
LPC_SC->PLL0CON = (3 << 0);              // ENABLE PLL0
LPC_SC->PLL0FEED = (0xAA << 0);          // CONFIRM SEQUENCE FOR PLL0
LPC_SC->PLL0FEED = (0x55 << 0);          // CONFIRM SEQUENCE FOR PLL0
LPC_SC->CCLKCFG = (2 << 0);              // DIVIDER FOR CPU CLOCK (288 / 3 = 96 MHz)

LPC_SC->PCONP = (1 << 8) | (1 << 15);    // CONNECT SPI, GPIO

LPC_GPIO0->FIODIR = (1 << 18) | (1 << 16) | (1 << 15); // P0.18 (SPI MOSI), P0.16 (SPI SSEL), P0.15 (SPI Clock) => Vystup

LPC_PINCON->PINSEL0 = (3 << 30);                      // P0.15 -> SCK (SPI Clock)
LPC_PINCON->PINSEL1 = (3 << 4) | (3 << 2) | (3 << 0); // P0.18 -> MOSI, P0.17 -> MISO, P0.16 -> SSEL

LPC_SC->PCLKSEL0 |= (1 << 16); // DIVIDER OF SPI (1:1)
LPC_SPI->SPCCR = (24 << 0);    // DIVIDER SPI Clock (24 => 96 / 24 = 4 Mhz)
LPC_SPI->SPCR = (1 << 5);      // SET SPI MASTER

LPC_SPI->SPDR = 0b00000101;          // READ STATUS REGISTER OF EEPROM
while (!(LPC_SPI->SPSR & (1 << 7))); // WAITING TO COMPLETE TRANSFER

while(1) {

}
return 0 ;
}



Result of this code is that value of LPC_SPI->SPDR is 0xFF. I think that is not correct value. Where is a problem?
0 Kudos
Reply
1 Reply

463 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Mar 01 03:34:04 MST 2013

Quote:

Where is a problem?

You don't understand what SPI (or SSP) is ;)

Chapter '2.5 Read Status Register Instruction' of 25AA256/25LC256 dataheet shows Figure 2-6: CS low, write 8bits, read 8bits, CS high. You are just writing  :eek:

So is there a special reason why you don't use a sample (SSP?) where you can learn how this stuff is working :confused:
0 Kudos
Reply