EmbeddedRelated.com
Forums

LPC1114 - SPI Clock speed

Started by nico...@gmail.com May 5, 2010
Hello all! I'm having some problems setting up ssp clock speed on a LPC1114. I want to set it to 15 MHz to communicate with an ATMEL AT45DB011D flash memory, but only get 3, no matter what I do, and I'm sure it's not a software problem since I already have this working with an LPC2368 at 15 MHz peripheral clock.

On the other hand, AT45DB011D electrical specifications does not specify a minimum clock speed, just a 66 MHz max. Anyone knows what the minimum should be?

I've changed M and N values on the LPC1114 and the resulting clock on spi is always around 3 MHz. Changing the peripheral divisor and prescaler work, but this doesn't help me at all since I want to increase speed.

I have the following settings:

12MHz external crystal

M = 6
N = 2

// Main Clock
LPC_SYSCON->SYSPLLCLKSEL = 0x01; /* Select system OSC */
LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL clock output */

// SSP Clock
LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */

// SSP Prescaler
LPC_SSP0->CPSR = 0x02; /* Minimum prescale */

Any thoughts? Thank you.

An Engineer's Guide to the LPC2100 Series

--- In l..., nicolas.christie@... wrote:
>
> Hello all! I'm having some problems setting up ssp clock speed on a LPC1114. I want to set it to 15 MHz to communicate with an ATMEL AT45DB011D flash memory, but only get 3, no matter what I do, and I'm sure it's not a software problem since I already have this working with an LPC2368 at 15 MHz peripheral clock.
>
> On the other hand, AT45DB011D electrical specifications does not specify a minimum clock speed, just a 66 MHz max. Anyone knows what the minimum should be?
>
> I've changed M and N values on the LPC1114 and the resulting clock on spi is always around 3 MHz. Changing the peripheral divisor and prescaler work, but this doesn't help me at all since I want to increase speed.
>
> I have the following settings:
>
> 12MHz external crystal
>
> M = 6
> N = 2
>
> // Main Clock
> LPC_SYSCON->SYSPLLCLKSEL = 0x01; /* Select system OSC */
> LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL clock output */
>
> // SSP Clock
> LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
>
> // SSP Prescaler
> LPC_SSP0->CPSR = 0x02; /* Minimum prescale */
>
> Any thoughts? Thank you.
>

Hi,
SPI is a synchronous interface, so in general there is no minimum speed, just gets slower.
Bob

--- In l..., nicolas.christie@... wrote:
>
> Hello all! I'm having some problems setting up ssp clock speed on a LPC1114. I want to set it to 15 MHz to communicate with an ATMEL AT45DB011D flash memory, but only get 3, no matter what I do, and I'm sure it's not a software problem since I already have this working with an LPC2368 at 15 MHz peripheral clock.
>
> On the other hand, AT45DB011D electrical specifications does not specify a minimum clock speed, just a 66 MHz max. Anyone knows what the minimum should be?
>
> I've changed M and N values on the LPC1114 and the resulting clock on spi is always around 3 MHz. Changing the peripheral divisor and prescaler work, but this doesn't help me at all since I want to increase speed.
>
> I have the following settings:
>
> 12MHz external crystal
>
> M = 6
> N = 2
>
> // Main Clock
> LPC_SYSCON->SYSPLLCLKSEL = 0x01; /* Select system OSC */
> LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL clock output */
>
> // SSP Clock
> LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
>
> // SSP Prescaler
> LPC_SSP0->CPSR = 0x02; /* Minimum prescale */
>
> Any thoughts? Thank you.
>

Hi,
The first issue I see is the M value. With a 12MHz crystal M should not be higher than 4 (12MHz x 4 = 48MHz) since the LPC1114 is rated at a max bus speed of 50MHz. Set M = 4 and P = 2. These values will give a FCCO frequency of 192MHz and bus frequency of 48MHz. Both of these are within the devices spec.

As for the SPI clock try the following:
LPC_SYSCON->SSP0CLKDIV = 0x02; // main clk Divided by 2
LPC_SSP0->CR0 = 0x0007 // 8 bit SPI with SCR = 0
LPC_SSP0->CPSR = 0x2; // SPI PCK/2 = 24MHz/2 = 12MHZ SPI clock

I haven't tried this code on the LPC1114 but I took it from some of my other LPC SPI code that is known to work. Also did you configure the I/O pins for the SPI port? I did not see that in your code snippet.

Good Luck..

Frank

Hi Bob, I know SPI is synchronous, however, the flash memory user manual
states a few commands for low/high frequency access to memory pages, so I
would expect a minimum clock speed to be needed... Regardless of that, I
want to go uppp =)

Hi Frank, M = 6 and N = 2 values used were the default values I found on
several example proyects from NXP, and so far I never had any problems. In
fact, I used M = 8 and N = 1 and it worked ok as far as UART and some GPIO
pins go.
The IO setup for ssp is taken care of, I just didn't post it because it had
not much to do with clock speed.

This would be the whole setup:

LPC_SYSCON->PRESETCTRL |= (1 << 0);
LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
LPC_IOCON->PIO0_8 &= ~0x07; /* SSP I/O config */
LPC_IOCON->PIO0_8 |= 0x01; /* SSP MISO */
LPC_IOCON->PIO0_9 &= ~0x07;
LPC_IOCON->PIO0_9 |= 0x01; /* SSP MOSI */

LPC_IOCON->SCK_LOC = 0x01; /* Set SSP0 CLK to P2.11 */
LPC_IOCON->PIO2_11 = 0x01; /* P2.11 function 1 is SSP clock */

LPC_SSP0->CR0 = 0x0707;
LPC_SSP0->CPSR = 0x02;

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

LPC_IOCON->PIO0_2 &= ~0x07; /* SSP SSEL is a GPIO pin */
/* port0, bit 2 is set to GPIO output and high */
GPIOSetDir ( PORT0, 2, 1 );
GPIOSetValue( PORT0, 2, 1 );

This yields a 3 MHz clock speed when measuring sck pin with an oscilloscope,
when 4 times that speed was expected...

Thanks for the help,

On Wed, May 5, 2010 at 11:10 PM, carnac100 wrote:

> --- In l... ,
> nicolas.christie@... wrote:
> >
> > Hello all! I'm having some problems setting up ssp clock speed on a
> LPC1114. I want to set it to 15 MHz to communicate with an ATMEL AT45DB011D
> flash memory, but only get 3, no matter what I do, and I'm sure it's not a
> software problem since I already have this working with an LPC2368 at 15 MHz
> peripheral clock.
> >
> > On the other hand, AT45DB011D electrical specifications does not specify
> a minimum clock speed, just a 66 MHz max. Anyone knows what the minimum
> should be?
> >
> > I've changed M and N values on the LPC1114 and the resulting clock on spi
> is always around 3 MHz. Changing the peripheral divisor and prescaler work,
> but this doesn't help me at all since I want to increase speed.
> >
> > I have the following settings:
> >
> > 12MHz external crystal
> >
> > M = 6
> > N = 2
> >
> > // Main Clock
> > LPC_SYSCON->SYSPLLCLKSEL = 0x01; /* Select system OSC */
> > LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL clock output */
> >
> > // SSP Clock
> > LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
> >
> > // SSP Prescaler
> > LPC_SSP0->CPSR = 0x02; /* Minimum prescale */
> >
> > Any thoughts? Thank you.
> > Hi,
> The first issue I see is the M value. With a 12MHz crystal M should not be
> higher than 4 (12MHz x 4 = 48MHz) since the LPC1114 is rated at a max bus
> speed of 50MHz. Set M = 4 and P = 2. These values will give a FCCO frequency
> of 192MHz and bus frequency of 48MHz. Both of these are within the devices
> spec.
>
> As for the SPI clock try the following:
> LPC_SYSCON->SSP0CLKDIV = 0x02; // main clk Divided by 2
> LPC_SSP0->CR0 = 0x0007 // 8 bit SPI with SCR = 0
> LPC_SSP0->CPSR = 0x2; // SPI PCK/2 = 24MHz/2 = 12MHZ SPI clock
>
> I haven't tried this code on the LPC1114 but I took it from some of my
> other LPC SPI code that is known to work. Also did you configure the I/O
> pins for the SPI port? I did not see that in your code snippet.
>
> Good Luck..
>
> Frank
>
>
>

--
Nicol Christie
n...@gmail.com
--- In l..., Nico Christie wrote:
>
> Hi Bob, I know SPI is synchronous, however, the flash memory user manual
> states a few commands for low/high frequency access to memory pages, so I
> would expect a minimum clock speed to be needed... Regardless of that, I
> want to go uppp =)
>
> Hi Frank, M = 6 and N = 2 values used were the default values I found on
> several example proyects from NXP, and so far I never had any problems. In
> fact, I used M = 8 and N = 1 and it worked ok as far as UART and some GPIO
> pins go.
> The IO setup for ssp is taken care of, I just didn't post it because it had
> not much to do with clock speed.
>
> This would be the whole setup:
>
> LPC_SYSCON->PRESETCTRL |= (1 << 0);
> LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
> LPC_IOCON->PIO0_8 &= ~0x07; /* SSP I/O config */
> LPC_IOCON->PIO0_8 |= 0x01; /* SSP MISO */
> LPC_IOCON->PIO0_9 &= ~0x07;
> LPC_IOCON->PIO0_9 |= 0x01; /* SSP MOSI */
>
> LPC_IOCON->SCK_LOC = 0x01; /* Set SSP0 CLK to P2.11 */
> LPC_IOCON->PIO2_11 = 0x01; /* P2.11 function 1 is SSP clock */
>
> LPC_SSP0->CR0 = 0x0707;
> LPC_SSP0->CPSR = 0x02;
>
> LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
>
> LPC_IOCON->PIO0_2 &= ~0x07; /* SSP SSEL is a GPIO pin */
> /* port0, bit 2 is set to GPIO output and high */
> GPIOSetDir ( PORT0, 2, 1 );
> GPIOSetValue( PORT0, 2, 1 );
>
> This yields a 3 MHz clock speed when measuring sck pin with an oscilloscope,
> when 4 times that speed was expected...
>
> Thanks for the help,
>
> On Wed, May 5, 2010 at 11:10 PM, carnac100 wrote:
>
> >
> >
> >
> >
> > --- In l... ,
> > nicolas.christie@ wrote:
> > >
> > > Hello all! I'm having some problems setting up ssp clock speed on a
> > LPC1114. I want to set it to 15 MHz to communicate with an ATMEL AT45DB011D
> > flash memory, but only get 3, no matter what I do, and I'm sure it's not a
> > software problem since I already have this working with an LPC2368 at 15 MHz
> > peripheral clock.
> > >
> > > On the other hand, AT45DB011D electrical specifications does not specify
> > a minimum clock speed, just a 66 MHz max. Anyone knows what the minimum
> > should be?
> > >
> > > I've changed M and N values on the LPC1114 and the resulting clock on spi
> > is always around 3 MHz. Changing the peripheral divisor and prescaler work,
> > but this doesn't help me at all since I want to increase speed.
> > >
> > > I have the following settings:
> > >
> > > 12MHz external crystal
> > >
> > > M = 6
> > > N = 2
> > >
> > > // Main Clock
> > > LPC_SYSCON->SYSPLLCLKSEL = 0x01; /* Select system OSC */
> > > LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL clock output */
> > >
> > > // SSP Clock
> > > LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
> > >
> > > // SSP Prescaler
> > > LPC_SSP0->CPSR = 0x02; /* Minimum prescale */
> > >
> > > Any thoughts? Thank you.
> > >
> >
> > Hi,
> > The first issue I see is the M value. With a 12MHz crystal M should not be
> > higher than 4 (12MHz x 4 = 48MHz) since the LPC1114 is rated at a max bus
> > speed of 50MHz. Set M = 4 and P = 2. These values will give a FCCO frequency
> > of 192MHz and bus frequency of 48MHz. Both of these are within the devices
> > spec.
> >
> > As for the SPI clock try the following:
> > LPC_SYSCON->SSP0CLKDIV = 0x02; // main clk Divided by 2
> > LPC_SSP0->CR0 = 0x0007 // 8 bit SPI with SCR = 0
> > LPC_SSP0->CPSR = 0x2; // SPI PCK/2 = 24MHz/2 = 12MHZ SPI clock
> >
> > I haven't tried this code on the LPC1114 but I took it from some of my
> > other LPC SPI code that is known to work. Also did you configure the I/O
> > pins for the SPI port? I did not see that in your code snippet.
> >
> > Good Luck..
> >
> > Frank
> >
> >
> >
>
>
>
> --
> Nicol Christie
> nicolas.christie@...
>

Hi Nicolas,
Did you try the configuration I suggested? I see you are setting LPC_SSP0->CR0 = 0x0707 This sets the SCR value to 7. this will cause the SPI clock to be divided by 8 times the PSR value which in your case is 2. The SPI bit rate is SPI_PCLK/(CPSR (SCR+1)).

Try setting LPC_SPP0->CR0 to 0x0007.

As for the M and P values (I assume your N is my P). NXP may have used a lower frequency crystal, maybe 8MHz on their examples or they may have lifted the code from one of the 72MHz devices and did not catch the error. If you read the user's manual you will see the formula for calculating FCLKout is M Fclkin = (FCCO)/(2 P) where FCCO is between 156 and 320 MHz.
Try the setting I sent you and let us know what SPI clock rate you get.

Frank

Hi Frank, you were (and are) right! I missed that. Changing CR0 to 0x0007
works! That is actually the one thing to change! The prescaler value alone
has no effect. I got a little mixed up in the learning. I'm actually using
0x0107, which gives a 12 MHz clock, since I loose measuring resolution with
higher values and 12 MHz should be ok :)

Thank you for the help!

On Thu, May 6, 2010 at 3:55 PM, carnac100 wrote:

> --- In l... , Nico Christie
> wrote:
> >
> > Hi Bob, I know SPI is synchronous, however, the flash memory user manual
> > states a few commands for low/high frequency access to memory pages, so I
> > would expect a minimum clock speed to be needed... Regardless of that, I
> > want to go uppp =)
> >
> > Hi Frank, M = 6 and N = 2 values used were the default values I found on
> > several example proyects from NXP, and so far I never had any problems.
> In
> > fact, I used M = 8 and N = 1 and it worked ok as far as UART and some
> GPIO
> > pins go.
> > The IO setup for ssp is taken care of, I just didn't post it because it
> had
> > not much to do with clock speed.
> >
> > This would be the whole setup:
> >
> > LPC_SYSCON->PRESETCTRL |= (1 << 0);
> > LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
> > LPC_IOCON->PIO0_8 &= ~0x07; /* SSP I/O config */
> > LPC_IOCON->PIO0_8 |= 0x01; /* SSP MISO */
> > LPC_IOCON->PIO0_9 &= ~0x07;
> > LPC_IOCON->PIO0_9 |= 0x01; /* SSP MOSI */
> >
> > LPC_IOCON->SCK_LOC = 0x01; /* Set SSP0 CLK to P2.11 */
> > LPC_IOCON->PIO2_11 = 0x01; /* P2.11 function 1 is SSP clock */
> >
> > LPC_SSP0->CR0 = 0x0707;
> > LPC_SSP0->CPSR = 0x02;
> >
> > LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
> >
> > LPC_IOCON->PIO0_2 &= ~0x07; /* SSP SSEL is a GPIO pin */
> > /* port0, bit 2 is set to GPIO output and high */
> > GPIOSetDir ( PORT0, 2, 1 );
> > GPIOSetValue( PORT0, 2, 1 );
> >
> > This yields a 3 MHz clock speed when measuring sck pin with an
> oscilloscope,
> > when 4 times that speed was expected...
> >
> > Thanks for the help,
> >
> > On Wed, May 5, 2010 at 11:10 PM, carnac100 wrote:
> >
> > >
> > >
> > >
> > >
> > > --- In l... > 40yahoogroups.com>,
>
> > > nicolas.christie@ wrote:
> > > >
> > > > Hello all! I'm having some problems setting up ssp clock speed on a
> > > LPC1114. I want to set it to 15 MHz to communicate with an ATMEL
> AT45DB011D
> > > flash memory, but only get 3, no matter what I do, and I'm sure it's
> not a
> > > software problem since I already have this working with an LPC2368 at
> 15 MHz
> > > peripheral clock.
> > > >
> > > > On the other hand, AT45DB011D electrical specifications does not
> specify
> > > a minimum clock speed, just a 66 MHz max. Anyone knows what the minimum
> > > should be?
> > > >
> > > > I've changed M and N values on the LPC1114 and the resulting clock on
> spi
> > > is always around 3 MHz. Changing the peripheral divisor and prescaler
> work,
> > > but this doesn't help me at all since I want to increase speed.
> > > >
> > > > I have the following settings:
> > > >
> > > > 12MHz external crystal
> > > >
> > > > M = 6
> > > > N = 2
> > > >
> > > > // Main Clock
> > > > LPC_SYSCON->SYSPLLCLKSEL = 0x01; /* Select system OSC */
> > > > LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL clock output */
> > > >
> > > > // SSP Clock
> > > > LPC_SYSCON->SSP0CLKDIV = 0x01; /* Divided by 1 */
> > > >
> > > > // SSP Prescaler
> > > > LPC_SSP0->CPSR = 0x02; /* Minimum prescale */
> > > >
> > > > Any thoughts? Thank you.
> > > >
> > >
> > > Hi,
> > > The first issue I see is the M value. With a 12MHz crystal M should not
> be
> > > higher than 4 (12MHz x 4 = 48MHz) since the LPC1114 is rated at a max
> bus
> > > speed of 50MHz. Set M = 4 and P = 2. These values will give a FCCO
> frequency
> > > of 192MHz and bus frequency of 48MHz. Both of these are within the
> devices
> > > spec.
> > >
> > > As for the SPI clock try the following:
> > > LPC_SYSCON->SSP0CLKDIV = 0x02; // main clk Divided by 2
> > > LPC_SSP0->CR0 = 0x0007 // 8 bit SPI with SCR = 0
> > > LPC_SSP0->CPSR = 0x2; // SPI PCK/2 = 24MHz/2 = 12MHZ SPI clock
> > >
> > > I haven't tried this code on the LPC1114 but I took it from some of my
> > > other LPC SPI code that is known to work. Also did you configure the
> I/O
> > > pins for the SPI port? I did not see that in your code snippet.
> > >
> > > Good Luck..
> > >
> > > Frank
> > >
> > >
> > >
> >
> >
> >
> > --
> > Nicol Christie
> > nicolas.christie@...
> > Hi Nicolas,
> Did you try the configuration I suggested? I see you are setting
> LPC_SSP0->CR0 = 0x0707 This sets the SCR value to 7. this will cause the SPI
> clock to be divided by 8 times the PSR value which in your case is 2. The
> SPI bit rate is SPI_PCLK/(CPSR (SCR+1)).
>
> Try setting LPC_SPP0->CR0 to 0x0007.
>
> As for the M and P values (I assume your N is my P). NXP may have used a
> lower frequency crystal, maybe 8MHz on their examples or they may have
> lifted the code from one of the 72MHz devices and did not catch the error.
> If you read the user's manual you will see the formula for calculating
> FCLKout is M Fclkin = (FCCO)/(2 P) where FCCO is between 156 and 320
> MHz.
> Try the setting I sent you and let us know what SPI clock rate you get.
>
> Frank
>
>
>

--
Nicol Christie
n...@gmail.com