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/cn0357/cn0357.h@4:5c1b28aff7e1, 2016-04-19 (annotated)
- Committer:
- Adrian Suciu
- Date:
- Tue Apr 19 17:55:14 2016 +0300
- Revision:
- 4:5c1b28aff7e1
- Parent:
- 3:1a8c14043a4e
- Child:
- 6:74651acebcc7
Driver and application redesign
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Suciu |
1:c1f0670bb370 | 1 | /** |
| Suciu |
3:1a8c14043a4e | 2 | * @file cn0357.h |
| Suciu |
3:1a8c14043a4e | 3 | * @brief Header file for CN0357 |
| Suciu |
3:1a8c14043a4e | 4 | * @author Analog Devices Inc. |
| Suciu |
3:1a8c14043a4e | 5 | * |
| Suciu |
3:1a8c14043a4e | 6 | * For support please go to: |
| Suciu |
3:1a8c14043a4e | 7 | * Github: https://github.com/analogdevicesinc/mbed-adi |
| Suciu |
3:1a8c14043a4e | 8 | * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers |
| Suciu |
3:1a8c14043a4e | 9 | * Product: www.analog.com/EVAL-CN0357-ARDZ |
| Suciu |
3:1a8c14043a4e | 10 | * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all |
| Suciu |
3:1a8c14043a4e | 11 | |
| Suciu |
3:1a8c14043a4e | 12 | ******************************************************************************** |
| Suciu |
3:1a8c14043a4e | 13 | * Copyright 2016(c) Analog Devices, Inc. |
| Suciu |
3:1a8c14043a4e | 14 | * |
| Suciu |
3:1a8c14043a4e | 15 | * All rights reserved. |
| Suciu |
3:1a8c14043a4e | 16 | * |
| Suciu |
3:1a8c14043a4e | 17 | * Redistribution and use in source and binary forms, with or without |
| Suciu |
3:1a8c14043a4e | 18 | * modification, are permitted provided that the following conditions are met: |
| Suciu |
3:1a8c14043a4e | 19 | * - Redistributions of source code must retain the above copyright |
| Suciu |
3:1a8c14043a4e | 20 | * notice, this list of conditions and the following disclaimer. |
| Suciu |
3:1a8c14043a4e | 21 | * - Redistributions in binary form must reproduce the above copyright |
| Suciu |
3:1a8c14043a4e | 22 | * notice, this list of conditions and the following disclaimer in |
| Suciu |
3:1a8c14043a4e | 23 | * the documentation and/or other materials provided with the |
| Suciu |
3:1a8c14043a4e | 24 | * distribution. |
| Suciu |
3:1a8c14043a4e | 25 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| Suciu |
3:1a8c14043a4e | 26 | * contributors may be used to endorse or promote products derived |
| Suciu |
3:1a8c14043a4e | 27 | * from this software without specific prior written permission. |
| Suciu |
3:1a8c14043a4e | 28 | * - The use of this software may or may not infringe the patent rights |
| Suciu |
3:1a8c14043a4e | 29 | * of one or more patent holders. This license does not release you |
| Suciu |
3:1a8c14043a4e | 30 | * from the requirement that you obtain separate licenses from these |
| Suciu |
3:1a8c14043a4e | 31 | * patent holders to use this software. |
| Suciu |
3:1a8c14043a4e | 32 | * - Use of the software either in source or binary form, must be run |
| Suciu |
3:1a8c14043a4e | 33 | * on or directly connected to an Analog Devices Inc. component. |
| Suciu |
3:1a8c14043a4e | 34 | * |
| Suciu |
3:1a8c14043a4e | 35 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| Suciu |
3:1a8c14043a4e | 36 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| Suciu |
3:1a8c14043a4e | 37 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| Suciu |
3:1a8c14043a4e | 38 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| Suciu |
3:1a8c14043a4e | 39 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| Suciu |
3:1a8c14043a4e | 40 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| Suciu |
3:1a8c14043a4e | 41 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| Suciu |
3:1a8c14043a4e | 42 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| Suciu |
3:1a8c14043a4e | 43 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| Suciu |
3:1a8c14043a4e | 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Suciu |
3:1a8c14043a4e | 45 | * |
| Suciu |
3:1a8c14043a4e | 46 | ********************************************************************************/ |
| Suciu |
1:c1f0670bb370 | 47 | |
| Suciu |
1:c1f0670bb370 | 48 | #ifndef CN0357_H |
| Suciu |
1:c1f0670bb370 | 49 | #define CN0357_H |
| Suciu |
1:c1f0670bb370 | 50 | |
| Suciu |
1:c1f0670bb370 | 51 | #include "mbed.h" |
| Suciu |
1:c1f0670bb370 | 52 | #include "ad7790.h" |
| Suciu |
1:c1f0670bb370 | 53 | #include "ad5270.h" |
| Suciu |
1:c1f0670bb370 | 54 | |
| Suciu |
1:c1f0670bb370 | 55 | /** |
| Suciu |
1:c1f0670bb370 | 56 | * @brief EVAL-CN0357 toxic gas sensor shield |
| Suciu |
1:c1f0670bb370 | 57 | */ |
| Suciu |
1:c1f0670bb370 | 58 | class CN0357 |
| Suciu |
1:c1f0670bb370 | 59 | { |
| Suciu |
1:c1f0670bb370 | 60 | public: |
| Suciu |
1:c1f0670bb370 | 61 | |
| Adrian Suciu |
4:5c1b28aff7e1 | 62 | private: |
| Adrian Suciu |
4:5c1b28aff7e1 | 63 | float _vref; |
| Adrian Suciu |
4:5c1b28aff7e1 | 64 | float _sensor_sensitivity; |
| Adrian Suciu |
4:5c1b28aff7e1 | 65 | float _sensor_range; |
| Adrian Suciu |
4:5c1b28aff7e1 | 66 | float _RDACvalue; |
| Adrian Suciu |
4:5c1b28aff7e1 | 67 | public: |
| Adrian Suciu |
4:5c1b28aff7e1 | 68 | AD7790 ad7790; ///< AD7790 instance - can be used for manual overriding |
| Adrian Suciu |
4:5c1b28aff7e1 | 69 | AD5270 ad5270; ///< AD5270 instance - can be used for manual overriding |
| Adrian Suciu |
4:5c1b28aff7e1 | 70 | |
| Suciu |
1:c1f0670bb370 | 71 | /// CN0357 shield jumper configuration |
| Suciu |
1:c1f0670bb370 | 72 | typedef enum { |
| Suciu |
1:c1f0670bb370 | 73 | INTERNAL_AD7790 = 0, ///< The shield's AD7790 is used |
| Suciu |
1:c1f0670bb370 | 74 | EXTERNAL_ADC ///< Sensor analog output is routed to A1 pin of the shield |
| Suciu |
1:c1f0670bb370 | 75 | } JumperConfig_t; |
| Suciu |
1:c1f0670bb370 | 76 | |
| Suciu |
3:1a8c14043a4e | 77 | CN0357(PinName CSAD7790 = D8, PinName CSAD5270 = D6, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK); |
| Suciu |
3:1a8c14043a4e | 78 | void init(float range, float sensitivity, JumperConfig_t jp = INTERNAL_AD7790, uint8_t mode_val = _DEFAULT_MODE_VAL, uint8_t filter_val = _DEFAULT_FILTER_VAL); |
| Suciu |
1:c1f0670bb370 | 79 | |
| Suciu |
1:c1f0670bb370 | 80 | uint8_t read_adc_status(void); |
| Suciu |
1:c1f0670bb370 | 81 | uint16_t read_sensor(void); |
| Suciu |
1:c1f0670bb370 | 82 | float read_sensor_voltage(void); |
| Suciu |
1:c1f0670bb370 | 83 | float data_to_voltage(uint16_t data); |
| Suciu |
1:c1f0670bb370 | 84 | float calc_ppm(float adcVoltage); |
| Suciu |
1:c1f0670bb370 | 85 | float read_ppm(void); |
| Suciu |
1:c1f0670bb370 | 86 | |
| Adrian Suciu |
4:5c1b28aff7e1 | 87 | void set_vref(float vref); |
| Adrian Suciu |
4:5c1b28aff7e1 | 88 | float get_vref(void); |
| Adrian Suciu |
4:5c1b28aff7e1 | 89 | |
| Suciu |
1:c1f0670bb370 | 90 | void set_RDAC_value(float resistor_val); |
| Suciu |
1:c1f0670bb370 | 91 | float get_RDAC_value(void); |
| Suciu |
1:c1f0670bb370 | 92 | float set_sensor_parameters(float range, float sensitivity); |
| Suciu |
1:c1f0670bb370 | 93 | float get_sensor_range(void); |
| Suciu |
1:c1f0670bb370 | 94 | float get_sensor_sensitivity(void); |
| Suciu |
1:c1f0670bb370 | 95 | |
| Suciu |
1:c1f0670bb370 | 96 | private: |
| Suciu |
1:c1f0670bb370 | 97 | const static int _RESET = 0xff; |
| Adrian Suciu |
4:5c1b28aff7e1 | 98 | const static int _DEFAULT_MODE_VAL = AD7790::MD1 | AD7790::MD0; // POWERDOWN MODE |
| Adrian Suciu |
4:5c1b28aff7e1 | 99 | const static int _DEFAULT_FILTER_VAL = AD7790::FS0 | AD7790::FS1 | AD7790::FS2; |
| Suciu |
1:c1f0670bb370 | 100 | void _rdac_init(float resistanceValue); |
| Suciu |
1:c1f0670bb370 | 101 | void _AD7790_init(uint8_t mode_val, uint8_t filter_val); |
| Suciu |
1:c1f0670bb370 | 102 | |
| Suciu |
1:c1f0670bb370 | 103 | }; |
| Suciu |
1:c1f0670bb370 | 104 | |
| Suciu |
1:c1f0670bb370 | 105 | #endif // CN0357_H |
CN0357 - Toxic gas measurement
CN0216 - Weight Scale