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

ADT7310 SPI temperature sensor driver #2980

Merged
merged 2 commits into from Jul 11, 2015

Conversation

jnohlgard
Copy link
Member

drivers/adt7310: Add ADT7310 temperature sensor driver

This is a driver for Analog Devices ADT7310 +/-0.5°C Accurate, 16-Bit Digital SPI Temperature Sensor.

Only basic reading is supported. Interrupt and compare are not implemented yet.

See: http://www.analog.com/en/products/analog-to-digital-converters/integrated-special-purpose-converters/integrated-temperature-sensors/adt7310.html

Tested on mulle

@jnohlgard jnohlgard added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers labels May 14, 2015
@LudwigKnuepfer
Copy link
Member

In case you don't want to implement interrupt mode etc. as part of this PR you could document this missing feature in the API.. Compare http://riot-os.org/api/group__driver__isl29125.html#details

@jnohlgard
Copy link
Member Author

@LudwigOrtmann Thank you for your suggestion. I have updated the PR with a little more documentation for the main page.

@jnohlgard jnohlgard added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label May 15, 2015
@jnohlgard
Copy link
Member Author

I fixed the cppcheck warning and removed the extra whitespaces that showed up in Travis. Waiting for a new Travis run.

int adt7310_init(adt7310_t *dev, spi_t spi, gpio_t cs);

/**
* @brief Reset the TMP006 sensor. After that, the sensor should be reinitialized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TMP006 -> ADT7310 I guess.

@jnohlgard
Copy link
Member Author

@LudwigOrtmann Addressed comments

*
* @param[out] dev device descriptor of sensor to initialize
* @param[in] spi SPI bus the sensor is connected to
* @param[in] cs GPIO pin which the chip select signal is connected to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "which" correct here?

@PeterKietzmann
Copy link
Member

Looks valid to me at first sight.

*
* @return floating point representation of temperature in degrees Celsius
*/
float adt7310_convert(int16_t raw);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a suggestion: how about changing the interface to

int16_t adt7310_read_raw(dev); // return raw value
int16_t adt7310_read(dev);     // return value in m°C
and
float adt7310_read_float(dev); // return value in °C

The error conditions you could either omit (just return 0 or something) or return INT16_MIN or similar. Opinions on this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, however it will have to be int32_t adt7310_read(dev); in order to represent temperatures above 32.767 C

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right :-)

@jnohlgard
Copy link
Member Author

I updated the code but I think I might have broke my sensor or some wire, every SPI transfer comes back with 0xff.. I'll post back when I have tested this.

@haukepetersen
Copy link
Contributor

Very nice. Code looks good to me. The only thing I am not sure if I like it, is the external initialization of the SPI port (I know this in general is subject to ongoing discussion). IMHO this (i) breaks the consistency with all other existing drivers and (ii) does make it harder to use a device. Actually what I like to prevent is the situation, that you have to look into the initialization code/doc everytime before you use a driver to find out which of the used peripherals you have to initialize beforehand... Also in the end, the driver knows best, which parameters to use (e.g. speed, etc.).

@kaspar030
Copy link
Contributor

+1 for moving spi initialization into the driver.

@haukepetersen
Copy link
Contributor

@gebart: how about moving the initialization into the driver for know and we give the general discussion a push to decide how we handle this situation in general for the future?

@jnohlgard
Copy link
Member Author

@haukepetersen I can live with that for the time being until a consensus is reached in #2528

@haukepetersen
Copy link
Contributor

I can if you document it properly for the init function :-)

ACK when this is done.

@OlegHahm OlegHahm modified the milestone: Release 2015.06 May 28, 2015
@haukepetersen
Copy link
Contributor

@gebart: I don't really understand my own last comment anymore... Where were we at with this PR? If you could either add documentation to the init function, that the SPI bus needs to be pre-initialized or if you could move the SPI init into the driver init, you can squash and we can merge this.

@jnohlgard jnohlgard force-pushed the pr/adt7310-initial branch 2 times, most recently from c7c4849 to 2c5e673 Compare June 25, 2015 05:57
@jnohlgard jnohlgard added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Jun 25, 2015
@jnohlgard
Copy link
Member Author

@haukepetersen

  • Added the comment about pre-initialized SPI bus to the documentation for adt7310_init.
  • Rebased after the new GPIO API was merged.

Tested on real hardware on my side. Waiting for Travis.

Joakim Gebart added 2 commits July 9, 2015 23:39
This is a driver for Analog Devices ADT7310 +/-0.5°C Accurate, 16-Bit
Digital SPI Temperature Sensor.

Only basic reading is supported. Interrupt and compare are not
implemented yet.

See: http://www.analog.com/en/products/analog-to-digital-converters/integrated-special-purpose-converters/integrated-temperature-sensors/adt7310.html
@LudwigKnuepfer
Copy link
Member

pre-ACKed, and go =)

LudwigKnuepfer added a commit that referenced this pull request Jul 11, 2015
ADT7310 SPI temperature sensor driver
@LudwigKnuepfer LudwigKnuepfer merged commit fe34e78 into RIOT-OS:master Jul 11, 2015
@jnohlgard jnohlgard deleted the pr/adt7310-initial branch July 21, 2015 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants