Advanced functions

The Accelerometer module working mode is to set and read registers, thus when it is wanted to change a data a register is set and when data wants to be read a register is read. There are some functions for writing and reading registers. As well, there are some registers that are used to configure the accelerometer module. These registers are called CTRL_REG1, CTRL_REG2, CTRL_REG3, CTRL_REG4 and CTRL_REG5 and are defined in the Waspmote ACC library as constants.

Some functions have been created to set and read these registers. However, these functions are not necessary for a basic accelerometer use.

Writing a register

It writes a byte into a register in the accelerometer.

It returns 1 if there is no error or 0 if there is error.

Example of use:

{
uint8_t reg1 = B01000111;
ACC.writeRegister(CTRL_REG1,reg1);
}

Reading a register

It reads a register from the accelerometer.

It returns 1 if there is no error or 0 if there is error.

Example of use:

{
uint16_t statusRegister = 0;
statusRegister = ACC.readRegister(statusReg);
}

Setting CTRL_REG1

It sets accelerometer's control register 1.

It returns '0' if error.

Since it calls writeRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg1 = B00100111;
ACC.setCTRL1(reg1);
}

Getting CTRL_REG1

It checks accelerometer's control register 1.

It returns the contents of control register 1.

Since it calls readRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg1;
reg1 = ACC.getCTRL1();
}

Setting CTRL_REG2

It sets accelerometer's control register 2.

It returns '0' if error.

Since it calls writeRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg2 = B00001000;
ACC.setCTRL2(reg2);
}

Getting CTRL_REG2

It checks accelerometer's control register 2.

It returns the contents of control register 2.

Since it calls readRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg2;
reg2 = ACC.getCTRL2();
}

Setting CTRL_REG3

It sets accelerometer's control register 3.

It returns '0' if error.

Since it calls writeRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg3 = B00001000;
ACC.setCTRL3(reg3);
}

Getting CTRL_REG3

It checks accelerometer's control register 3.

It returns the contents of control register 3.

Since it calls readRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg3;
reg3 = ACC.getCTRL3();
}

Setting CTRL_REG4

It sets accelerometer's control register 4.

It returns '0' if error.

Since it calls writeRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg4 = B00001000;
ACC.setCTRL4(reg4);
}

Getting CTRL_REG4

It checks accelerometer's control register 4.

It returns the contents of control register 4.

Since it calls readRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg4;
reg4 = ACC.getCTRL4();
}

Setting CTRL_REG5

It sets accelerometer's control register 5.

It returns '0' if error.

Since it calls writeRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg5 = B00001000;
ACC.setCTRL5(reg5);
}

Getting CTRL_REG5

It checks accelerometer's control register 5.

It returns the contents of control register 5.

Since it calls readRegister(), it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING in case there was an error when communicating to the register.

Example of use:

{
uint8_t reg5;
reg5 = ACC.getCTRL5();
}

Sleep to wake mode

The sleep to wake function, in conjunction with Low Power mode, allows further reduction of system power consumption and the development of new smart applications. The accelerometer can be set in a low-power operating mode, characterized by lower date rate refreshments. In this way the device, even if "sleeping", continues sensing acceleration and generating interrupt requests.

When the sleep to wake function is activated, the accelerometer is able to automatically wake up Waspmote as soon as the interrupt event has been detected, increasing the output data rate and bandwidth. With this feature the Waspmote can be efficiently switched from Low Power mode to full performance, depending on user-selectable positioning and acceleration events, thus ensuring power saving and flexibility.

Setting sleep to wake mode

It sets the sleep to wake mode of the accelerometer.

Example of use:

{
ACC.setSleepToWake();
}

Unsetting the sleep to wake mode

It unsets the sleep to wake mode of the accelerometer.

Example of use:

{
ACC.unSetSleepToWake();
}

Last updated