Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial soft reset may be required #6

Open
tdjastrzebski opened this issue Aug 21, 2024 · 0 comments
Open

initial soft reset may be required #6

tdjastrzebski opened this issue Aug 21, 2024 · 0 comments

Comments

@tdjastrzebski
Copy link

tdjastrzebski commented Aug 21, 2024

Not sure why, but my BMP581 does not seem to properly initialize during POR.
I think in any case, to be on the safe side performing soft reset during init may be a good idea - in my case it fixed the issue.
Improved bmp5_init() code below.

int8_t bmp5_init(struct bmp5_dev *dev) {
    int8_t rslt;
    uint8_t reg_data;
    uint8_t chip_id;

    /* Check for null pointer in the device structure */
    rslt = null_ptr_check(dev);

    if (rslt != BMP5_OK) return rslt;

    dev->chip_id = 0;

    if (dev->intf == BMP5_SPI_INTF) {
        /* Performing a single read via SPI of registers,
            * e.g. registers CHIP_ID, before the actual
            * SPI communication with the device.
            */
        rslt = bmp5_get_regs(BMP5_REG_CHIP_ID, &reg_data, 1, dev);
        if (rslt != BMP5_OK) return rslt;
    }

    /* perform soft reset */
    reg_data = BMP5_SOFT_RESET_CMD;
    rslt = bmp5_set_regs(BMP5_REG_CMD, &reg_data, 1, dev);
    dev->delay_us(BMP5_DELAY_US_SOFT_RESET, dev->intf_ptr);

    if (rslt != BMP5_OK) return rslt;

    rslt = bmp5_get_interrupt_status(&reg_data, dev);

    if (rslt != BMP5_OK) return rslt;
        
    if ((reg_data & BMP5_INT_ASSERTED_POR_SOFTRESET_COMPLETE) != BMP5_INT_ASSERTED_POR_SOFTRESET_COMPLETE) {
        return BMP5_E_POR_SOFTRESET;
    }
    
    /* Read chip_id */
    rslt = bmp5_get_regs(BMP5_REG_CHIP_ID, &chip_id, 1, dev);

    if (rslt != BMP5_OK) return rslt;

    if (chip_id != 0) {
        /* Validate post power-up procedure */
        rslt = power_up_check(dev);
    } else {
        return BMP5_E_INVALID_CHIP_ID;
    }

    rslt = validate_chip_id(chip_id, dev);

    return rslt;
}```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant