Reference firmware for PixArt's PAT9130EW 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.
Diff: main.cpp
- Revision:
- 0:5a34a4387fb0
- Child:
- 1:efa5e5a1e308
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 20 22:33:08 2018 +0000 @@ -0,0 +1,58 @@ +// PAT9130EW: Optical Tracking Miniature Chip reference code. +// Version: 1.0 +// Latest Revision Date: 16 Apr. 2018 +// By PixArt Imaging Inc. +// Primary Engineer: Vincent Yeh (PixArt USA) + +/* +//======================= +//Revision History +//======================= +Version 1.0 -- 16 Apr. 2018 +First release. +*/ + +#include "mbed.h" +#include "registerArrays.h" +#include "SPIcommFunctions.h" + +int main() +{ + pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. + + spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. + spi.frequency(1000000); // Set frequency for SPI communication. + cs = 1; // Initialize chip select as inactive. + + pc.printf("Program START\n\r"); + + pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. + if(readRegister(0x00) != 0x31) + { + pc.printf("Communication protocol error! Terminating program.\n\r"); + return 0; + } + + writeRegister(0x06, 0x80); //Software reset (i.e. set bit7 to 1) + wait_ms(1); //Delay 1 ms for chip reset timing. + + pc.printf("ID Check #2: %2X\n\r", readRegister(0x00)); //Checks product ID after resetting to make sure communication protocol is working properly. + if(readRegister(0x00) != 0x31) + { + pc.printf("Communication protocol error! Terminating program.\n\r"); + return 0; + } + + load(initialize, initialize_size); //Load register settings from the "initialize" array (see registerArrays.h) + + while(1) + { + //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. + + if(readRegister(0x02) & 0x80) + { + grabData(); + printData(); + } + } +}