Content originally posted in LPCWare by researchinnovation on Mon Nov 26 03:53:24 MST 2012
Why, following code is checking for only one if condition, it is not checking all the conditions. Why so.
#include "driver_config.h"
#include "target_config.h"
#include "gpio.h"
#include "timer32.h"
#include "ssp.h"
#if SSP_DEBUG
#include "uart.h"
#endif
#include <stdio.h>
#define SSP_NUM 0
uint8_t i=0;
uint16_t buff[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint16_t mm;
int main (void)
{
SystemInit();
SSP_IOConfig( 0 ); /* initialize SSP port, share pins with SPI1
on port2(p2.0-3). */
//SSP_Init( SSP_NUM );
//GPIOSetDir(PORT0,2,0);
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;
LPC_IOCON->SCK_LOC = 0x02;
LPC_IOCON->PIO0_6 = 0x02;
LPC_IOCON->PIO0_2 &= ~0x07;
LPC_IOCON->PIO0_2 |= 0x01;
if ( LPC_SSP0->CR1 & SSPCR1_SSE )
{
/* The slave bit can't be set until SSE bit is zero. */
LPC_SSP0->CR1 &= ~SSPCR1_SSE;
}
LPC_SSP0->CR1 = SSPCR1_MS; /* Enable slave bit first */
LPC_SSP0->CR1 |= SSPCR1_SSE;
LPC_SSP0->CR0 = 0x04CF;
LPC_SSP0 ->CR1 = 0x06;
while(1)
{
while ( !(LPC_SSP0->SR & SSPSR_RNE) );
{//printf(" I am in buff loop buff");
buff = (uint16_t)LPC_SSP0->DR;
i++;
mm = buff;
if( mm = 0x0400)
{
while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
LPC_SSP0->DR = 0x4567;
}
if( mm = 0x0600)
{
while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
LPC_SSP0->DR = 0x1234;
}
if( mm = 0x0800)
{
while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
LPC_SSP0->DR = 0x9875;
}
if( mm = 0x0A00)
{
while( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );
LPC_SSP0->DR = 0x45FF;
}
}
}
return 0;
}