SCP1000 pressure sensor and LPC2103 uC problems

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?

ok… Does anyone know how to interface an LPC with the sensor?

Hi there,

I was working with my SCP1000 on one of the ADuC7026 boards, and eventually came to the conclusion that since the ADuC SPI module always reads and writes on opposite phases of the clock (unlike a dsPIC where MISO, MOSI phase can be set independently), it was not possible to interface with this sensor.

I don’t know if the pins you mentioned are SPI port pins or just GPIO for bit banging. If it’s for bit banging here’s some code to guide you:

void Delay (unsigned long a) { while (–a!=0); }

#define SETCS() (GP4SET = 1 << (6 + 16))

#define CLRCS() (GP4CLR = 1 << (6 + 16))

#define MOSI(x) \

do{\

GP1SET = (x) << (6 + 16);\

GP1CLR = (~(x)) << (6+16);\

}while(0)

#define SETCLK() (GP1SET = 1 << (4 + 16))

#define CLRCLK() (GP1CLR = 1 << (4 + 16))

#define MISO ((GP1DAT & 0x00000020)>>(5))

SPC_1000_INIT(void)

{

SPCInitialized=0;

unsigned char SPIout;

ctl_board_set_led1(1);

//Read ASIC Revision

SETCS();

CLRCLK();

Delay(1000000);

CLRCS();

SPIout=SendSPI8((0x00<<2)&0xFC);

SPIout=SendSPI8(0x00);

SETCS();

Delay(100);

//Read ASIC Startup

SETCS();

CLRCLK();

Delay(100);

CLRCS();

SPIout=SendSPI8((0x07<<2)&0xFC);

SPIout=SendSPI8(0x00);

SETCS();

Delay(100);

//It’s go time!

//Set Continuous High Speed Measurements

SETCS();

CLRCLK();

Delay(100);

CLRCS();

SPIout=SendSPI8((0x03<<2)|0x02);

SPIout=SendSPI8(0x09);

SETCS();

Delay(100);

SPCInitialized=1;

while((GP4DAT&0x80)==0){} //wait for data to become ready

//Read Temperature Data

SPCSource=0; //indiacate temperature goal

SETCS();

CLRCLK();

Delay(100);

CLRCS();

SPCTemp[0]=SendSPI8((0x21<<2)&0xFC);

SPCTemp[1]=SendSPI8(0x00);

SPCTemp[2]=SendSPI8(0x00);

//temperature in celsius = SPCTemp[1]*256 + SPCTemp[2];

SETCS();

Delay(100);

//Read Pressure Data

SPCSource=1; //indiacate temperature goal

SETCS();

CLRCLK();

Delay(100);

CLRCS();

SPCPres[0]=SendSPI8((0x1F<<2)&0xFC);

SPCPres[1]=SendSPI8(0x00);

SETCS();

Delay(100);

CLRCS();

SPCPres[1]=SPCPres[1]&0x07; //Data bits are only 2:0

SPCPres[2]=SendSPI8((0x20<<2)&0xFC);

SPCPres[2]=SendSPI8(0x00); //Overwrite wasted byte

SPCPres[3]=SendSPI8(0x00);

SPCPres[3]=SPCPres[3]&0xF0; //Discard lower four bits in high res mode

SETCS();

unsigned int pressuredec=0;

pressuredec=SPCPres[1]*65536;

pressuredec=pressuredec+SPCPres[2]*256;

pressuredec=pressuredec+SPCPres[3];

unsigned int pressurePA=0;

pressurePA=pressuredec >>2; //Divide by four

Delay(100);

ctl_board_set_led0(0);

}

unsigned char

SendSPI8(unsigned char indata)

{

unsigned char recdata=0;

unsigned int index=0;

for(index=0; index <8; index++)

{

MOSI(((indata&0x80)>>7));

Delay(10);

indata=indata<<1;

SETCLK();

Delay(100);

recdata=recdata<<1;

recdata |=MISO;

CLRCLK();

Delay(100);

}

return(recdata);

}