[SENSOR]/기타센서2009. 3. 22. 19:36

[SCP1000-D01] 압력센서 테스트

[SCP1000-D01] 압력센서 테스트




테스트 동영상
SCP1000-D01 압력센서를 이용하여 바닥에서(설정값)  고도에 대한 차이값을 표시




압력값의 표시는 지난번 제작해 두었던 SPI제어 FND모듈 이용하여 압력의 차이값표시를 간단하게 했다.


FND모듈 핀맵



엘리베이터 1~5층 까지 압력 측정 데이터





SCP1000 예제 소스코드 (AVR Mega128)

void Write_Direct_Access_SPI(unsigned char address, unsigned char data)
{
 address = (address << 2); // #1, shift the SCP1000 reg address to left by 2
 address |= 0x02; // #2, set write bit to one (RW=1)
 //set CSB to low
 PRESSURE_CS_ASSERT();
 
 // #4, write register address byte (8bits)
 SPI0_WriteByte(address);
 
 // #5, write data byte (8bit) to line
 SPI0_WriteByte(data);
 
 // Set CSB to HIGH
 PRESSURE_CS_DEASSERT();
}
unsigned int Read_Direct_Access_SPI(unsigned char address, unsigned char number_of_bytes)
{
 unsigned int value;
 value = 0;
 address = (address << 2); //shift the SCP1000 reg address to left by 2
 
 PRESSURE_CS_ASSERT();
 
 //write register address byte (8bits)
 SPI0_WriteByte(address);

 while(number_of_bytes-- > 0)
 {
  value <<= 8;
  // Read data byte from MCU SPI register
  value |= SPI0_WriteReadByte(0);
 }
 
 // Set CSB to HIGH
 PRESSURE_CS_DEASSERT();
 return value;
}
unsigned int Read_Indirect_Access_SPI(unsigned char address)
{
 unsigned long value;
 Write_Direct_Access_SPI(0x02, address); // #1, write reg address to ADDPTR (0x02)
 Write_Direct_Access_SPI(0x03, 0x01); // #2, write 0x01 to OPERATION (0x03)
 Delay(10); // #3, wait 10ms
 value = Read_Direct_Access_SPI(0x20, 0x02); // #4, read two bytes from DATARD16 (0x20)
 return value;
}
void Write_Indirect_Access_SPI(unsigned char address, unsigned char data)
{
 Write_Direct_Access_SPI(0x02, address); // #1, write reg address to ADDPTR (0x02)
 Write_Direct_Access_SPI(0x01, data); // #2, write reg data to DATAWR (0x01)
 Write_Direct_Access_SPI(0x03, 0x02); // #3, write 0x02 to OPERATION (0x03)
 Delay(50); // #4, wait 50ms
}

void init_scp1000(void)
{
 unsigned int DATA;
 unsigned char i;
 
 PRESSURE_CS_INIT();
 PRESSURE_CS_DEASSERT();
 
 SPI0_Init();
 SPI0_MODE0();
 SPI0_CLK_DOULBE();
 SPI0_CLK_DIV128();
 
 Delay(60); // #3, 60ms wait
 
 DebugPrint("\r\nDATA: ");
 for(i = 6; i > 0 ; i--)
 {
  DATA = Read_Direct_Access_SPI(0x07, 1);// #4, read STATUS register --> LSB '0'=OK
  DebugPrint("%02X ", DATA);
  
  if(!(DATA & 0x0001))break;
  Delay(10);
 }
 
 if(i == 0)
 {
  //fail();
  DebugPrint("\r\nSTATUS register error\r\n");
  return;
 }
 DebugPrint("STATUS(%d)=0x%02X\r\n", i, DATA);
 
 DATA = Read_Direct_Access_SPI(0x1F, 1); // #5, read DATARD8 register --> LSB '1'=OK
 
 if(!(DATA && 0x0001))
 {
  //fail();
  DebugPrint("DATA(%02X) register error\r\n", DATA);
 }
 
 Write_Indirect_Access_SPI(0x2D, 0x03); // #6, Low noise configuration
 Delay(100); // #7, wait for 100ms
 Write_Direct_Access_SPI(0x03, 0x00); // Reset operation mode
 Delay(10); // Wait before change new mode
 Write_Direct_Access_SPI(0x03, 0x09); 
 // measurement mode (0x0A)
 Delay(100);
}
unsigned short GetPressure(void)
{
 unsigned long pressure;

 pressure = (uint32_t)((0x0007) & Read_Direct_Access_SPI(0x1F, 1));

 pressure <<= 16; // shift 3MSB bits to left by 16
 pressure |= (uint32_t)Read_Direct_Access_SPI(0x20, 2);

 pressure >>= 2; // Convert to [Pa] by dividing the 19 bit
 
 DebugPrint("%ld\r\n", 0x7FFFF&pressure); 
}
Posted by nexp

댓글을 달아 주세요

  1. choi

    안녕하세요. 이 센서를 쓰고 있는 유저인데
    데이터값이 제대로 잘 안나오네요
    16비트 dsp28335를 쓰고있는데요

    ////////main.c
    DSP28x_usDelay(1800000); // #.1
    /*
    for(i = 6; i > 0 ; i--)
    {
    DATA = (spi_read_Press(0x07, 1) & 0xFF);// #4, read STATUS register --> LSB '0'=OK

    if(!(DATA & 0x0001))break;
    DSP28x_usDelay(300000);
    }

    if(i == 0)
    {
    //SCP1000 에러
    DSP28x_usDelay(10000);
    return;
    }
    */

    spi_write_Press(0x022D);
    spi_write_Press(0x0103);
    spi_write_Press(0x0302);
    DSP28x_usDelay(1500000);

    DSP28x_usDelay(3000000);
    spi_write_Press(0x0300);
    DSP28x_usDelay(1200000);
    spi_write_Press(0x030A);
    DSP28x_usDelay(0x0309);
    DSP28x_usDelay(3000000);


    ////////spi.c
    void spi_write_Press(WORD tdata)
    {
    BYTE a,b;

    a=tdata&0xFF00;
    b=tdata&0x00FF;
    a=a<<2;
    GpioDataRegs.GPADAT.bit.GPIO9=0;
    SpiaRegs.SPITXBUF=a;
    delay_loop();
    SpiaRegs.SPITXBUF=b;
    GpioDataRegs.GPADAT.bit.GPIO9=1;

    }

    WORD spi_read_Press(BYTE tdata, BYTE type)
    {
    WORD rdata=0;

    SpiaRegs.SPIFFRX.bit.RXFIFORESET = 0;
    SpiaRegs.SPIFFRX.bit.RXFIFORESET = 1;

    tdata = tdata;

    GpioDataRegs.GPADAT.bit.GPIO9=0;
    SpiaRegs.SPITXBUF=tdata; //tdata 2byte -> 1byte
    while(type-- > 0)
    {
    rdata <<=8;
    rdata |= SpiaRegs.SPIRXBUF;
    }
    GpioDataRegs.GPADAT.bit.GPIO9=1;
    return rdata;
    }

    /////////interrupt.c

    WORD temp_data=0;
    WORD pressure=0;


    temp_data = spi_read_Press(0x1F, 1); //Read MSB pressure data - 3 lower bits
    pressure = spi_read_Press(0x20, 2);
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;


    이런식으로 테스트를 하고있는데......

    데이터값이 이상하게 나와요 ㅠㅠ

    2010.06.30 11:52 [ ADDR : EDIT/ DEL : REPLY ]