Greetings:
Intro.
I’m attempting to interface a SCP1000 sensor (on sparkfun’s breakout board) with an olimex LPC2103 development board. The dev board is using the standard 14.7456 MHz crystal. and the PLLCFG is set to 0x23.
I have connected the breakout board’s DRDY pin to P0.16 on the dev board.
I also set IODIR to 0xFFFEFFFF
Breakout board --------------------------------Dev Board
SCK…P0.14
MOSI…P0.20
MISO…P0.19
CSB…P0.21
Problem.
No matter what I do, I cannot interface with the sensor. I believe my problem is the either the SPI initialization or the functions I use to write to and read from the device.
Here are my functions:
////////////////////////////////////////////////////////////////////////////////
void spi_init(void){ //This configures SPI1
PINSEL0 |= 0x20000000; //Configure P0.14
PINSEL1 |= 0x00000140; //Configure P0.20 and P0.19
IODIR |= CS;
IOSET |= CS;
SSPCR0 = 0x070F; // cpol = 0, cpha = 0 16bit transfer SCR=7
SSPCPSR = 7; // prescale
SSPCR1 = 2; // enable
}
////////////////////////////////////////////////////////////////////////////////
void spi(long data){ //This sends data to SPI 1
IOCLR |= CS;
SSPDR = data;
while ((SSPSR & 0x10)) ; // wait for transfer completed
IOSET |= CS;
}
////////////////////////////////////////////////////////////////////////////////
long scp_read(int address){
long input_buffer=0; //declare and reset the input buffer
address<<2; //Shift address over 2 places
input_buffer=input_buffer&address; //merge the output buffer and the address/rw buffer
input_buffer<<8; //Shift the address to the end of the buffer
spi(input_buffer); //Send the data
input_buffer=0; //reset the input buffer
input_buffer=SSPDR; //copy the SSPDR (recieved data) to the input buffer
return(input_buffer); //Return this value
}
////////////////////////////////////////////////////////////////////////////////
void scp_write(int address,int data){
long output_buffer=0; //declare and reset the output buffer
address<<2; //Shift address over 2 places
address&0x02; //Set bit 1 high to indicate this is a write
output_buffer=output_buffer&address; //merge the output buffer
output_buffer<<8; //Shift the address to the end of the buffer
output_buffer=output_buffer&data; //merge the output buffer
spi(output_buffer); //Send the data
}
////////////////////////////////////////////////////////////////////////////////
I’m using rowley crossworks.
Where have I gone wrong?