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.
main.cpp
00001 // PAT9125EL: Miniature Optical Navigation Chip reference code. 00002 // Version: 1.2 00003 // Latest Revision Date: 23 July 2018 00004 // By PixArt Imaging Inc. 00005 // Primary Engineer: Vincent Yeh (PixArt USA) 00006 00007 // Copyright [2018] [Vincent Yeh] 00008 // 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: 00009 // http://www.apache.org/licenses/LICENSE-2.0 00010 00011 00012 /* 00013 //======================= 00014 //Revision History 00015 //======================= 00016 Version 1.2 -- 23 July 2018 00017 -Changed SPI frequency to 2MHz. 00018 -Changed SPI timing for the readRegister function. 00019 00020 Version 1.1 -- 18 July 2018 00021 -Added apache license notice. 00022 00023 Version 1.0 -- 16 Feb. 2018 00024 -First release. 00025 */ 00026 00027 #include "mbed.h" 00028 #include "registerArrays.h" 00029 #include "SPIcommFunctions.h" 00030 //#include "I2CcommFunctions.h" 00031 //Make sure you only have SPIcommFunctions or I2CcommFunctions enabled. You cannot include both headers. 00032 00033 int main() 00034 { 00035 pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. 00036 00037 #ifdef SPImode 00038 spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. 00039 spi.frequency(2000000); // Set frequency for SPI communication. 00040 cs = 1; // Initialize chip select as inactive. 00041 #endif 00042 00043 #ifdef I2Cmode 00044 i2c.frequency(400000); // Set frequency for I2C communication. 00045 #endif 00046 00047 pc.printf("Program START\n\r"); 00048 00049 pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. 00050 if(readRegister(0x00) != 0x31) 00051 { 00052 pc.printf("Communication protocol error! Terminating program.\n\r"); 00053 return 0; 00054 } 00055 00056 writeRegister(0x06, 0x97); //Software reset (i.e. set bit7 to 1) 00057 wait_ms(1); //Delay 1 ms for chip reset timing. 00058 writeRegister(0x06, 0x17); //Ensure software reset is done and chip is no longer in that state. 00059 00060 load(initialize, initialize_size); //Load register settings from the "initialize" array 00061 00062 00063 00064 if(readRegister(0x5E) == 0x04) //These unlisted registers are used for internal recommended settings. 00065 { 00066 writeRegister(0x5E, 0x08); 00067 00068 if(readRegister(0x5D) == 0x10) 00069 writeRegister(0x5D, 0x19); 00070 } 00071 00072 writeRegister(0x09, 0x00); // enable write protect. 00073 00074 while(1) 00075 { 00076 //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. 00077 00078 if(readRegister(0x02) & 0x80) 00079 { 00080 grabData(); 00081 printData(); 00082 } 00083 } 00084 }
Generated on Thu Jul 14 2022 06:25:47 by
1.7.2
PAT9125EL | Versatile Low-Energy Surface Tracking Sensor