google / cyanobyte

Machine-readable datasheets
https://cyanobyte.dev
Apache License 2.0
79 stars 31 forks source link

BMP280 Generated files for Arduino with the given datasheet is not working? #244

Closed rohitsam closed 3 years ago

rohitsam commented 3 years ago

Hey,

I have run cyanobyte-Codegen for Sensor BMP280 and generated code for Arduino.

cyanobyte-codegen -t templates/arduino.cpp -o ./build peripherals/BMP280.yaml

cyanobyte-codegen -t templates/arduino.h -o ./build peripherals/BMP280.yaml

Later I have used these generated library files and written these lines of code for Atmega 328(Arduino)

#include "BMP280.h"
TwoWire Wire1;
BMP280 sensor(Wire1);

void setup() {
sensor.begin();
Serial.begin(9600);
}
void loop() {
Serial.println(sensor.temperatureasCelsius());
delay(2000);
}

But I get null output. I have also confirmed my my hardware to be working fine, since I have verifyed it with adfruits library

rohitsam commented 3 years ago

In the cyanobyte datasheet Many registers are given wrong datasize #246

rohitsam commented 3 years ago
uint16_t BMP280::readDigP8() {
    uint8_t datum;
    uint16_t value;
    _wire->beginTransmission(DEVICE_ADDRESS);
    _wire->write(REGISTER_DIGP8);
    if (_wire->endTransmission(false) != 0) {
        return -1;
    }

    if (_wire->requestFrom(DEVICE_ADDRESS, 2) != 2) {
        return 0;
    }

    datum = _wire->read();
    value = value << 8 | datum;
    datum = _wire->read();
    value = value << 8 | datum;

    return value;
}

This is the generated code of BMP280 for arduino, and the endianness is ignored. image

Fleker commented 3 years ago

Yeah I'll need to re-review the datasheet and ensure that the registers are all correctly typed.

rohitsam commented 3 years ago

The template for Arduino doesn't have method to typecast variables.

Fleker commented 3 years ago

Arduino variables should now be properly signed as-necessary.