LIS302DL » Historie » Version 1
Maximilian Seesslen, 24.11.2026 11:57
| 1 | 1 | Maximilian Seesslen | h1. LIS302DL |
|---|---|---|---|
| 2 | |||
| 3 | LIS302DL |
||
| 4 | |||
| 5 | |LIS302DL | STM32F407 | |
||
| 6 | |SCK | PA5 | |
||
| 7 | |MISO | PA6 | |
||
| 8 | |MOSI | PA7 | |
||
| 9 | |CS | PE3 | |
||
| 10 | |INT1 | PE0 | |
||
| 11 | |INT2 | PE1 | |
||
| 12 | |||
| 13 | <pre><code class="c"> |
||
| 14 | |||
| 15 | Register 0xF=0x3B |
||
| 16 | // 100Hz, all axes active |
||
| 17 | lis_write(0x20, 0x47); |
||
| 18 | // High-pass-filter (Statische erdbeschleunigung entfernen) |
||
| 19 | lis_write(0x21, 0x09); |
||
| 20 | // +-2g |
||
| 21 | lis_write(0x23, 0x00); |
||
| 22 | // INT1 |
||
| 23 | lis_write(0x22, 0x04); |
||
| 24 | // Interrupt on all axes |
||
| 25 | lis_write(0x30, 0xEA); |
||
| 26 | // Interrupt Richtungsänderung |
||
| 27 | lis_write(0x30, 0xEA); |
||
| 28 | |||
| 29 | // Klopfen: |
||
| 30 | lis_write(0x20, 0x47); |
||
| 31 | lis_write(0x21, 0x09); |
||
| 32 | lis_write(0x22, 0x04); |
||
| 33 | lis_write(0x30, 0xFF); |
||
| 34 | lis_write(0x32, 0x08); |
||
| 35 | lis_write(0x33, 0x00); |
||
| 36 | |||
| 37 | // Clear interrupt |
||
| 38 | uint8_t src = lis_read(0x31); |
||
| 39 | |||
| 40 | int8_t x = (int8_t)lis_read(0x29); |
||
| 41 | int8_t y = (int8_t)lis_read(0x2B); |
||
| 42 | int8_t z = (int8_t)lis_read(0x2D); |
||
| 43 | |||
| 44 | uint8_t lis_read(uint8_t reg) |
||
| 45 | { |
||
| 46 | uint8_t tx[2]; |
||
| 47 | uint8_t rx[2]; |
||
| 48 | |||
| 49 | tx[0] = reg | 0x80; // Read-Bit setzen |
||
| 50 | tx[1] = 0; |
||
| 51 | |||
| 52 | CS_LOW(); |
||
| 53 | HAL_SPI_TransmitReceive(&hspi1, tx, rx, 2, 100); |
||
| 54 | CS_HIGH(); |
||
| 55 | |||
| 56 | return rx[1]; |
||
| 57 | } |
||
| 58 | |||
| 59 | |||
| 60 | </code></pre> |