BMP280 work

This commit is contained in:
uvos 2023-03-30 19:22:44 +02:00
parent 3b04b070a4
commit 1f18e76622
6 changed files with 27 additions and 16 deletions

View File

@ -88,3 +88,11 @@ uint32_t BMP280::compensatePressure(const int32_t adc_P)
return p;
}
#endif
void BMP280::getCoefficient(uint16_t* coefficients)
{
for(uint8_t i = 0; i < 9; i++)
{
coefficients[i] = (uint16_t)read16b(DIG_P1+i*2);
}
}

View File

@ -3,7 +3,7 @@
#include "softspim.h"
#define PRECOMP_COMPENSATION
//#define PRECOMP_COMPENSATION
class BMP280
{
@ -42,8 +42,8 @@ private:
static constexpr int16_t digP7value = 7;
static constexpr int16_t digP8value = 3;
static constexpr int16_t digP9value = 58;
static constexpr int32_t var1StepA = ((((int32_t)t_fine)>>1) - (int32_t)64000);
static constexpr int32_t var1StepB = ((((32768+((((digP3value *
static constexpr int32_t var1StepA = ((((int32_t)t_fine)>>1) - (int32_t)64000);
static constexpr int32_t var1StepB = ((((32768+((((digP3value *
(((var1StepA>>2) * (var1StepA>>2)) >> 13 )) >> 3) + ((((int32_t)digP2value) * var1StepA)>>1))>>18)))*
((int32_t)digP1value))>>15);
static constexpr int32_t var2StepA = ((((var1StepA>>2) * (var1StepA>>2)) >> 11 ) * ((int32_t)digP6value)) + ((var1StepA*((int32_t)digP5value))<<1);
@ -64,5 +64,6 @@ private:
public:
BMP280(SpiMaster * const spi, volatile uint8_t * const port, const uint8_t pin);
uint16_t getPressure();
uint16_t getPressure();
void getCoefficient(uint16_t* coefficients);
};

View File

@ -68,7 +68,8 @@ void W433DataTransmitter::sendPacket(const uint32_t data)
for(uint8_t i = 0; i < 4; ++i)
{
uint8_t dataOctet = (data & (0xFF000000 >> i*8 )) >> (24 - 8*i);
for(uint8_t i = 0; i < 8; i++) checksum = checksum + (dataOctet & ( 1 << (8 - i)));
//for(uint8_t i = 0; i < 8; i++) checksum = checksum + (dataOctet & ( 1 << (8 - i)));
for(uint8_t i = 0; i < 8; i++) checksum = checksum + ((dataOctet & ( 1 << (8 - i))) >> (8 - i));
sendRawData( dataOctet );
}

View File

@ -8,9 +8,9 @@ class W433DataTransmitter
{
private:
static constexpr uint16_t SYNC_TIME = 800;
static constexpr uint16_t LARGE_TIME = 2000;
static constexpr uint16_t SMALL_TIME = 500;
static constexpr uint16_t SYNC_TIME = 800;
static constexpr uint8_t signature = 0xA5;
volatile unsigned char * const _port;

View File

@ -8,7 +8,7 @@ class Dht11
static constexpr uint16_t LOOP_TIMEOUT_COUNT = (10000.0 / 16000000.0)*F_CPU;
static constexpr uint8_t LOOP_TIMEOUT_SMALL_COUNT = (100.0 / 16000000.0)*F_CPU;
static constexpr uint8_t BIT_COUNT = 6;//(8.0 / 16000000.0)*F_CPU;
static constexpr bool DHT22 = false;
static constexpr bool DHT22 = true;
volatile unsigned char * const _port;
volatile unsigned char * const _port_ctl;
@ -19,5 +19,5 @@ public:
Dht11(volatile unsigned char * const port, volatile unsigned char * const inPort, volatile unsigned char * const port_ctl, const unsigned char pin);
uint8_t read();
int16_t humidity = 0;
uint16_t temperature = 0;
int16_t temperature = 0;
};

View File

@ -10,6 +10,7 @@
#include "BMP280.h"
#include "comperator.h"
#define TEMP_SENSOR_DATA PB4
#define TRANSMITTER_DATA PD0
#define DOOR_PIN PD2
@ -18,9 +19,9 @@
EMPTY_INTERRUPT(WDT_OVERFLOW_vect);
static constexpr uint8_t id = 4;
static constexpr uint8_t id = 1;
static constexpr bool WATCH_DOOR = false;
static constexpr bool BMP_280 = true;
static constexpr bool BMP_280 = false;
static constexpr bool DHT22 = true;
@ -64,8 +65,8 @@ int main()
Comperator comp;
sei();
wdt_set(WDTO_8S);
WDTCSR = 1<<WDIE;
wdt_set(WDTO_2S);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
uint8_t couter = 200;
@ -85,15 +86,15 @@ int main()
PORTD &= ~(1 << LED_PIN);
uint8_t paket[4] = {0};
paket[1] = 4;
paket[1] = id;
//temperature sensor
if constexpr (DHT22)
{
//debugBlink(false);
uint8_t readret = tempSensor.read();
paket[0] = readret;
tempSensor.read();
paket[0] = 1;
paket[2] = tempSensor.temperature >> 8;
paket[3] = tempSensor.temperature;
transmiter.send(paket, 4);
@ -141,7 +142,7 @@ int main()
transmiter.send(paket, 4);
}
comp.off();
//power(false);
power(false);
}
sleep_mode();
}