This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

lpc2148 spi problem

I have interfaced lpc2148 with MCP3208(adc) the port pins i have used are smae
as that have mentioned for spi0(P0.4...P0.7),but I have faced some problems
1.my SSEL0 pin was always zero(I have programmed it as GPIO),then I have used
another pin for chip selection.I have used multislave communication and
established successful communication with the other device(i.e. MCP4922)
can't I use SSEL0 pin as GPIO?
2.Second problem which I am facing is the clock frequency,I want to communicate
at 10 KHz SPI clock ,but not able to generate clock less than 83 KHz.I have used
default startup file provided by KEIL.

here is my code

#define SPICLK (1 << 4)
#define SSDAC2 (1 << 31)
#define MOSI (1 << 6)
#define MISO (1 << 5)
//#define SSADC1 (1 << 7)
#define SSADC1 (1 << 24)


#define SPI_MASTER (1 << 5)
#define LSB_FIRST (1 << 6)
#define DATA_8BIT (1 << 11)

#define CS_DAC 0x80000000
#define CS_ADC 0x00000080

#define SET_SPICLK (FIO0SET = (SPICLK))
#define CLR_SPICLK (FIO0CLR = (SPICLK))

#define SET_SSDAC2 (FIO0SET = (SSDAC2))
#define CLR_SSDAC2 (FIO0CLR = (SSDAC2))

#define SET_SSADC1 (FIO1SET = (SSADC1))
#define CLR_SSADC1 (FIO1CLR = (SSADC1))

#define SET_MOSI (FIO0SET = (MOSI))
#define CLR_MOSI (FIO0CLR = (MOSI))


void init_spi(void)
{
/* initialize the serial interface */
PINSEL0 &= 0xffff00ff; /* Enable MOSI,MISO and clock and TxD1
*/
PINSEL0 |= 0x000001500; /* Enable RxD1(P0_9) , TxD1(P0_8)
*/

PINSEL1 &= 0x3fffffff; /* P0.31 gpio*/
FIO0DIR |= (SSDAC2); //P0.31 and P0.7 as outputs
FIO1DIR |= SSADC1; //p1.24

FIO0SET = ((SSDAC2)); //P0.31 and P0.7 as outputs

FIO1SET = ((SSADC1)); //P0.31 and P0.7 as outputs

S0SPCR = ((SPI_MASTER) | (DATA_8BIT)); //8bit data in master mode
S0SPCCR = 0x000001bc; //spi at 10 KHz
PCONP |= 0x00000010; // turn on SPI0
}

void preset_dac(unsigned int dac_count,unsigned char ch_no)
{
unsigned int x;
unsigned char ch;
x = dac_count;
x &= 0x0FFF;

x |= 0x2000; // DAC Gain of 1.00
x |= 0x1000; // Shut down bit is set high.

if(ch_no == 'B')
x |= 0x8000; //for DACb x ored with 8000

CLR_SSDAC2;
ch = (x >> 8);
S0SPDR = ch;
while(!(S0SPSR & 0x80));

S0SPDR = (x & 0xff);
while(!(S0SPSR & 0x80));

SET_SSDAC2;
}

unsigned int get_adc_value(unsigned char ch_no)
{
unsigned int ch;
unsigned char myint_low,myint_high;

ch_no &= 0x03;

CLR_SSADC1;

S0SPDR = 0x06;
while(!(S0SPSR & 0x80));

S0SPDR = ch_no << 6;
while(!(S0SPSR & 0x80));
myint_high = S0SPDR;

S0SPDR = 0xff;
while(!(S0SPSR & 0x80));
myint_low = S0SPDR;

SET_SSADC1;
ch = myint_high << 8;
ch |= (myint_low);
return(ch);
}

    0