ssp(spi) on lpc1785

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

ssp(spi) on lpc1785

591 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by castiel on Mon Dec 03 21:51:08 MST 2012
Please help.I try to transfer 3 bytes back-to-back(1st byte-command,2-3 addres) via ssp.Data is transmitted but incorrectly.Where is my mistake? Here is my code.

#include <LPC177x_8x.h>
#include "lpc177x_8x_clkpwr.h"
#include "lpc177x_8x_ssp.h"
#define SSP_DR_BITMASK(n)   ((n)&0xFFFF)

void SSP_SendData(LPC_SSP_TypeDef* SSPx, uint16_t Data)
{
SSPx->DR = SSP_DR_BITMASK(Data);
}



int main(void) {
LPC_SC->PCONP   |= (1<<15);            /* enable power to GPIO & IOCON  */
LPC_SC->PCONP |=(1<<21);//enable ssp0
/* APB 48МHz*/
LPC_SSP0->CPSR |= (0x2);  //clock prescaler SSP0=2

LPC_IOCON->P0_15 |= (1<<1) ; //sck    
LPC_IOCON->P0_16 |= (1<<1);//ssel
LPC_IOCON->P0_17 |= (1<<1);//miso
        LPC_IOCON->P0_18 |=(1<<1);//mosi

LPC_SSP0->CR0 |= (0x787);  // CPOL=0,CPHA=1,Frame Format=SPI,Serial Clock Rate=7,8 bit mode     
  LPC_SSP0->CR1 |= (1<<1);//sse enable,master mode
//master clock rate 3МHz

SSPTransfer(0x2);
SSPTransfer(0x0);
SSPTransfer(0x2);

}
Labels (1)
0 Kudos
6 Replies

551 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lien.Nguyen on Mon Dec 10 19:45:53 MST 2012
Why don't you refer to http://sw.lpcware.com/?p=lpc177x_8x.git&a=tree and check it by yourself?

Best Regards,
Lien
0 Kudos

551 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by castiel on Mon Dec 10 07:07:10 MST 2012
i wrote function,which send three bytes.Is it right?

#define SSPSR_TNF      (1 << 1)  // Transmit FIFO not full
#define SSPSR_RNE      (1 << 2)  // Receive FIFO not empty
#define SSPSR_BSY      (1 << 4)  // Busy
uint8_t ret[3];
......
...
void ssp(int a,int b,int c) {
cs_clr;
while ((LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF);
SSP_SendData(LPC_SSP0,a);
while ((LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE);
ret[0] = LPC_SSP0->DR;
while ((LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF);
SSP_SendData(LPC_SSP0,b);
while ((LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE);
ret[1] = LPC_SSP0->DR;

while ((LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF);
SSP_SendData(LPC_SSP0,c);
while ((LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE);
ret[2] = LPC_SSP0->DR;


cs_set;
}
0 Kudos

551 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lien.Nguyen on Fri Dec 07 02:31:52 MST 2012
I think so. But, if you would like to send more data later, you should check the SR register.

Best Regards,
Lien
0 Kudos

551 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by castiel on Thu Dec 06 21:42:44 MST 2012
that is, all right?
0 Kudos

551 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lien.Nguyen on Tue Dec 04 20:36:00 MST 2012
I ran your code and checked bytes sent. All bytes are the same to expectation. :D
0 Kudos

551 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by castiel on Tue Dec 04 02:50:56 MST 2012
Oh,last lines should be:
SSP_SendData(LPC_SSP0,0x2);
SSP_SendData(LPC_SSP0,0x0);
SSP_SendData(LPC_SSP0,0x2);

What I do wrong? Prompt please.
0 Kudos