Davide Urbano / Mbed OS microSDreader
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers adxl355.cpp Source File

adxl355.cpp

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    adxl355.cpp         
00004   * @author  DUR
00005   * @version V1.0.0  
00006   * @date    01-Aug-2017
00007   * @brief   Library for adxl355 interface.
00008   *
00009   * @par Manual Reference Names:
00010   *  1. "Low Noise, Low Drift, Low Power, 3-Axis MEMS Accelerometers
00011   *      ADXL354/ADXL355"
00012   *      9/2016—Revision 0: Initial Version  
00013   *
00014   * @par Document History:
00015   * 
00016   * Version: 1.0.0 (01/08/2017)
00017   * ----------------------------------------------------------------------------
00018   * Author: DUR
00019   * First release.
00020   * ----------------------------------------------------------------------------
00021   *
00022 @verbatim
00023 ================================================================================
00024                  ##### How to use this file #####
00025 ================================================================================
00026 Questa libreria è stata redatta per poter gestire ad alto livello il sensore di  
00027 accelerazione ad uscita digitale a 20 bit della Analog Devices ADXL355, dotato
00028 di un bus SPI/I2C per la comunicazione, insieme ad un pin per la segnalazione di 
00029 nuovi dati pronti e ben 2 pin di interrupt che sono configurabili per scattare a 
00030 seguito di ben precisi eventi interni.
00031 Perché si possa utilizzare questa libreria su di una qualunque piattaforma 
00032 hardware, la seguente funzione dovrà poi essere associata a quella di basso 
00033 livello:
00034     (+) uint16_t adxl355_spi_transfer(uint8_t * rbuffer, uint32_t rlen)
00035         < trasferimento su bus SPI >;
00036 Nella presente versione della libreria, sono state fatte le seguenti scelte 
00037 progettuali:
00038     (+) è stato scelto di utilizzare il bus SPI piuttosto che il bus I2C per la 
00039         comunicazione da e verso l'host;
00040     (+) è stato scelto l'utilizzo della sincronizzazione interna (EXT_SYNC = 0x00).
00041 L'accelerometro viene configurato dall'utente, per mezzo di una struttura dati 
00042 adxl355_handler, con la quale è possibile definire un setting di parametri 
00043 applicativi in base alle differenti esigenze. Nel suo utilizzo è importante tenere
00044 a mente le seguenti osservzioni:
00045     (i) dopo avere lanciato il comando di reset software (adxl355_sw_reset) il 
00046         sensore deve essere nuovamente inizializzato (adxl355_init);
00047     (i) per effettuare il self test, il sensore deve già essere in modalità di 
00048         acquisizione; il camando adxl355_self_test(true) dovrà essere lanciato 
00049         più volte perché ad ogni invocazione del metodo viene appicata una 
00050         specifica accelerazione all'interno, e quella che si andrà a rilevare
00051         sarà proprio la differenza tra i valori in g rilevati tra due invocazioni
00052         successive, e che dovrà rispettare i valori imposti dal datasheet.
00053 @endverbatim
00054 
00055   ******************************************************************************
00056 @attention
00057 <h2><center>&copy; COPYRIGHT(c) 2014 TD Group</center></h2>
00058 
00059 The information contained herein is property of TD Group S.p.A.
00060 
00061 Licensees are granted free, non-transferable use of the information. NO
00062 WARRANTY of ANY KIND is provided. This heading must NOT be removed from
00063 the file.
00064   ******************************************************************************
00065   */
00066 
00067 #define ADXL355_VERSION  1
00068 #define ADXL355_REVISION 0
00069 #define ADXL355_PATCH    0  
00070     
00071     
00072 /* Includes ------------------------------------------------------------------*/
00073 
00074 /** @brief   Add ONLY the header of THIS source file and not others.
00075  */
00076 
00077 #include "adxl355.h"
00078 
00079 /** @addtogroup FILE_FUNCTIONS
00080   * @{
00081   */
00082 
00083 
00084 
00085 /* Private function prototypes -----------------------------------------------*/
00086 /* Ricava da una maschera di bit, la posizione del primo bit della maschera stessa */
00087 static uint8_t  adxl355_get_bit_position(uint8_t gbp_mask);
00088 /* Setting dei parametri */
00089 static uint16_t adxl355_set_parameter(uint8_t sp_reg, uint8_t sp_mask_data, uint8_t sp_data);
00090 /* Lettura valore accelerazione lungo asse X, Y e Z */
00091 static uint16_t adxl355_read_acc_value(adxl355_handler *adxl_acc);
00092 /* Lettura valore di temperatura */
00093 static uint16_t adxl355_read_temp_value(adxl355_handler *adxl_temp);
00094 
00095 
00096 /* Private variables ---------------------------------------------------------*/
00097 /* Definisce in ogni momento quali misure sono attive */
00098 static adxl355_measure_enabled adxl_measure_on;
00099 
00100 
00101 /* Exported variables --------------------------------------------------------*/
00102 
00103 
00104 /* Private functions ---------------------------------------------------------*/
00105 
00106 /** @defgroup Group1 Private_Functions      
00107  *  @brief    Function used only in this file and NOT visible to the rest of the 
00108  *            code. 
00109  *  @{
00110  */
00111 
00112 
00113 /**
00114   *  @brief   Ricava da una maschera di bit, la posizione del primo bit della maschera 
00115   *           stessa.
00116   *  @note    No one.
00117   *  @param   gbp_mask           maschera di bit
00118   *  @retval  uint8_t            posizione del primo bit nella maschera
00119   *  @todo    Nothing.
00120   *  @warning No one.
00121   */  
00122 static uint8_t adxl355_get_bit_position(uint8_t gbp_mask)
00123 {
00124     uint8_t gbp_index;
00125     
00126     for(gbp_index = 0; gbp_index < 8; gbp_index++)
00127     {
00128         if(((gbp_mask>>gbp_index) & 0x01) != 0)
00129         {
00130             break;
00131         }else{}
00132     }
00133     
00134     return gbp_index;
00135 }
00136 
00137 
00138 /**
00139   *  @brief   Funzione per la scrittura di un parametro su di un registro dell'accelerometro.
00140   *  @note    No one.
00141   *  @param   sp_reg             indirizzo del registro da settare
00142   *  @param   sp_mask_data       posizione del/i bit da settare sotto forma di maschera
00143   *  @param   sp_data            valore del/i bit da settare
00144   *  @retval  uint16_t           errore restituito dal metodo (se 0, tutto ok)
00145   *  @todo    Nothing.
00146   *  @warning No one.
00147   */ 
00148 static uint16_t adxl355_set_parameter(uint8_t sp_reg, uint8_t sp_mask_data, uint8_t sp_data)
00149 {
00150     uint16_t adxl_sp_error = 0u;
00151     uint8_t  adxl_sp_data[2];       
00152     
00153     /* Lettura del registro */  
00154     adxl_sp_data[0] = (uint8_t)((sp_reg << 1) | ADXL355_READ_BYTE_MASK);
00155     adxl_sp_data[1] = 0x00;
00156     if(adxl355_spi_transfer((uint8_t*)&adxl_sp_data, 2) == 0)
00157     {
00158         adxl_sp_data[0]  = (uint8_t)((sp_reg << 1) & ADXL355_WRITE_BYTE_MASK);      
00159         adxl_sp_data[1] &= (uint8_t)~sp_mask_data;
00160         adxl_sp_data[1] |= (uint8_t)(sp_data << (adxl355_get_bit_position(sp_mask_data)));
00161         /* Scrittura del nuovo valore */
00162         if(adxl355_spi_transfer((uint8_t*)&adxl_sp_data, 2) == 0)
00163         {}
00164         else
00165         {
00166             adxl_sp_error = (uint16_t)__LINE__;//ERRORE SCRITTURA REGISTRO
00167         }   
00168     }
00169     else
00170     {
00171         adxl_sp_error = (uint16_t)__LINE__;//ERRORE LETTURA REGISTRO
00172     }
00173     
00174     return adxl_sp_error;
00175 }
00176 
00177 
00178 /**
00179   *  @brief   Funzione di lettura del dato grezzo di accelerazione lungo gli assi 
00180   *           X, Y e Z dell'accelerometro.
00181   *  @note    No one.
00182   *  @param   adxl_acc      puntatore all'handler dell'accelerometro 
00183   *  @retval  uint16_t      errore restituito dal metodo (se 0, tutto ok)
00184   *  @todo    No one.
00185   *  @warning No one.
00186   */ 
00187 static uint16_t adxl355_read_acc_value(adxl355_handler *adxl_acc)
00188 {
00189     uint16_t adxl_read_acc_error = 0u;
00190     uint8_t  adxl_read_acc_data[10];
00191     /* Azzeramento buffer dati SPI */
00192     memset(adxl_read_acc_data, 0x00, 10);
00193     adxl_read_acc_data[0u] = (uint8_t)((ADXL355_XDATA3<<1) | ADXL355_READ_BYTE_MASK);
00194     
00195     if(adxl355_spi_transfer((uint8_t*)&adxl_read_acc_data, 10) == 0)
00196     {
00197         adxl_acc->raw_acc_x_value = 0u;
00198         adxl_acc->raw_acc_x_value = (adxl_read_acc_data[1]<<16u) | (adxl_read_acc_data[2]<<8u) | (adxl_read_acc_data[3]);
00199         adxl_acc->raw_acc_x_value = (adxl_acc->raw_acc_x_value>>4u) & ADXL355_20_BIT_MASK;
00200         
00201         adxl_acc->raw_acc_y_value = 0u;
00202         adxl_acc->raw_acc_y_value = (adxl_read_acc_data[4]<<16u) | (adxl_read_acc_data[5]<<8u) | (adxl_read_acc_data[6]);
00203         adxl_acc->raw_acc_y_value = (adxl_acc->raw_acc_y_value>>4u) & ADXL355_20_BIT_MASK;      
00204         
00205         adxl_acc->raw_acc_z_value = 0u;
00206         adxl_acc->raw_acc_z_value = (adxl_read_acc_data[7]<<16u) | (adxl_read_acc_data[8]<<8u) | (adxl_read_acc_data[9]);
00207         adxl_acc->raw_acc_z_value = (adxl_acc->raw_acc_z_value>>4u) & ADXL355_20_BIT_MASK;      
00208     }
00209     else
00210     {
00211         adxl_read_acc_error = (uint16_t)__LINE__;//ERRORE LETTURA DATI ACCELERAZIONE
00212     }
00213         
00214     return adxl_read_acc_error;
00215 }
00216 
00217 
00218 
00219 /**
00220   *  @brief   Funzione di lettura del dato grezzo di temperatura fornito dall'accelerometro.
00221   *  @note    No one.
00222   *  @param   adxl_temp      puntatore all'handler dell'accelerometro 
00223   *  @retval  uint16_t      errore restituito dal metodo (se 0, tutto ok)
00224   *  @todo    No one.
00225   *  @warning No one.
00226   */ 
00227 static uint16_t adxl355_read_temp_value(adxl355_handler *adxl_temp)
00228 {
00229     uint16_t adxl_read_temp_error = 0u;
00230     uint8_t  adxl_read_temp_data[3];
00231     /* Azzeramento buffer dati SPI */
00232     memset(adxl_read_temp_data, 0x00, 3);
00233     adxl_read_temp_data[0u] = (uint8_t)((ADXL355_TEMP2<<1) | ADXL355_READ_BYTE_MASK);
00234     
00235     if(adxl355_spi_transfer((uint8_t*)&adxl_read_temp_data, 3) == 0)
00236     {
00237         adxl_temp->raw_temp_value = 0u;
00238         adxl_temp->raw_temp_value = (adxl_read_temp_data[1]<<8u) | adxl_read_temp_data[2];
00239         adxl_temp->raw_temp_value &=  ADXL355_12_BIT_MASK;      
00240     }
00241     else
00242     {
00243         adxl_read_temp_error = (uint16_t)__LINE__;//ERRORE LETTURA DATI ACCELERAZIONE
00244     }
00245         
00246     return adxl_read_temp_error;    
00247 }
00248     
00249     
00250 
00251 
00252 
00253 
00254 /**
00255   * @}
00256   */
00257 
00258   
00259 /* Exported functions --------------------------------------------------------*/
00260 
00261 /** @defgroup Group2 Exported_Functions      
00262  *  @brief    Functions used in this file and also visible to the rest of the 
00263  *            code.
00264  *  @{
00265  */  
00266   
00267 
00268   
00269 /**
00270 *  @brief   Funzione che restituisce i parametri identificativi del driver.
00271 *  @note    No one.
00272 *  @param   adxl355_driver_version    puntatore all'identificatore di versione del driver 
00273 *  @param   adxl355_driver_revision   puntatore all'identificatore di revisione del driver 
00274 *  @param   adxl355_driver_patch      puntatore all'identificatore di patch del driver 
00275 *  @retval  No one.
00276 *  @todo    No one.
00277 *  @warning No one.
00278 */ 
00279 void adxl355_driver_info(uint8_t * adxl355_driver_version, uint8_t * adxl355_driver_revision, uint8_t * adxl355_driver_patch)
00280 {
00281     *adxl355_driver_version  = ADXL355_VERSION;
00282     *adxl355_driver_revision = ADXL355_REVISION;
00283     *adxl355_driver_patch    = ADXL355_PATCH;   
00284 }
00285 
00286  
00287 /**
00288 *  @brief   Funzione che restituisce l'ID dell'accelerometro.
00289 *  @note    No one.
00290 *  @param   adxl355_device_id    puntatore all'identificatore del device 
00291 *  @retval  uint16_t             errore restituito dal metodo (se 0, tutto ok)
00292 *  @todo    No one.
00293 *  @warning No one.
00294 */ 
00295 uint16_t adxl355_who_am_i(uint8_t * adxl355_device_id)
00296 {
00297     uint16_t adxl_whoami_error = 0u;
00298     uint8_t  adxl_whoami_data[2];       
00299     
00300     /* Lettura del registro */  
00301     adxl_whoami_data[0] = (uint8_t)((ADXL355_PARTID << 1) | ADXL355_READ_BYTE_MASK);
00302     adxl_whoami_data[1] = 0x00;
00303     if(adxl355_spi_transfer((uint8_t*)&adxl_whoami_data, 2) == 0)   
00304     {
00305         *adxl355_device_id = adxl_whoami_data[1];
00306     }
00307     else
00308     {
00309         adxl_whoami_error = (uint16_t)__LINE__;//ERRORE LETTURA ID
00310     }
00311     
00312     return adxl_whoami_error;
00313 }   
00314   
00315   
00316 /**
00317   *  @brief   Funzione di inizializzazione dell'accelerometro.
00318   *  @note    No one.
00319   *  @param   adxl_init_handler      puntatore all'handler dell'accelerometro 
00320   *  @retval  uint16_t               errore restituito dal metodo (se 0, tutto ok)
00321   *  @todo    No one.
00322   *  @warning No one.
00323   */ 
00324 uint16_t adxl355_init(adxl355_handler *adxl_init_handler)
00325 {
00326     uint16_t adxl_init_error = 0u;
00327     uint8_t  adxl_init_state = 0u;  
00328     
00329     switch(adxl_init_state)
00330     {       
00331         case 0:/* Configurazione range di misura */
00332             if(0u == adxl355_set_parameter(ADXL355_RANGE, ADXL355_RANGE_MASK, (uint8_t)adxl_init_handler->measure_range))
00333             {}
00334             else
00335             {
00336                 adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING RANGE DI MISURA
00337                 break;
00338             }           
00339                 
00340                 
00341         case 1:/* Configurazione output data rate */
00342             if(0u == adxl355_set_parameter(ADXL355_FILTER, ADXL355_ODR_MASK, (uint8_t)adxl_init_handler->out_data_rate))
00343             {}
00344             else
00345             {
00346                 adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING OUTPUT DATA RATE
00347                 break;
00348             }               
00349                 
00350                 
00351         case 2:/* Configurazione polarità interrupt */
00352             if((adxl_init_handler->int1_pin == NULL) && 
00353                (adxl_init_handler->int2_pin == NULL)){}//Se i pin non sono configurati, è inutile configurare la polarità degli interrupt
00354             else
00355             {
00356                 if(0u == adxl355_set_parameter(ADXL355_RANGE, ADXL355_ODR_MASK, (adxl_init_handler->int_config.int_act_low==true) ? 0:1))
00357                 {}
00358                 else
00359                 {
00360                     adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING POLARITA' INTERRUPT
00361                     break;
00362                 }
00363             }           
00364                 
00365         
00366         case 3:/* Configurazione interrupt 1 */
00367             if(adxl_init_handler->int1_pin == NULL){}//Se il pin non è configurato, è inutile configurare il relativo interrupt
00368             else        
00369             {
00370                 if(0u == adxl355_set_parameter(ADXL355_INT_MAP, ADXL355_INT_1_MASK, (uint8_t)adxl_init_handler->int_config.int1_evt))
00371                 {}
00372                 else
00373                 {
00374                     adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING EVENTO ASSOCIATO AD INTERRUPT 1
00375                     break;
00376                 }                                   
00377             }
00378             
00379     
00380         case 4:/* Configurazione interrupt 2 */
00381             if(adxl_init_handler->int2_pin == NULL){}//Se il pin non è configurato, è inutile configurare il relativo interrupt
00382             else        
00383             {
00384                 if(0u == adxl355_set_parameter(ADXL355_INT_MAP, ADXL355_INT_2_MASK, (uint8_t)adxl_init_handler->int_config.int2_evt))
00385                 {}
00386                 else
00387                 {
00388                     adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING EVENTO ASSOCIATO AD INTERRUPT 2
00389                     break;
00390                 }                                   
00391             }               
00392             
00393         
00394         case 5:/* Stop di tutte le possibili misure */
00395             if(0u == adxl355_start_acquisition(adxl355_none))
00396             {}
00397             else
00398             {
00399                 adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING STOP MISURE
00400                 break;
00401             }   
00402             
00403 
00404         case 6:/* Self-test disabilitato */
00405             if(0u == adxl355_self_test(false))
00406             {}
00407             else
00408             {
00409                 adxl_init_error = (uint16_t)__LINE__;//ERRORE DISABILITAZIONE SELF-TEST
00410                 break;
00411             }           
00412         
00413             
00414         default:        
00415             break;      
00416     }
00417                                 
00418     return adxl_init_error; 
00419 }
00420 
00421 
00422 
00423 /**
00424   *  @brief   Funzione di start/stop delle acquisizioni.
00425   *  @note    No one.
00426   *  @param   adxl_start      misura/e da avviare 
00427   *  @retval  uint16_t        errore restituito dal metodo (se 0, tutto ok)
00428   *  @todo    No one.
00429   *  @warning No one.
00430   */
00431 uint16_t adxl355_start_acquisition(adxl355_measure_enabled adxl_start)
00432 {
00433     uint16_t adxl_start_error = 0u; 
00434     uint8_t  adxl_start_data;   
00435         
00436     switch(adxl_start)
00437     {
00438         case 0://Solo accelerazione
00439             adxl_start_data = 0x02;
00440             break;  
00441 
00442         case 1://Entrambe le misure (accelerazione e temperatura)
00443             adxl_start_data = 0x00;
00444             break;  
00445 
00446         case 2://Nessuna misura (mette in standby il sensore)
00447             adxl_start_data = 0x03;
00448             break;          
00449         
00450         default:
00451             break;      
00452     }
00453     
00454     if(0u == adxl355_set_parameter(ADXL355_POWER_CTL, ADXL355_MEAS_MASK, adxl_start_data))
00455     {
00456         adxl_measure_on = adxl_start;       
00457     }
00458     else
00459     {
00460         adxl_start_error = (uint16_t)__LINE__;//ERRORE SETTING RANGE DI MISURA      
00461     }   
00462         
00463     return adxl_start_error;
00464 }
00465 
00466 
00467 
00468 /**
00469   *  @brief   Funzione per la lettura del/i dato/i acquisito/i.
00470   *  @note    No one.
00471   *  @param   adxl_data_handler      puntatore all'handler dell'accelerometro 
00472   *  @retval  uint16_t               errore restituito dal metodo (se 0, tutto ok)
00473   *  @todo    No one.
00474   *  @warning No one.
00475   */
00476 uint16_t adxl355_get_data(adxl355_handler *adxl_data_handler)  
00477 {
00478     uint16_t adxl_data_error = 0u;      
00479     
00480     if((adxl_measure_on == adxl355_acc) || (adxl_measure_on == adxl355_both))
00481     {   /* Lettura accelerazione */
00482         if(adxl355_read_acc_value(adxl_data_handler) == 0u)
00483         {
00484             if(adxl_measure_on == adxl355_both)
00485             {   /* Lettura temperatura */
00486                 if(adxl355_read_temp_value(adxl_data_handler) == 0u)
00487                 {}
00488                 else 
00489                 {
00490                     adxl_data_error = (uint16_t)__LINE__;//ERRORE LETTURA MISURA TEMPERATURA 
00491                 }               
00492             }
00493             else{}
00494             
00495         }
00496         else
00497         {
00498             adxl_data_error = (uint16_t)__LINE__;//ERRORE LETTURA MISURA ACCELERAZIONE 
00499         }
00500     }else{}
00501 
00502     return adxl_data_error;
00503 }
00504 
00505 
00506 
00507 /**
00508   *  @brief   Funzione che restituisce il valore grezzo di accelerazione lungo l'asse X.
00509   *  @note    No one.
00510   *  @param   adxl_xdata_handler     puntatore all'handler dell'accelerometro 
00511   *  @retval  uint32_t               valore grezzo accelerazione
00512   *  @todo    No one.
00513   *  @warning No one.
00514   */
00515 uint32_t adxl355_raw_x_acc(adxl355_handler *adxl_xdata_handler)
00516 {
00517     return adxl_xdata_handler->raw_acc_x_value;
00518 }
00519 
00520 
00521 
00522 /**
00523   *  @brief   Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Y.
00524   *  @note    No one.
00525   *  @param   adxl_ydata_handler     puntatore all'handler dell'accelerometro 
00526   *  @retval  uint32_t               valore grezzo accelerazione
00527   *  @todo    No one.
00528   *  @warning No one.
00529   */
00530 uint32_t adxl355_raw_y_acc(adxl355_handler *adxl_ydata_handler)
00531 {
00532     return adxl_ydata_handler->raw_acc_y_value;
00533 }
00534 
00535 
00536 
00537 /**
00538   *  @brief   Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Z.
00539   *  @note    No one.
00540   *  @param   adxl_zdata_handler     puntatore all'handler dell'accelerometro 
00541   *  @retval  uint32_t               valore grezzo accelerazione
00542   *  @todo    No one.
00543   *  @warning No one.
00544   */
00545 uint32_t adxl355_raw_z_acc(adxl355_handler *adxl_zdata_handler)
00546 {
00547     return adxl_zdata_handler->raw_acc_z_value;
00548 }
00549 
00550 
00551 
00552 /**
00553   *  @brief   Funzione che restituisce il valore grezzo di temperatura.
00554   *  @note    No one.
00555   *  @param   adxl_tdata_handler     puntatore all'handler dell'accelerometro 
00556   *  @retval  uint16_t               valore grezzo temperatura
00557   *  @todo    No one.
00558   *  @warning No one.
00559   */
00560 uint16_t adxl355_raw_temp(adxl355_handler *adxl_tdata_handler)
00561 {
00562     return adxl_tdata_handler->raw_temp_value;
00563 }
00564 
00565 
00566 
00567 /**
00568   *  @brief   Funzione per il reset sw.
00569   *  @note    No one.
00570   *  @param   No one.
00571   *  @retval  uint16_t               errore restituito dal metodo (se 0, tutto ok)
00572   *  @todo    No one.
00573   *  @warning No one.
00574   */
00575 uint16_t adxl355_sw_reset(void)
00576 {
00577     uint16_t adxl_swres_error = 0u;
00578     uint8_t  adxl_swres_data[2];        
00579     
00580     /* Lettura del registro */  
00581     adxl_swres_data[0] = (uint8_t)((ADXL355_RESET << 1) & ADXL355_WRITE_BYTE_MASK);
00582     adxl_swres_data[1] = ADXL355_RESET_CODE;
00583     if(adxl355_spi_transfer((uint8_t*)&adxl_swres_data, 2) == 0)    
00584     {}
00585     else
00586     {
00587         adxl_swres_error = (uint16_t)__LINE__;//ERRORE RESET ACCELEROMETRO
00588     }
00589     
00590     return adxl_swres_error;
00591 }
00592 
00593 
00594 
00595 /**
00596   *  @brief   Funzione per il self-test.
00597   *  @note    Questo metodo va utilizzato lanciandolo ponendo a true adxl_start
00598   *           ad acquisizione in corso; in questa modalità il metodo va lanciato 
00599   *           diverse volte in modo che si possa registrare la variazione di 
00600   *           accelerazione sui 3 assi che deve essere, secondo datasheet:
00601   *           [X]: 0.3g
00602   *           [Y]: 0.3g
00603   *           [Z]: 1.5g
00604   *           In modalità self-test, il sensore non registra alcuna accelerazione 
00605   *           esterna; ponendo a false adxl_start, il sensore termina il self-test 
00606   *           e ritorna in modalità normale di funzionamento.
00607   *  @param   adxl_start          booleano per avviare/fermare il self test
00608   *  @retval  uint16_t            errore restituito dal metodo (se 0, tutto ok)
00609   *  @todo    No one.
00610   *  @warning No one.
00611   */
00612 uint16_t adxl355_self_test(bool adxl_start)
00613 {
00614     uint16_t adxl_st_error = 0u;
00615     static uint8_t adxl_st2_val = 0u;
00616     
00617     if(adxl_start == true)
00618     {           
00619         adxl_measure_on = adxl355_acc;
00620         if(0u == adxl355_set_parameter(ADXL355_SELF_TEST, ADXL355_SELF_TEST_MASK, (adxl_st2_val<<1)|ADXL355_SELF_TEST_ENABLE ))
00621         {
00622             if(adxl_st2_val == 0u) adxl_st2_val = 1u;
00623             else adxl_st2_val = 0u;
00624         }
00625         else    
00626         {
00627             adxl_st_error = (uint16_t)__LINE__;//ERRORE AVVIO SELF-TEST     
00628         }
00629     }
00630     else
00631     {
00632         if(0u == adxl355_set_parameter(ADXL355_SELF_TEST, ADXL355_SELF_TEST_MASK, ADXL355_SELF_TEST_DISABLE))
00633         {
00634             adxl_st2_val = 0u;
00635         }
00636         else    
00637         {
00638             adxl_st_error = (uint16_t)__LINE__;//ERRORE STOP SELF-TEST      
00639         }       
00640     }
00641         
00642     return adxl_st_error;
00643 }
00644 
00645 
00646 
00647 /**
00648   * @}
00649   */
00650 
00651 
00652 
00653  /**
00654   * @}
00655   */ 
00656   
00657 /************************ (C) COPYRIGHT TD Group *****END OF FILE**************/
00658 
00659