본문 바로가기

[SENSOR]/기타센서

[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); 
}
반응형