Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
libraries/cn0216/CN0216.h@18:7d35420ff4aa, 2016-05-05 (annotated)
- Committer:
- Adrian Suciu
- Date:
- Thu May 05 15:59:47 2016 +0300
- Revision:
- 18:7d35420ff4aa
- Parent:
- 17:b8356808e8ad
Fixed header comments
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Adrian Suciu |
18:7d35420ff4aa | 1 | /** |
| Adrian Suciu |
18:7d35420ff4aa | 2 | * @file cn0216.h |
| Adrian Suciu |
18:7d35420ff4aa | 3 | * @brief Header file for CN0216 |
| Adrian Suciu |
18:7d35420ff4aa | 4 | * @author Analog Devices Inc. |
| Adrian Suciu |
18:7d35420ff4aa | 5 | * |
| Adrian Suciu |
18:7d35420ff4aa | 6 | * For support please go to: |
| Adrian Suciu |
18:7d35420ff4aa | 7 | * Github: https://github.com/analogdevicesinc/mbed-adi |
| Adrian Suciu |
18:7d35420ff4aa | 8 | * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers |
| Adrian Suciu |
18:7d35420ff4aa | 9 | * Product: www.analog.com/EVAL-CN0216-ARDZ |
| Adrian Suciu |
18:7d35420ff4aa | 10 | * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all |
| Adrian Suciu |
18:7d35420ff4aa | 11 | |
| Adrian Suciu |
18:7d35420ff4aa | 12 | ******************************************************************************** |
| Adrian Suciu |
18:7d35420ff4aa | 13 | * Copyright 2016(c) Analog Devices, Inc. |
| Adrian Suciu |
18:7d35420ff4aa | 14 | * |
| Adrian Suciu |
18:7d35420ff4aa | 15 | * All rights reserved. |
| Adrian Suciu |
18:7d35420ff4aa | 16 | * |
| Adrian Suciu |
18:7d35420ff4aa | 17 | * Redistribution and use in source and binary forms, with or without |
| Adrian Suciu |
18:7d35420ff4aa | 18 | * modification, are permitted provided that the following conditions are met: |
| Adrian Suciu |
18:7d35420ff4aa | 19 | * - Redistributions of source code must retain the above copyright |
| Adrian Suciu |
18:7d35420ff4aa | 20 | * notice, this list of conditions and the following disclaimer. |
| Adrian Suciu |
18:7d35420ff4aa | 21 | * - Redistributions in binary form must reproduce the above copyright |
| Adrian Suciu |
18:7d35420ff4aa | 22 | * notice, this list of conditions and the following disclaimer in |
| Adrian Suciu |
18:7d35420ff4aa | 23 | * the documentation and/or other materials provided with the |
| Adrian Suciu |
18:7d35420ff4aa | 24 | * distribution. |
| Adrian Suciu |
18:7d35420ff4aa | 25 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| Adrian Suciu |
18:7d35420ff4aa | 26 | * contributors may be used to endorse or promote products derived |
| Adrian Suciu |
18:7d35420ff4aa | 27 | * from this software without specific prior written permission. |
| Adrian Suciu |
18:7d35420ff4aa | 28 | * - The use of this software may or may not infringe the patent rights |
| Adrian Suciu |
18:7d35420ff4aa | 29 | * of one or more patent holders. This license does not release you |
| Adrian Suciu |
18:7d35420ff4aa | 30 | * from the requirement that you obtain separate licenses from these |
| Adrian Suciu |
18:7d35420ff4aa | 31 | * patent holders to use this software. |
| Adrian Suciu |
18:7d35420ff4aa | 32 | * - Use of the software either in source or binary form, must be run |
| Adrian Suciu |
18:7d35420ff4aa | 33 | * on or directly connected to an Analog Devices Inc. component. |
| Adrian Suciu |
18:7d35420ff4aa | 34 | * |
| Adrian Suciu |
18:7d35420ff4aa | 35 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| Adrian Suciu |
18:7d35420ff4aa | 36 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| Adrian Suciu |
18:7d35420ff4aa | 37 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| Adrian Suciu |
18:7d35420ff4aa | 38 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| Adrian Suciu |
18:7d35420ff4aa | 39 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| Adrian Suciu |
18:7d35420ff4aa | 40 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| Adrian Suciu |
18:7d35420ff4aa | 41 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| Adrian Suciu |
18:7d35420ff4aa | 42 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| Adrian Suciu |
18:7d35420ff4aa | 43 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| Adrian Suciu |
18:7d35420ff4aa | 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Adrian Suciu |
18:7d35420ff4aa | 45 | * |
| Adrian Suciu |
18:7d35420ff4aa | 46 | ********************************************************************************/ |
| Adrian Suciu |
13:66c8e4ce4ff1 | 47 | |
| Adrian Suciu |
13:66c8e4ce4ff1 | 48 | #include "mbed.h" |
| Adrian Suciu |
13:66c8e4ce4ff1 | 49 | #include "AD7791.h" |
| Adrian Suciu |
13:66c8e4ce4ff1 | 50 | |
| Adrian Suciu |
13:66c8e4ce4ff1 | 51 | #ifndef CN0216_H_ |
| Adrian Suciu |
13:66c8e4ce4ff1 | 52 | #define CN0216_H_ |
| Adrian Suciu |
13:66c8e4ce4ff1 | 53 | |
| Adrian Suciu |
13:66c8e4ce4ff1 | 54 | class CN0216 |
| Adrian Suciu |
13:66c8e4ce4ff1 | 55 | { |
| Adrian Suciu |
13:66c8e4ce4ff1 | 56 | public: |
| Adrian Suciu |
17:b8356808e8ad | 57 | typedef enum { |
| Adrian Suciu |
17:b8356808e8ad | 58 | ZERO_SCALE_CALIBRATION, ///< Calibration of the zero scale value |
| Adrian Suciu |
17:b8356808e8ad | 59 | FULL_SCALE_CALIBRATION, ///< Calibration of the full scale value |
| Adrian Suciu |
17:b8356808e8ad | 60 | COMPUTE_UNITS_PER_BIT ///< Units per LSB computation |
| Adrian Suciu |
17:b8356808e8ad | 61 | } CalibrationStep_t; |
| Adrian Suciu |
13:66c8e4ce4ff1 | 62 | |
| Adrian Suciu |
17:b8356808e8ad | 63 | CN0216(PinName CSAD7791 = D8, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK); |
| Adrian Suciu |
17:b8356808e8ad | 64 | void init(float cal_weight = _DEFAULT_CAL_WEIGHT, uint8_t mode_val = _DEFAULT_MODE_VAL, uint8_t filter_val = _DEFAULT_FILTER_VAL); |
| Adrian Suciu |
17:b8356808e8ad | 65 | void calibrate(CalibrationStep_t cal); |
| Adrian Suciu |
17:b8356808e8ad | 66 | float compute_weight(uint32_t data); |
| Adrian Suciu |
17:b8356808e8ad | 67 | uint32_t read_u32(); |
| Adrian Suciu |
17:b8356808e8ad | 68 | float read_weight(); |
| Adrian Suciu |
13:66c8e4ce4ff1 | 69 | |
| Adrian Suciu |
13:66c8e4ce4ff1 | 70 | private: |
| Adrian Suciu |
13:66c8e4ce4ff1 | 71 | |
| Adrian Suciu |
17:b8356808e8ad | 72 | const static int _NUMBER_OF_SAMPLES = 20; ///< Number of samples used in calibration |
| Adrian Suciu |
17:b8356808e8ad | 73 | const static int _DEFAULT_MODE_VAL = AD7791::MD1 | AD7791::MD0; // POWERDOWN MODE |
| Adrian Suciu |
17:b8356808e8ad | 74 | const static int _DEFAULT_FILTER_VAL = AD7791::FS0 | AD7791::FS1 | AD7791::FS2; |
| Adrian Suciu |
17:b8356808e8ad | 75 | const static int _DEFAULT_CAL_WEIGHT = 1000.0; |
| Adrian Suciu |
13:66c8e4ce4ff1 | 76 | |
| Adrian Suciu |
17:b8356808e8ad | 77 | AD7791 ad7791; |
| Adrian Suciu |
17:b8356808e8ad | 78 | float _cal_weight; |
| Adrian Suciu |
17:b8356808e8ad | 79 | uint32_t _zero_scale_value; |
| Adrian Suciu |
17:b8356808e8ad | 80 | uint32_t _full_scale_value; |
| Adrian Suciu |
17:b8356808e8ad | 81 | float _weight_units_per_bit; |
| Adrian Suciu |
17:b8356808e8ad | 82 | |
| Adrian Suciu |
13:66c8e4ce4ff1 | 83 | }; |
| Adrian Suciu |
13:66c8e4ce4ff1 | 84 | |
| Adrian Suciu |
13:66c8e4ce4ff1 | 85 | #endif |
CN0357 - Toxic gas measurement
CN0216 - Weight Scale