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.
main.cpp@0:5a34a4387fb0, 2018-04-20 (annotated)
- Committer:
- PixArtVY
- Date:
- Fri Apr 20 22:33:08 2018 +0000
- Revision:
- 0:5a34a4387fb0
- Child:
- 1:efa5e5a1e308
First revision.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PixArtVY | 0:5a34a4387fb0 | 1 | // PAT9130EW: Optical Tracking Miniature Chip reference code. |
PixArtVY | 0:5a34a4387fb0 | 2 | // Version: 1.0 |
PixArtVY | 0:5a34a4387fb0 | 3 | // Latest Revision Date: 16 Apr. 2018 |
PixArtVY | 0:5a34a4387fb0 | 4 | // By PixArt Imaging Inc. |
PixArtVY | 0:5a34a4387fb0 | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
PixArtVY | 0:5a34a4387fb0 | 6 | |
PixArtVY | 0:5a34a4387fb0 | 7 | /* |
PixArtVY | 0:5a34a4387fb0 | 8 | //======================= |
PixArtVY | 0:5a34a4387fb0 | 9 | //Revision History |
PixArtVY | 0:5a34a4387fb0 | 10 | //======================= |
PixArtVY | 0:5a34a4387fb0 | 11 | Version 1.0 -- 16 Apr. 2018 |
PixArtVY | 0:5a34a4387fb0 | 12 | First release. |
PixArtVY | 0:5a34a4387fb0 | 13 | */ |
PixArtVY | 0:5a34a4387fb0 | 14 | |
PixArtVY | 0:5a34a4387fb0 | 15 | #include "mbed.h" |
PixArtVY | 0:5a34a4387fb0 | 16 | #include "registerArrays.h" |
PixArtVY | 0:5a34a4387fb0 | 17 | #include "SPIcommFunctions.h" |
PixArtVY | 0:5a34a4387fb0 | 18 | |
PixArtVY | 0:5a34a4387fb0 | 19 | int main() |
PixArtVY | 0:5a34a4387fb0 | 20 | { |
PixArtVY | 0:5a34a4387fb0 | 21 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
PixArtVY | 0:5a34a4387fb0 | 22 | |
PixArtVY | 0:5a34a4387fb0 | 23 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
PixArtVY | 0:5a34a4387fb0 | 24 | spi.frequency(1000000); // Set frequency for SPI communication. |
PixArtVY | 0:5a34a4387fb0 | 25 | cs = 1; // Initialize chip select as inactive. |
PixArtVY | 0:5a34a4387fb0 | 26 | |
PixArtVY | 0:5a34a4387fb0 | 27 | pc.printf("Program START\n\r"); |
PixArtVY | 0:5a34a4387fb0 | 28 | |
PixArtVY | 0:5a34a4387fb0 | 29 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
PixArtVY | 0:5a34a4387fb0 | 30 | if(readRegister(0x00) != 0x31) |
PixArtVY | 0:5a34a4387fb0 | 31 | { |
PixArtVY | 0:5a34a4387fb0 | 32 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:5a34a4387fb0 | 33 | return 0; |
PixArtVY | 0:5a34a4387fb0 | 34 | } |
PixArtVY | 0:5a34a4387fb0 | 35 | |
PixArtVY | 0:5a34a4387fb0 | 36 | writeRegister(0x06, 0x80); //Software reset (i.e. set bit7 to 1) |
PixArtVY | 0:5a34a4387fb0 | 37 | wait_ms(1); //Delay 1 ms for chip reset timing. |
PixArtVY | 0:5a34a4387fb0 | 38 | |
PixArtVY | 0:5a34a4387fb0 | 39 | pc.printf("ID Check #2: %2X\n\r", readRegister(0x00)); //Checks product ID after resetting to make sure communication protocol is working properly. |
PixArtVY | 0:5a34a4387fb0 | 40 | if(readRegister(0x00) != 0x31) |
PixArtVY | 0:5a34a4387fb0 | 41 | { |
PixArtVY | 0:5a34a4387fb0 | 42 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:5a34a4387fb0 | 43 | return 0; |
PixArtVY | 0:5a34a4387fb0 | 44 | } |
PixArtVY | 0:5a34a4387fb0 | 45 | |
PixArtVY | 0:5a34a4387fb0 | 46 | load(initialize, initialize_size); //Load register settings from the "initialize" array (see registerArrays.h) |
PixArtVY | 0:5a34a4387fb0 | 47 | |
PixArtVY | 0:5a34a4387fb0 | 48 | while(1) |
PixArtVY | 0:5a34a4387fb0 | 49 | { |
PixArtVY | 0:5a34a4387fb0 | 50 | //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:5a34a4387fb0 | 51 | |
PixArtVY | 0:5a34a4387fb0 | 52 | if(readRegister(0x02) & 0x80) |
PixArtVY | 0:5a34a4387fb0 | 53 | { |
PixArtVY | 0:5a34a4387fb0 | 54 | grabData(); |
PixArtVY | 0:5a34a4387fb0 | 55 | printData(); |
PixArtVY | 0:5a34a4387fb0 | 56 | } |
PixArtVY | 0:5a34a4387fb0 | 57 | } |
PixArtVY | 0:5a34a4387fb0 | 58 | } |