Content originally posted in LPCWare by anandana on Thu Nov 28 02:26:13 MST 2013
Hi Martin,
Thank U for ur response. U r right, Actually I was using UM LPC17xx. Now I configured SSP0 in SPI mode. But still it is not working.. Here i am giving the configuration details. Please check and tell if anything is wrong.
(LPC_SC->PCONP) = 0x0528929E; //21st bit is high to enable SSP0
LPC_IOCON->P0_15 |= 2;
LPC_IOCON->P0_16 |= 2;
LPC_IOCON->P0_18 |= 2;
void SSP_ConfigStructInit(SSP_CFG_Type *SSP_InitStruct)
{
SSP_InitStruct->CPHA = SSP_CPHA_FIRST; //0
SSP_InitStruct->CPOL = SSP_CPOL_HI; //0
SSP_InitStruct->ClockRate = 1000000; //1 Mhz
SSP_InitStruct->Databit = SSP_DATABIT_8; //8 8bit data length
SSP_InitStruct->Mode = SSP_MASTER_MODE; //0 Master Mode
SSP_InitStruct->FrameFormat = SSP_FRAME_SPI; //Motorola SPI Mode
}
void SSP_Init(LPC_SSP_TypeDef *SSPx, SSP_CFG_Type *SSP_ConfigStruct)
{
uint32_t tmp;
/* Configure SSP, interrupt is disable, LoopBack mode is disable,
* SSP is disable, Slave output is disable as default
*/
tmp = ((SSP_ConfigStruct->CPHA) | (SSP_ConfigStruct->CPOL) \
| (SSP_ConfigStruct->FrameFormat) | (SSP_ConfigStruct->Databit))
& SSP_CR0_BITMASK;
// write back to SSP control register
SSPx->CR0 = tmp;
tmp = SSP_ConfigStruct->Mode & SSP_CR1_BITMASK;
// Write back to CR1
SSPx->CR1 = tmp;
// Set clock rate for SSP peripheral
setSSPclock(SSPx, SSP_ConfigStruct->ClockRate);
}
static void setSSPclock (LPC_SSP_TypeDef *SSPx, uint32_t target_clock)
{
uint32_t prescale, cr0_div, cmp_clk, ssp_clk;
// ssp_clk = PeripheralClock;
/* Find closest divider to get at or under the target frequency.
Use smallest prescale possible and rely on the divider to get
the closest target frequency */
cr0_div = 0;
cmp_clk = 0xFFFFFFFF;
prescale = 2;
while (cmp_clk > target_clock)
{
cmp_clk = ssp_clk / ((cr0_div + 1) * prescale);
if (cmp_clk > target_clock)
{
cr0_div++;
if (cr0_div > 0xFF)
{
cr0_div = 0; prescale += 2;
}
}
}
/* Write computed prescaler and divider back to register */
SSPx->CR0 &= ~(SSP_CR0_SCR(0xFF)) & SSP_CR0_BITMASK;
SSPx->CR0 |= (SSP_CR0_SCR(cr0_div)) & SSP_CR0_BITMASK;
SSPx->CPSR = prescale & SSP_CPSR_BITMASK;
}
void SPI0Send(unsigned char TxDat) //write command
{
LPC_SSP0->DR = 0xAA;
for(;LPC_SSP0->SR==0x10;); Checking for Busy stae..
}
My code struck in above mentioned for loop.. Busy bit not cleared in SR register..
Please check and tell me
Regards
Anandan