![](/media/cache/profiles/3ceca2fc13c2fa01d4aed1e552d3a6fb.50x50_q85.jpg)
there is a problem. i cant send data continuously.
Dependencies: EthernetNetIf mbed HMC6352 ITG3200 ADXL345 IMUfilter
SCP1000/SCP1000.cpp@0:711905e937b9, 2011-07-24 (annotated)
- Committer:
- fyazgan
- Date:
- Sun Jul 24 19:49:51 2011 +0000
- Revision:
- 0:711905e937b9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fyazgan | 0:711905e937b9 | 1 | /** |
fyazgan | 0:711905e937b9 | 2 | * @section LICENSE |
fyazgan | 0:711905e937b9 | 3 | * This program is free software; you can redistribute it and/or modify |
fyazgan | 0:711905e937b9 | 4 | * it under the terms of the GNU General Public License as published by |
fyazgan | 0:711905e937b9 | 5 | * the Free Software Foundation; either version 2 of the License, or |
fyazgan | 0:711905e937b9 | 6 | * (at your option) any later version. |
fyazgan | 0:711905e937b9 | 7 | * |
fyazgan | 0:711905e937b9 | 8 | * This program is distributed in the hope that it will be useful, but |
fyazgan | 0:711905e937b9 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
fyazgan | 0:711905e937b9 | 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fyazgan | 0:711905e937b9 | 11 | * for more details. |
fyazgan | 0:711905e937b9 | 12 | * |
fyazgan | 0:711905e937b9 | 13 | * You should have received a copy of the GNU General Public License along |
fyazgan | 0:711905e937b9 | 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
fyazgan | 0:711905e937b9 | 15 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
fyazgan | 0:711905e937b9 | 16 | * |
fyazgan | 0:711905e937b9 | 17 | * @section DESCRIPTION |
fyazgan | 0:711905e937b9 | 18 | * Library to interface with the SCP1000 pressure and temperature sensor. |
fyazgan | 0:711905e937b9 | 19 | */ |
fyazgan | 0:711905e937b9 | 20 | |
fyazgan | 0:711905e937b9 | 21 | #include "SCP1000.h" |
fyazgan | 0:711905e937b9 | 22 | |
fyazgan | 0:711905e937b9 | 23 | SCP1000::SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs) |
fyazgan | 0:711905e937b9 | 24 | : m_spi(mosi, miso, sclk) |
fyazgan | 0:711905e937b9 | 25 | , m_cs(cs) { |
fyazgan | 0:711905e937b9 | 26 | m_cs=1; |
fyazgan | 0:711905e937b9 | 27 | m_spi.frequency(500000); // the fastest of the sensor |
fyazgan | 0:711905e937b9 | 28 | m_spi.format(8, 0); // duda son dos palabras de 8 bits? |
fyazgan | 0:711905e937b9 | 29 | wait(0.5); |
fyazgan | 0:711905e937b9 | 30 | //------------------------------------------------ |
fyazgan | 0:711905e937b9 | 31 | // pc.printf("RESET\r\n"); |
fyazgan | 0:711905e937b9 | 32 | write_register(0x06,0x01); |
fyazgan | 0:711905e937b9 | 33 | wait(0.5); |
fyazgan | 0:711905e937b9 | 34 | |
fyazgan | 0:711905e937b9 | 35 | // pc.printf("Initialize High Resolution Constant Reading Mode\r\n"); |
fyazgan | 0:711905e937b9 | 36 | write_register(0x03,0x0A); |
fyazgan | 0:711905e937b9 | 37 | wait(0.5); |
fyazgan | 0:711905e937b9 | 38 | } |
fyazgan | 0:711905e937b9 | 39 | |
fyazgan | 0:711905e937b9 | 40 | unsigned long SCP1000::readPressure() { |
fyazgan | 0:711905e937b9 | 41 | unsigned long pressure_msb = read_register(PRESSURE); |
fyazgan | 0:711905e937b9 | 42 | pressure_msb &= 0x07; |
fyazgan | 0:711905e937b9 | 43 | unsigned long pressure_lsb = read_register16(PRESSURE_LSB); |
fyazgan | 0:711905e937b9 | 44 | unsigned long pressure = ((pressure_msb<<16)| pressure_lsb); |
fyazgan | 0:711905e937b9 | 45 | pressure /= 4; |
fyazgan | 0:711905e937b9 | 46 | |
fyazgan | 0:711905e937b9 | 47 | return pressure; |
fyazgan | 0:711905e937b9 | 48 | } |
fyazgan | 0:711905e937b9 | 49 | |
fyazgan | 0:711905e937b9 | 50 | float SCP1000::readTemperature() { |
fyazgan | 0:711905e937b9 | 51 | float temp_in = read_register16(TEMP); |
fyazgan | 0:711905e937b9 | 52 | temp_in /= 20; |
fyazgan | 0:711905e937b9 | 53 | return temp_in; |
fyazgan | 0:711905e937b9 | 54 | } |
fyazgan | 0:711905e937b9 | 55 | |
fyazgan | 0:711905e937b9 | 56 | char SCP1000::read_register(char register_name) { |
fyazgan | 0:711905e937b9 | 57 | register_name <<=2; |
fyazgan | 0:711905e937b9 | 58 | register_name &= 0xFC; |
fyazgan | 0:711905e937b9 | 59 | m_cs=0; //Select SPI device |
fyazgan | 0:711905e937b9 | 60 | m_spi.write(register_name); //Send register location |
fyazgan | 0:711905e937b9 | 61 | char register_value=m_spi.write(0x00); |
fyazgan | 0:711905e937b9 | 62 | m_cs=1; |
fyazgan | 0:711905e937b9 | 63 | return register_value; |
fyazgan | 0:711905e937b9 | 64 | } |
fyazgan | 0:711905e937b9 | 65 | |
fyazgan | 0:711905e937b9 | 66 | void SCP1000::write_register(char register_name, char register_value) { |
fyazgan | 0:711905e937b9 | 67 | register_name <<= 2; |
fyazgan | 0:711905e937b9 | 68 | register_name |= 0x02; //le estamos diciendo que escriba |
fyazgan | 0:711905e937b9 | 69 | m_cs=0; //Select SPI device |
fyazgan | 0:711905e937b9 | 70 | m_spi.write(register_name); //Send register location |
fyazgan | 0:711905e937b9 | 71 | m_spi.write(register_value); //Send value to record into register |
fyazgan | 0:711905e937b9 | 72 | m_cs=1; |
fyazgan | 0:711905e937b9 | 73 | } |
fyazgan | 0:711905e937b9 | 74 | |
fyazgan | 0:711905e937b9 | 75 | float SCP1000::read_register16(char register_name) { |
fyazgan | 0:711905e937b9 | 76 | register_name <<= 2; |
fyazgan | 0:711905e937b9 | 77 | register_name &= 0xFC; //Read command |
fyazgan | 0:711905e937b9 | 78 | m_cs=0; //Select SPI Device |
fyazgan | 0:711905e937b9 | 79 | m_spi.write(register_name); //Write byte to device |
fyazgan | 0:711905e937b9 | 80 | int in_byte1 = m_spi.write(0x00); |
fyazgan | 0:711905e937b9 | 81 | int in_byte2 = m_spi.write(0x00); |
fyazgan | 0:711905e937b9 | 82 | m_cs=1; |
fyazgan | 0:711905e937b9 | 83 | float in_word= (in_byte1<<=8) | (in_byte2); |
fyazgan | 0:711905e937b9 | 84 | return(in_word); |
fyazgan | 0:711905e937b9 | 85 | } |