@@ -35,60 +35,60 @@ LIS3DHTR<T>::LIS3DHTR()
35
35
36
36
}
37
37
38
- // template <class T>
39
- // void LIS3DHTR<T>::begin(SPIClass &comm, uint8_t sspin)
40
- // {
41
- // chipSelectPin = sspin;
42
- // _spi_com = &comm;
43
- // _wire_com = NULL;
44
- // pinMode(chipSelectPin, OUTPUT);
45
- // digitalWrite(chipSelectPin, HIGH);
38
+ template <class T >
39
+ void LIS3DHTR<T>::begin(SPIClass &comm, uint8_t sspin)
40
+ {
41
+ chipSelectPin = sspin;
42
+ _spi_com = &comm;
43
+ _wire_com = NULL ;
44
+ pinMode (chipSelectPin, OUTPUT);
45
+ digitalWrite (chipSelectPin, HIGH);
46
46
47
- // // Maximum SPI frequency is 10MHz, Data is read and written MSb first,
48
- // // Data is captured on rising edge of clock (CPHA = 0)
49
- // // Base value of the clock is HIGH (CPOL = 1)
50
- // // MODE3 for 328p operation
51
- // SPISettings _settings(10000000, MSBFIRST, SPI_MODE3);
47
+ // Maximum SPI frequency is 10MHz, Data is read and written MSb first,
48
+ // Data is captured on rising edge of clock (CPHA = 0)
49
+ // Base value of the clock is HIGH (CPOL = 1)
50
+ // MODE3 for 328p operation
51
+ SPISettings _settings (10000000 , MSBFIRST, SPI_MODE3);
52
52
53
- // // start the SPI library:
54
- // _spi_com->begin();
53
+ // start the SPI library:
54
+ _spi_com->begin ();
55
55
56
- // delay(200);
56
+ delay (200 );
57
57
58
- // uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
59
- // LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
58
+ uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
59
+ LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
60
60
61
- // writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
62
- // delay(LIS3DHTR_CONVERSIONDELAY);
61
+ writeRegister (LIS3DHTR_REG_TEMP_CFG, config5);
62
+ delay (LIS3DHTR_CONVERSIONDELAY);
63
63
64
- // uint8_t config1 = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL | // Normal Mode
65
- // LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE | // Acceleration Z-Axis Enabled
66
- // LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE | // Acceleration Y-Axis Enabled
67
- // LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
64
+ uint8_t config1 = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL | // Normal Mode
65
+ LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE | // Acceleration Z-Axis Enabled
66
+ LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE | // Acceleration Y-Axis Enabled
67
+ LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
68
68
69
- // writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
70
- // delay(LIS3DHTR_CONVERSIONDELAY);
69
+ writeRegister (LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
70
+ delay (LIS3DHTR_CONVERSIONDELAY);
71
71
72
- // uint8_t config4 = LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED | // Continuous Update
73
- // LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB | // Data LSB @ lower address
74
- // LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE | // High Resolution Disable
75
- // LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL | // Normal Mode
76
- // LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE; // 4-Wire Interface
72
+ uint8_t config4 = LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED | // Continuous Update
73
+ LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB | // Data LSB @ lower address
74
+ LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE | // High Resolution Disable
75
+ LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL | // Normal Mode
76
+ LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE; // 4-Wire Interface
77
77
78
- // writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, config4);
78
+ writeRegister (LIS3DHTR_REG_ACCEL_CTRL_REG4, config4);
79
79
80
- // delay(LIS3DHTR_CONVERSIONDELAY);
80
+ delay (LIS3DHTR_CONVERSIONDELAY);
81
81
82
- // setFullScaleRange(LIS3DHTR_RANGE_16G);
83
- // setOutputDataRate(LIS3DHTR_DATARATE_400HZ);
84
- // }
82
+ setFullScaleRange (LIS3DHTR_RANGE_16G);
83
+ setOutputDataRate (LIS3DHTR_DATARATE_400HZ);
84
+ }
85
85
86
86
template <class T >
87
87
void LIS3DHTR<T>::begin(TwoWire &wire, uint8_t address)
88
88
{
89
89
_wire_com = &wire;
90
90
_wire_com->begin ();
91
- // _spi_com = NULL;
91
+ _spi_com = NULL ;
92
92
devAddr = address;
93
93
94
94
uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
@@ -360,22 +360,22 @@ uint16_t LIS3DHTR<T>::readbitADC3(void)
360
360
template <class T >
361
361
void LIS3DHTR<T>::writeRegister(uint8_t reg, uint8_t val)
362
362
{
363
- // if (_spi_com != NULL)
364
- // {
365
- // _spi_com->beginTransaction(_settings);
366
- // digitalWrite(chipSelectPin, LOW);
367
- // _spi_com->transfer(reg);
368
- // _spi_com->transfer(val);
369
- // digitalWrite(chipSelectPin, HIGH);
370
- // _spi_com->endTransaction();
371
- // }
372
- // else
373
- // {
363
+ if (_spi_com != NULL )
364
+ {
365
+ _spi_com->beginTransaction (_settings);
366
+ digitalWrite (chipSelectPin, LOW);
367
+ _spi_com->transfer (reg);
368
+ _spi_com->transfer (val);
369
+ digitalWrite (chipSelectPin, HIGH);
370
+ _spi_com->endTransaction ();
371
+ }
372
+ else
373
+ {
374
374
_wire_com->beginTransmission (devAddr);
375
375
_wire_com->write (reg);
376
376
_wire_com->write (val);
377
377
_wire_com->endTransmission ();
378
- // }
378
+ }
379
379
}
380
380
381
381
template <class T >
@@ -386,23 +386,23 @@ void LIS3DHTR<T>::readRegisterRegion(uint8_t *outputPointer, uint8_t reg, uint8_
386
386
uint8_t i = 0 ;
387
387
uint8_t c = 0 ;
388
388
389
- // if (_spi_com != NULL)
390
- // {
391
- // _spi_com->beginTransaction(_settings);
392
- // digitalWrite(chipSelectPin, LOW);
393
- // _spi_com->transfer(reg | 0x80 | 0x40); //Ored with "read request" bit and "auto increment" bit
394
- // while (i < length) // slave may send less than requested
395
- // {
396
- // c = _spi_com->transfer(0x00); // receive a byte as character
397
- // *outputPointer = c;
398
- // outputPointer++;
399
- // i++;
400
- // }
401
- // digitalWrite(chipSelectPin, HIGH);
402
- // _spi_com->endTransaction();
403
- // }
404
- // else
405
- // {
389
+ if (_spi_com != NULL )
390
+ {
391
+ _spi_com->beginTransaction (_settings);
392
+ digitalWrite (chipSelectPin, LOW);
393
+ _spi_com->transfer (reg | 0x80 | 0x40 ); // Ored with "read request" bit and "auto increment" bit
394
+ while (i < length) // slave may send less than requested
395
+ {
396
+ c = _spi_com->transfer (0x00 ); // receive a byte as character
397
+ *outputPointer = c;
398
+ outputPointer++;
399
+ i++;
400
+ }
401
+ digitalWrite (chipSelectPin, HIGH);
402
+ _spi_com->endTransaction ();
403
+ }
404
+ else
405
+ {
406
406
407
407
_wire_com->beginTransmission (devAddr);
408
408
reg |= 0x80 ; // turn auto-increment bit on, bit 7 for I2C
@@ -417,7 +417,7 @@ void LIS3DHTR<T>::readRegisterRegion(uint8_t *outputPointer, uint8_t reg, uint8_
417
417
outputPointer++;
418
418
i++;
419
419
}
420
- // }
420
+ }
421
421
}
422
422
423
423
template <class T >
@@ -473,5 +473,5 @@ void LIS3DHTR<T>::click(uint8_t c, uint8_t click_thresh, uint8_t limit, uint8_t
473
473
template <class T >
474
474
LIS3DHTR<T>::operator bool () { return isConnection (); }
475
475
476
- // template class LIS3DHTR<SPIClass>;
476
+ template class LIS3DHTR <SPIClass>;
477
477
template class LIS3DHTR <TwoWire>;
0 commit comments