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:
Fri Feb 23 23:32:40 2018 +0000
Revision:
0:e9cce1154246
Child:
2:bebddee7347e
First release of 9125 firmware.

Who changed what in which revision?

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