Reference firmware for PixArt's PAT9125EL sensor and evaluation board. "Hello World" and "Library" contain the exact same files. Please import just one of the two into your mBed compiler as a new program and not as a library.

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

Committer:
PixArtVY
Date:
Wed Jul 18 18:33:38 2018 +0000
Revision:
3:979019410df2
Parent:
2:bebddee7347e
Child:
4:8f7d8ff001f8
Added Apache License notice.

Who changed what in which revision?

UserRevisionLine numberNew 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 3:979019410df2 16 Version 1.1 -- 18 July 2018
PixArtVY 3:979019410df2 17 Added apache license notice.
PixArtVY 3:979019410df2 18
PixArtVY 0:e9cce1154246 19 Version 1.0 -- 16 Feb. 2018
PixArtVY 0:e9cce1154246 20 First release.
PixArtVY 0:e9cce1154246 21 */
PixArtVY 0:e9cce1154246 22
PixArtVY 0:e9cce1154246 23 #include "mbed.h"
PixArtVY 0:e9cce1154246 24 #include "registerArrays.h"
PixArtVY 3:979019410df2 25 #include "SPIcommFunctions.h"
PixArtVY 3:979019410df2 26 //#include "I2CcommFunctions.h"
PixArtVY 0:e9cce1154246 27 //Make sure you only have SPIcommFunctions or I2CcommFunctions enabled. You cannot include both headers.
PixArtVY 0:e9cce1154246 28
PixArtVY 0:e9cce1154246 29 int main()
PixArtVY 0:e9cce1154246 30 {
PixArtVY 0:e9cce1154246 31 pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value.
PixArtVY 0:e9cce1154246 32
PixArtVY 0:e9cce1154246 33 #ifdef SPImode
PixArtVY 0:e9cce1154246 34 spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge.
PixArtVY 0:e9cce1154246 35 spi.frequency(1000000); // Set frequency for SPI communication.
PixArtVY 0:e9cce1154246 36 cs = 1; // Initialize chip select as inactive.
PixArtVY 0:e9cce1154246 37 #endif
PixArtVY 0:e9cce1154246 38
PixArtVY 0:e9cce1154246 39 #ifdef I2Cmode
PixArtVY 0:e9cce1154246 40 i2c.frequency(400000); // Set frequency for I2C communication.
PixArtVY 0:e9cce1154246 41 #endif
PixArtVY 0:e9cce1154246 42
PixArtVY 0:e9cce1154246 43 pc.printf("Program START\n\r");
PixArtVY 0:e9cce1154246 44
PixArtVY 0:e9cce1154246 45 pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly.
PixArtVY 0:e9cce1154246 46 if(readRegister(0x00) != 0x31)
PixArtVY 0:e9cce1154246 47 {
PixArtVY 0:e9cce1154246 48 pc.printf("Communication protocol error! Terminating program.\n\r");
PixArtVY 0:e9cce1154246 49 return 0;
PixArtVY 0:e9cce1154246 50 }
PixArtVY 0:e9cce1154246 51
PixArtVY 0:e9cce1154246 52 writeRegister(0x06, 0x97); //Software reset (i.e. set bit7 to 1)
PixArtVY 0:e9cce1154246 53 wait_ms(1); //Delay 1 ms for chip reset timing.
PixArtVY 0:e9cce1154246 54 writeRegister(0x06, 0x17); //Ensure software reset is done and chip is no longer in that state.
PixArtVY 0:e9cce1154246 55
PixArtVY 0:e9cce1154246 56 load(initialize, initialize_size); //Load register settings from the "initialize" array
PixArtVY 0:e9cce1154246 57
PixArtVY 0:e9cce1154246 58
PixArtVY 0:e9cce1154246 59
PixArtVY 0:e9cce1154246 60 if(readRegister(0x5E) == 0x04) //These unlisted registers are used for internal recommended settings.
PixArtVY 0:e9cce1154246 61 {
PixArtVY 0:e9cce1154246 62 writeRegister(0x5E, 0x08);
PixArtVY 0:e9cce1154246 63
PixArtVY 0:e9cce1154246 64 if(readRegister(0x5D) == 0x10)
PixArtVY 0:e9cce1154246 65 writeRegister(0x5D, 0x19);
PixArtVY 0:e9cce1154246 66 }
PixArtVY 0:e9cce1154246 67
PixArtVY 2:bebddee7347e 68 writeRegister(0x09, 0x00); // enable write protect.
PixArtVY 0:e9cce1154246 69
PixArtVY 0:e9cce1154246 70 while(1)
PixArtVY 0:e9cce1154246 71 {
PixArtVY 0:e9cce1154246 72 //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 73
PixArtVY 0:e9cce1154246 74 if(readRegister(0x02) & 0x80)
PixArtVY 0:e9cce1154246 75 {
PixArtVY 0:e9cce1154246 76 grabData();
PixArtVY 0:e9cce1154246 77 printData();
PixArtVY 0:e9cce1154246 78 }
PixArtVY 0:e9cce1154246 79 }
PixArtVY 0:e9cce1154246 80 }