Honeywell HSC Sensor über SPI auslesen

Gast #4318008
Lesenswert?

Hi.

Ich versuche gerade einen bzw. zwei Honeywell Drucksensoren über SPI 
auszulesen, das ganze Funkioniert jedoch nur halb.

Der eine ist ein 1.6Bar absolut Sensor (HSCMRNN1.6BASA3) und der andere 
ein 60mBar differential Sensor (HSCDRRN060MDSA3).

Hier mein Code:
1
#include <SPI.h>
2
uint8_t chipSelectPin1 = 3;
3
uint8_t chipSelectPin2 = 2;
4

5
void setup() {
6
  Serial.begin(9600);
7
  SPI.begin();
8
  pinMode(chipSelectPin1, OUTPUT);
9
  digitalWrite(chipSelectPin1, HIGH);
10

11
  pinMode(chipSelectPin2, OUTPUT);
12
  digitalWrite(chipSelectPin2, HIGH);
13
}
14
void loop()
15
{
16
  delay(1000);
17
  float val1 =  (1600 * ((float)readSensor(chipSelectPin1) - 1638) / 13107);
18
  Serial.print("PRESS1 = "); Serial.println(val1);
19

20
  float val2 =  (40 * ((float)readSensor(chipSelectPin2) - 1638) / 4369) + 60;
21
  Serial.print("PRESS2 = "); Serial.println(val2);
22
}
23

24
int16_t readSensor (uint8_t selectPin) {
25

26
  SPI.beginTransaction(SPISettings(700000, MSBFIRST, SPI_MODE1)); // Set to 700kHz, MSB and MODE1
27
  digitalWrite(selectPin, LOW);       //pull Chipselect Pin to Low
28

29
  int inByte_1 = SPI.transfer(0x00);  // Read first Byte of Pressure
30
  int inByte_2 = SPI.transfer(0x00);  // Read second Byte of Pressure
31
  int inByte_3 = SPI.transfer(0x00);  // Read first Byte of Temperature
32
  int inByte_4 = SPI.transfer(0x00);  // Read second Byte of Temperature
33

34
  digitalWrite(selectPin, HIGH);      //pull Chipselect Pin to High
35
  SPI.endTransaction();               //end SPI Transaction
36
  Serial.print("Chipselect = "); Serial.print(selectPin, DEC); Serial.print(" ");
37
  Serial.print("Byte_1 = "); Serial.print(inByte_1, DEC); Serial.print(" ");
38
  Serial.print("Byte_2 = "); Serial.print(inByte_2, DEC); Serial.print(" ");
39
  Serial.print("Byte_3 = "); Serial.print(inByte_3, DEC); Serial.print(" ");
40
  Serial.print("Byte_4 = "); Serial.print(inByte_4, DEC); Serial.print(" ");
41

42
  int16_t pressure_dig = inByte_1 << 8 | inByte_2; 
43

44
  inByte_3 = inByte_3 << 3; //Shift first Temperature byte 3 left 
45
  float realTemp = ((float)inByte_3 * 200 / 2047) - 50; //Convert Digital value to °C
46
  Serial.print("Temp[C]= "); Serial.print(realTemp); Serial.print(" ");
47

48
  return pressure_dig; //return digital Pressure Value
49
}

Als Ergebnis bekomme ich jedoch:
1
Chipselect = 2 Byte_1 = 255 Byte_2 = 255 Byte_3 = 255 Byte_4 = 255 Temp[C]= 149.32 PRESS2 = 44.99
2
Chipselect = 3 Byte_1 = 31 Byte_2 = 255 Byte_3 = 88 Byte_4 = 111 Temp[C]= 18.78 PRESS1 = 799.94
3
Chipselect = 2 Byte_1 = 255 Byte_2 = 255 Byte_3 = 255 Byte_4 = 255 Temp[C]= 149.32 PRESS2 = 44.99
4
Chipselect = 3 Byte_1 = 31 Byte_2 = 253 Byte_3 = 88 Byte_4 = 111 Temp[C]= 18.78 PRESS1 = 799.69

Eine Wetterstation in der gleichen Stadt zeigte mir zu diesem Zeitpunkt 
1022mBar an, meine höhe Beträgt ca. 45m über dem Meeresspiegel.
Der Zweite Sensor sollte auch 0 anzeigen, da er einfach nur so auf dem 
Tisch liegt und kein Druck angeschlossen ist.

Zusätzlich bekomme ich beim zweiten Sensor eine falsche Temperatur 
angezeigt, die 18.78°C vom ersten könnten hier hinkommen.

Grüße

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren