Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Welcome to the code repository for PixArt's PAT9125EL sensor and evaluation board.
For general information about this product, please visit this product's components page here:
https://os.mbed.com/components/PAT9125EL-Evaluation-Board/
For guides and tips on how to setup and evaluate the PAT9125EL sensor with the Nordic nRF52-DK microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/9125_referenceCode/wiki/Guide-for-nRF52-DK-Platform
For guides and tips on how to setup and evaluate the PAT9125EL sensor with any microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/9125_referenceCode/wiki/Guide-for-Any-Platform
main.cpp@4:8f7d8ff001f8, 2018-07-23 (annotated)
- Committer:
- PixArtVY
- Date:
- Mon Jul 23 22:14:06 2018 +0000
- Revision:
- 4:8f7d8ff001f8
- Parent:
- 3:979019410df2
- Child:
- 5:577976dae20d
Fixed some SPI timing.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| PixArtVY | 0:e9cce1154246 | 1 | // PAT9125EL: Miniature Optical Navigation Chip reference code. |
| PixArtVY | 3:979019410df2 | 2 | // Version: 1.1 |
| PixArtVY | 3:979019410df2 | 3 | // Latest Revision Date: 18 July 2018 |
| PixArtVY | 0:e9cce1154246 | 4 | // By PixArt Imaging Inc. |
| PixArtVY | 0:e9cce1154246 | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
| PixArtVY | 0:e9cce1154246 | 6 | |
| PixArtVY | 3:979019410df2 | 7 | // Copyright [2018] [Vincent Yeh] |
| PixArtVY | 3:979019410df2 | 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: |
| PixArtVY | 3:979019410df2 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| PixArtVY | 3:979019410df2 | 10 | |
| PixArtVY | 3:979019410df2 | 11 | |
| PixArtVY | 0:e9cce1154246 | 12 | /* |
| PixArtVY | 0:e9cce1154246 | 13 | //======================= |
| PixArtVY | 0:e9cce1154246 | 14 | //Revision History |
| PixArtVY | 0:e9cce1154246 | 15 | //======================= |
| PixArtVY | 4:8f7d8ff001f8 | 16 | Version 1.2 -- 23 July 2018 |
| PixArtVY | 4:8f7d8ff001f8 | 17 | -Changed SPI frequency to 2MHz. |
| PixArtVY | 4:8f7d8ff001f8 | 18 | -Changed SPI timing for the readRegister function. |
| PixArtVY | 4:8f7d8ff001f8 | 19 | |
| PixArtVY | 3:979019410df2 | 20 | Version 1.1 -- 18 July 2018 |
| PixArtVY | 4:8f7d8ff001f8 | 21 | -Added apache license notice. |
| PixArtVY | 3:979019410df2 | 22 | |
| PixArtVY | 0:e9cce1154246 | 23 | Version 1.0 -- 16 Feb. 2018 |
| PixArtVY | 4:8f7d8ff001f8 | 24 | -First release. |
| PixArtVY | 0:e9cce1154246 | 25 | */ |
| PixArtVY | 0:e9cce1154246 | 26 | |
| PixArtVY | 0:e9cce1154246 | 27 | #include "mbed.h" |
| PixArtVY | 0:e9cce1154246 | 28 | #include "registerArrays.h" |
| PixArtVY | 3:979019410df2 | 29 | #include "SPIcommFunctions.h" |
| PixArtVY | 3:979019410df2 | 30 | //#include "I2CcommFunctions.h" |
| PixArtVY | 0:e9cce1154246 | 31 | //Make sure you only have SPIcommFunctions or I2CcommFunctions enabled. You cannot include both headers. |
| PixArtVY | 0:e9cce1154246 | 32 | |
| PixArtVY | 0:e9cce1154246 | 33 | int main() |
| PixArtVY | 0:e9cce1154246 | 34 | { |
| PixArtVY | 0:e9cce1154246 | 35 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
| PixArtVY | 0:e9cce1154246 | 36 | |
| PixArtVY | 0:e9cce1154246 | 37 | #ifdef SPImode |
| PixArtVY | 0:e9cce1154246 | 38 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
| PixArtVY | 4:8f7d8ff001f8 | 39 | spi.frequency(2000000); // Set frequency for SPI communication. |
| PixArtVY | 0:e9cce1154246 | 40 | cs = 1; // Initialize chip select as inactive. |
| PixArtVY | 0:e9cce1154246 | 41 | #endif |
| PixArtVY | 0:e9cce1154246 | 42 | |
| PixArtVY | 0:e9cce1154246 | 43 | #ifdef I2Cmode |
| PixArtVY | 0:e9cce1154246 | 44 | i2c.frequency(400000); // Set frequency for I2C communication. |
| PixArtVY | 0:e9cce1154246 | 45 | #endif |
| PixArtVY | 0:e9cce1154246 | 46 | |
| PixArtVY | 0:e9cce1154246 | 47 | pc.printf("Program START\n\r"); |
| PixArtVY | 0:e9cce1154246 | 48 | |
| PixArtVY | 0:e9cce1154246 | 49 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
| PixArtVY | 0:e9cce1154246 | 50 | if(readRegister(0x00) != 0x31) |
| PixArtVY | 0:e9cce1154246 | 51 | { |
| PixArtVY | 0:e9cce1154246 | 52 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
| PixArtVY | 0:e9cce1154246 | 53 | return 0; |
| PixArtVY | 0:e9cce1154246 | 54 | } |
| PixArtVY | 0:e9cce1154246 | 55 | |
| PixArtVY | 0:e9cce1154246 | 56 | writeRegister(0x06, 0x97); //Software reset (i.e. set bit7 to 1) |
| PixArtVY | 0:e9cce1154246 | 57 | wait_ms(1); //Delay 1 ms for chip reset timing. |
| PixArtVY | 0:e9cce1154246 | 58 | writeRegister(0x06, 0x17); //Ensure software reset is done and chip is no longer in that state. |
| PixArtVY | 0:e9cce1154246 | 59 | |
| PixArtVY | 0:e9cce1154246 | 60 | load(initialize, initialize_size); //Load register settings from the "initialize" array |
| PixArtVY | 0:e9cce1154246 | 61 | |
| PixArtVY | 0:e9cce1154246 | 62 | |
| PixArtVY | 0:e9cce1154246 | 63 | |
| PixArtVY | 0:e9cce1154246 | 64 | if(readRegister(0x5E) == 0x04) //These unlisted registers are used for internal recommended settings. |
| PixArtVY | 0:e9cce1154246 | 65 | { |
| PixArtVY | 0:e9cce1154246 | 66 | writeRegister(0x5E, 0x08); |
| PixArtVY | 0:e9cce1154246 | 67 | |
| PixArtVY | 0:e9cce1154246 | 68 | if(readRegister(0x5D) == 0x10) |
| PixArtVY | 0:e9cce1154246 | 69 | writeRegister(0x5D, 0x19); |
| PixArtVY | 0:e9cce1154246 | 70 | } |
| PixArtVY | 0:e9cce1154246 | 71 | |
| PixArtVY | 2:bebddee7347e | 72 | writeRegister(0x09, 0x00); // enable write protect. |
| PixArtVY | 0:e9cce1154246 | 73 | |
| PixArtVY | 0:e9cce1154246 | 74 | while(1) |
| PixArtVY | 0:e9cce1154246 | 75 | { |
| PixArtVY | 0:e9cce1154246 | 76 | //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. |
| PixArtVY | 0:e9cce1154246 | 77 | |
| PixArtVY | 0:e9cce1154246 | 78 | if(readRegister(0x02) & 0x80) |
| PixArtVY | 0:e9cce1154246 | 79 | { |
| PixArtVY | 0:e9cce1154246 | 80 | grabData(); |
| PixArtVY | 0:e9cce1154246 | 81 | printData(); |
| PixArtVY | 0:e9cce1154246 | 82 | } |
| PixArtVY | 0:e9cce1154246 | 83 | } |
| PixArtVY | 0:e9cce1154246 | 84 | } |
PAT9125EL | Versatile Low-Energy Surface Tracking Sensor