SPI Clock not coming on P0.15 port Pin

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

SPI Clock not coming on P0.15 port Pin

1,353 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Fri Jun 12 22:16:45 MST 2015
Hi,

i made one code for SPI interface(Not using SSP) in master mode .Following is the code used.But when i check the SPI SCK on oscilloscope, it does not give any output.


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

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

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;


int main(){

LPC_SC->PCONP |= (1<<8); //Power SPI peripheral

LPC_SC->PCLKSEL0 |= (1<<16); //PCLK for SPI0 = CCLK

LPC_PINCON->PINSEL0=(3<<30);
LPC_PINCON->PINSEL1=(3<<0)|(3<<2)|(3<<4);
LPC_PINCON->PINMODE0 = (3<<30);
LPC_PINCON->PINMODE3 = (3<<0)|(3<<2)|(3<<4);

LPC_SPI->SPCCR= 4;               //SCK= PCLK/4
LPC_SPI->SPCR |= 0x38;         //master mode


int data_in = 0;

    while(1){

        LPC_SPI->SPDR = 0xAAAA;
        while ( (LPC_SPI->SPIF & 0x0080)!=0x0080 );
        data_in = LPC_SPI0->S0SPDR;

    }

}


Please Can any one help?

Thanks a lot.

Gitanjali
Labels (1)
0 Kudos
22 Replies

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nitin52 on Mon Aug 17 00:17:54 MST 2015
Hello Gitanjali,
What was the problem and how did you solve it.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 04:42:23 MST 2015
Its working,
I was trying it for so many days and checking again & again the register.

Thanks a lot.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 04:40:39 MST 2015
Hi ,

Thanks A lot this is Working.

0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 14 04:34:01 MST 2015

Quote: gitanjali
i did as you said but still no clock is coming.



I'm not sure what you are mesuring, but your code is working here 

This is a working SPI sample, which is doing the same (400KHz SPI). The short delay isn't necessary, but useful...

volatile uint8_t data_out = 0xA5;
volatile uint8_t data_in;

int main(void)
{
 volatile static int i = 0 ;
 LPC_SC->PCONP |= (1<<8); //switch SPI on
 LPC_SC->PCLKSEL0 |= (1<<16); //PCLK  = CCLK
 LPC_PINCON->PINSEL0 &= ~(3<<30);//reset
 LPC_PINCON->PINSEL0 |=  (3<<30);//set SCLK
 LPC_PINCON->PINSEL1 &= ~((3<<0)|(3<<2)|(3<<4)); //reset
 LPC_PINCON->PINSEL1 |=  ((3<<0)|(3<<2)|(3<<4)); //set SSEL, MISO, MOSI
 LPC_SPI->SPCCR= 250; //>=8 100E6/250 = 400kHz
 LPC_SPI->SPCR = 0x38; //master 8bit

 while(1)
 {
  LPC_SPI->SPDR = data_out;
  while ((LPC_SPI->SPSR & 0x80)!=0x80);
  data_in = LPC_SPI->SPDR;
  for(i=0;i<100;i++){}//short delay
 }
 return 0;
}


If you connect P0.17 and P0.18 SPI is receiving the transmitted data...

If this sample isn't working either your hardware is faulty or your SystemInit() is wrong...
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 04:14:46 MST 2015
i did as you said but still no clock is coming.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 14 04:04:25 MST 2015

Quote: gitanjali
On port P0.15 that the SCK port the clock is not coming .
Actually I'm using Oscilloscope for the same.



Then use a slower SCK (400kHz @ 100MHz main clock):

LPC_SPI->SPCCR= 250;

0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 03:57:54 MST 2015
On port P0.15 that the SCK port the clock is not coming .
Actually I'm using Oscilloscope for the same.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 14 03:48:06 MST 2015
And what's not working with this code?
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 03:44:20 MST 2015
Really Srrym for the code .Please see this one.


Thanks a lot.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 14 03:36:38 MST 2015
Can't compile that  :((


Quote:
../src/main.c:46:18: error: '[color=#f00]LPC_SPSR' undeclared [/color](first use in this function)
         while ( (LPC_SPSR & 0x0080)!= 0x0080 );

0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 03:26:08 MST 2015
i trying to interface a abs encoder to Lpc1769.

But firstly i was checking on configuring spi of Lpc ,whether the clock is coming on the port or not.

0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 03:22:05 MST 2015
Here the code.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 14 03:05:52 MST 2015

Quote: gitanjali
i write it wrong actually it like this

while ( (LPC_SPI->SPSR & 0x0080)!=0x0080 ); // just seeing that the spif register is one or not.
data_in = LPC_SPI->SPDR;


do you have any code for spi not the one given by LPC peripheral lib?



Please stop posting code snippets  :O

Post your file (use code tags) or better your complete project. Otherwise that's a guessing game here...

A working SPI setting and read / write code requires less than 10 lines of code. If you don't post your complete code and don't describe what you are measuring it's difficult and annoying to help you...
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 02:53:49 MST 2015
i write it wrong actually it like this

while ( (LPC_SPI->SPSR & 0x0080)!=0x0080 ); // just seeing that the spif register is one or not.
data_in = LPC_SPI->SPDR;


do you have any code for spi not the one given by LPC peripheral lib?
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 14 00:54:41 MST 2015

Quote: gitanjali
I'm using LPC1769 and LPCXpresso IDE.
lpc17XX.h

I tries for SPCCR value more than 8 too, but its still not working.



I'm not sure what you are doing in detail here:

 while ( (LPC_SPI->SPIF & 0x0080)!=0x0080 );
 data_in = LPC_SPI0->S0SPDR;


Probably that should be the part to wait for SPIF...

It's not very difficult to get SPI working,  just setup SPI, write data and wait for SPIF...

My library and my User manual has no LPC_SPI->SPIF register, so I've no clue what you are doing there  :~ 
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sun Jun 14 00:36:40 MST 2015
I'm using LPC1769 and LPCXpresso IDE.
lpc17XX.h

I tries for SPCCR value more than 8 too, but its still not working.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat Jun 13 09:19:43 MST 2015

Quote: 1234567890

I'm not sure if a pull-down on SCK is the right choice.



:D

It's an output (master), so you can pull it up, down, right or left...
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 1234567890 on Sat Jun 13 08:50:26 MST 2015

Quote:
SPI Clock not coming on P0.15 port Pin


I'm not sure if a pull-down on SCK is the right choice.
0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat Jun 13 03:19:57 MST 2015
If your setup is nonsense, SPI isn't working  :)


Quote: gitanjali

LPC_SPI->SPCCR= 4;               //SCK= PCLK/4



UM LPC1768:

Quote:

17.7.4 SPI Clock Counter Register (S0SPCCR - 0x4002 000C)
This register controls the frequency of a master’s SCK. The register indicates the number of SPI peripheral clock cycles that make up an SPI clock.
[color=#f00]In Master mode, this register must be an even number greater than or equal to 8.[/color]



Could be useful if you describe hardware and software and post a project or at least a file...

Which MCU are you using?

Which library?




0 Kudos

1,114 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gitanjali on Sat Jun 13 01:34:54 MST 2015
i changed the value of SPCCR also (more then 8 ,even number ) but it is not working.

Similar code when i use it for SSP0(changing the pin and registers respectively ) then it is working.


Can u suggest something on this.


0 Kudos