LPC 1788 SSP(SPI)

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

LPC 1788 SSP(SPI)

1,678 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shkang on Wed Nov 21 23:50:39 MST 2012
please help me.

Recently, I try to communicate with a sensor by LPC 1788 SSP(SPI).

During control the board. SSP is not working. But I don't know what is problem.

is it ok to control SPI Communication??? Am I miss somthing?

//-----------------------------------------------------------------------------

PINSEL_ConfigPin(PORT_0, 15, 2);
PINSEL_ConfigPin(PORT_0, 17, 2);
PINSEL_ConfigPin(PORT_0, 18, 2);
PINSEL_ConfigPin(PORT_1, 18, 0); // Frame Ready
PINSEL_ConfigPin(PORT_2, 21, 0); // LED
PINSEL_ConfigPin(PORT_2, 14, 0); // CS

GPIO_SetDir(PORT_1, _PORT(18), GPIO_DIRECTION_INPUT);
GPIO_SetDir(PORT_2, _PORT(21), GPIO_DIRECTION_OUTPUT);
GPIO_SetDir(PORT_2, _PORT(14), GPIO_DIRECTION_OUTPUT);

GPIO_ClearValue(PORT_2, _PORT(21));          // LED
GPIO_SetValue(PORT_2, _PORT(14));          // CS


// initialize SSP configuration structure to default
SSP_ConfigStructInit(&SSP_ConfigStruct);
// Initialize SSP peripheral with parameter given in structure above
SSP_Init(LPC_SSP, &SSP_ConfigStruct);
// Enable SSP peripheral
SSP_Cmd(LPC_SSP, ENABLE);


GPIO_ClearValue(PORT_2, _PORT(14));          // CS Low
GPIO_SetValue(PORT_2, _PORT(21));          // LED OFF
   
SSP_SendData(LPC_SSP,0x99);
data2[0] = SSP_ReceiveData(LPC_SSP);
SSP_SendData(LPC_SSP,0x02);
data2[1] = SSP_ReceiveData(LPC_SSP);
SSP_SendData(LPC_SSP,0x8F);
data2[2] = SSP_ReceiveData(LPC_SSP);

GPIO_SetValue(PORT_2, _PORT(14));          // CS High
Labels (1)
0 Kudos
Reply
5 Replies

1,136 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lien.Nguyen on Thu Nov 22 20:46:31 MST 2012
Hi,
I mean you should check SR to make sure all data sent. When you write to DR, it just write to the FIFO.
And, before you read data, you also make sure that there is available data for your read. 
Best Regards,
Lien
0 Kudos
Reply

1,136 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shkang on Thu Nov 22 20:19:10 MST 2012
Thank you so much giving reply quickly.

I did CS pin in active state until all data sent. There is send and receive function below.

Regards,

--------------------------------------------------------
#define SSP_DR_BITMASK(n)   ((n)&0xFFFF)

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

uint16_t SSP_ReceiveData(LPC_SSP_TypeDef* SSPx)
{
return ((uint16_t) (SSP_DR_BITMASK(SSPx->DR)));
}
0 Kudos
Reply

1,136 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lien.Nguyen on Thu Nov 22 19:54:18 MST 2012
There is no information about your send and receive function. The CS must be in active state until all data sent.

Best Regards,
Lien
0 Kudos
Reply

1,136 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shkang on Thu Nov 22 18:59:10 MST 2012
Lien,
Thank you for reply.

My setting is below. I used CPOL =1, CPHA = 1. This is the first time I'm using a SPI on an ARM processor. I am not sure, I'm going to be right way.

-----------------------------------------------------

void SSP_ConfigStructInit(SSP_CFG_Type *SSP_InitStruct)
{
    SSP_InitStruct->CPHA = SSP_CR0_CPHA_SECOND; // CPHA_HIGH
    SSP_InitStruct->CPOL = SSP_CR0_CPOL_HI; // CPOL_HIGH
    SSP_InitStruct->ClockRate = 1000000;
    SSP_InitStruct->Databit = SSP_DATABIT_8;
    SSP_InitStruct->Mode = SSP_MASTER_MODE;
    SSP_InitStruct->FrameFormat = SSP_FRAME_SPI;
}

Regards!
0 Kudos
Reply

1,136 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lien.Nguyen on Thu Nov 22 03:47:20 MST 2012
What are settings of CPOL & CPHA? In case CPHA =0, the SSEL signal must be pulsed HIGH between each data word transfer.

Best Regards,
Lien
0 Kudos
Reply