there is a problem. i cant send data continuously.

Dependencies:   EthernetNetIf mbed HMC6352 ITG3200 ADXL345 IMUfilter

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SCP1000.cpp Source File

SCP1000.cpp

00001 /**
00002  * @section LICENSE
00003  * This program is free software; you can redistribute it and/or modify 
00004  * it under the terms of the GNU General Public License as published by 
00005  * the Free Software Foundation; either version 2 of the License, or 
00006  * (at your option) any later version.
00007  * 
00008  * This program is distributed in the hope that it will be useful, but 
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
00010  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
00011  * for more details.
00012  * 
00013  * You should have received a copy of the GNU General Public License along 
00014  * with this program; if not, write to the Free Software Foundation, Inc., 
00015  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00016  *
00017  * @section DESCRIPTION
00018  * Library to interface with the SCP1000 pressure and temperature sensor.
00019  */
00020 
00021 #include "SCP1000.h"
00022 
00023 SCP1000::SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs)
00024     : m_spi(mosi, miso, sclk)
00025     , m_cs(cs) {
00026     m_cs=1;
00027     m_spi.frequency(500000); // the fastest of the sensor
00028     m_spi.format(8, 0); // duda son dos palabras de 8 bits? 
00029     wait(0.5);
00030     //------------------------------------------------
00031     // pc.printf("RESET\r\n");
00032     write_register(0x06,0x01);
00033     wait(0.5);
00034 
00035     // pc.printf("Initialize High Resolution Constant Reading Mode\r\n");
00036     write_register(0x03,0x0A);
00037     wait(0.5);
00038 }
00039 
00040 unsigned long SCP1000::readPressure() {
00041     unsigned long pressure_msb = read_register(PRESSURE);
00042     pressure_msb &= 0x07;
00043     unsigned long pressure_lsb = read_register16(PRESSURE_LSB);
00044     unsigned long pressure = ((pressure_msb<<16)| pressure_lsb);
00045     pressure /= 4;
00046     
00047     return pressure;
00048 }
00049 
00050 float SCP1000::readTemperature() {
00051     float temp_in = read_register16(TEMP);
00052     temp_in /= 20;
00053     return temp_in;
00054 }
00055 
00056  char SCP1000::read_register(char register_name) {
00057     register_name <<=2;
00058     register_name &= 0xFC;
00059     m_cs=0; //Select SPI device
00060     m_spi.write(register_name); //Send register location
00061     char register_value=m_spi.write(0x00);
00062     m_cs=1;
00063     return register_value;  
00064 }
00065 
00066 void SCP1000::write_register(char register_name, char register_value) {
00067     register_name <<= 2;
00068     register_name |= 0x02; //le estamos diciendo que escriba
00069     m_cs=0; //Select SPI device
00070     m_spi.write(register_name); //Send register location
00071     m_spi.write(register_value); //Send value to record into register
00072     m_cs=1;
00073 }
00074 
00075 float SCP1000::read_register16(char register_name) {   
00076     register_name <<= 2;
00077     register_name &= 0xFC; //Read command
00078     m_cs=0; //Select SPI Device
00079     m_spi.write(register_name); //Write byte to device
00080     int in_byte1 = m_spi.write(0x00);    
00081     int in_byte2 = m_spi.write(0x00);
00082     m_cs=1;
00083     float in_word= (in_byte1<<=8) | (in_byte2);   
00084     return(in_word);
00085 }