# MC3630 - Accel sensor

Accelerometer using SPI bus.

{% hint style="warning" %}
Available only when board BEHAVIOR `<PAL_MOT>` `<PAL_NOTICE>` is loaded. Procedures of common methods except `begin(), available()` are executed in board BEHAVIOR.
{% endhint %}

## Operation flow

1.`.begin()`: Sensor operation starts 2. 2.`PIN_SNS_INT` interrupt or `available()`: FIFO queue reaches the specified number 3. 3.`.get_que()`: Get data from the FIFO queue

## Procedures required for operation

### SPI bus

None in particular.

### Sleep procedure

To wake up by PIN\_SNS\_INT interrupt, the following settings must be made before sleep.

```cpp
pinMode(PAL_MOT::PIN_SNS_INT, WAKE_FALLING);
```

### Procedures for waking up from sleep

A call to the `.wakeup()` method is required. This process is executed in the `<PAL_MOT>` board BEHAVIOR.

{% hint style="warning" %}
If the semiconductor's internal FIFO queue is full and no read is performed, the data acquisition is terminated and no new values are stored.
{% endhint %}

## Data Structure

Each sample is stored in a queue [`smplque`](https://mwx.twelite.info/latest_en/api-reference/classes/smplque) whose elements are [`axis_xyzt`](https://mwx.twelite.info/latest_en/api-reference/classes/axis_xyzt) structures. The members x,y,z correspond to the X, Y, and Z axes, respectively.

```cpp
struct axis_xyzt {
  int16_t x;
  int16_t y;
  int16_t z;
  uint16_t t;
};
```

The value of each axis is stored as a value where 1G is 1000. The `t` is the sample number, which is assigned to each sample in order from `0`.

## Methods

### read()

```cpp
uint8_t read()
```

Reads data from a semiconductor FIFO queue. The number of bytes read is returned, but be sure to read the number of data stored in the size of the queue referenced by `.get_que()`.

{% hint style="warning" %}
After returning from sleep, `<PAL_MOT>` will do `read()`.
{% endhint %}

### get\_que()

```cpp
smplque<axis_xyzt>& get_que()
```

Get a sample of the acceleration. The queue is [`smplque`](https://mwx.twelite.info/latest_en/api-reference/classes/smplque) with [`axis_xyzt`](https://mwx.twelite.info/latest_en/api-reference/classes/axis_xyzt) as an element; the queue should be emptied as soon as it is available.

## Common methods

### setup()

```cpp
void setup() 
```

This sensor does not use `setup()`.

### begin(), end()

```cpp
void begin(uint32_t conf)
void end()
```

Initialize with the settings specified in `conf`.

`conf[0:15]` (bit0-15): sampling mode, `conf[16:23]` (bit16-23): range of acceleration, `conf[24:31]` (bit24-31): number of samples until interrupt occurs.

| conf\[0:15] sample mode  | contents                           |
| ------------------------ | ---------------------------------- |
| `MODE_LP_1HZ_UNOFFICIAL` | 1Hz Low Power (unofficial setting) |
| `MODE_LP_2HZ_UNOFFICIAL` | 2Hz Low Power (unofficial setting) |
| `MODE_LP_7HZ_UNOFFICIAL` | 7Hz Low Power (unofficial setting) |
| `MODE_LP_14HZ`           | 14Hz Low Power (default)           |
| `MODE_LP_28HZ`           | 28Hz Low Power                     |
| `MODE_LP_54HZ`           | 54Hz Low Power                     |
| `MODE_LP_105HZ`          | 105Hz Low Power                    |
| `MODE_LP_210HZ`          | 210Hz Low Power                    |
| `MODE_LP_400HZ`          | 400Hz Low Power                    |
| `MODE_ULP_25HZ`          | 25Hz Ultra Low Power               |
| `MODE_ULP_50HZ`          | 50Hz Ultra Low Power               |
| `MODE_ULP_100HZ`         | 100Hz Ultra Low Power              |
| `MODE_ULP_190HZ`         | 190Hz Ultra Low Power              |
| `MODE_ULP_380HZ`         | 380Hz Ultra Low Power              |

{% hint style="warning" %}
**Unofficial settings** are not described in the MC3630 datasheet and their behavior is **undefined**. Please check the behavior of the settings before using them. We are not able to answer any questions or problems related to the unofficial settings.
{% endhint %}

| conf\[16:23] Acceleration range | Contents      |
| ------------------------------- | ------------- |
| `RANGE_PLUS_MINUS_8G`           | ±8G (default) |
| `RANGE_PLUS_MINUS_4G`           | ±4G           |
| `RANGE_PLUS_MINUS_2G`           | ±2G           |
| `RANGE_PLUS_MINUS_1G`           | ±1G           |

### process\_ev()

```cpp
void process_ev(uint32_t arg1, uint32_t arg2 = 0)
```

This sensor does not use `process_ev()`.

### available()

```cpp
bool available()
```

Returns `true` if data is read out to the sensor and stored in the internal queue.

### probe()

```cpp
bool probe()
```

You cannot use `probe()` with this sensor.

### wakeup()

```cpp
void wakeup()
```

Reinitializes the SPI bus after sleep recovery and reads acceleration data.
