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@0:c8a2256e02c2, 2018-04-03 (annotated)
- Committer:
- PixArtVY
- Date:
- Tue Apr 03 20:04:39 2018 +0000
- Revision:
- 0:c8a2256e02c2
- Child:
- 1:782127a132a3
First revision.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| PixArtVY | 0:c8a2256e02c2 | 1 | // PAA5100JE-Q: Optical Tracking Chip reference code. |
| PixArtVY | 0:c8a2256e02c2 | 2 | // Version: 1.0 |
| PixArtVY | 0:c8a2256e02c2 | 3 | // Latest Revision Date: 4 Apr. 2018 |
| PixArtVY | 0:c8a2256e02c2 | 4 | // By PixArt Imaging Inc. |
| PixArtVY | 0:c8a2256e02c2 | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
| PixArtVY | 0:c8a2256e02c2 | 6 | |
| PixArtVY | 0:c8a2256e02c2 | 7 | /* |
| PixArtVY | 0:c8a2256e02c2 | 8 | //======================= |
| PixArtVY | 0:c8a2256e02c2 | 9 | //Revision History |
| PixArtVY | 0:c8a2256e02c2 | 10 | //======================= |
| PixArtVY | 0:c8a2256e02c2 | 11 | Version 1.0 -- 4 Apr. 2018 |
| PixArtVY | 0:c8a2256e02c2 | 12 | First release. |
| PixArtVY | 0:c8a2256e02c2 | 13 | */ |
| PixArtVY | 0:c8a2256e02c2 | 14 | |
| PixArtVY | 0:c8a2256e02c2 | 15 | #include "mbed.h" |
| PixArtVY | 0:c8a2256e02c2 | 16 | #include "SPIcommFunctions.h" |
| PixArtVY | 0:c8a2256e02c2 | 17 | |
| PixArtVY | 0:c8a2256e02c2 | 18 | int main() |
| PixArtVY | 0:c8a2256e02c2 | 19 | { |
| PixArtVY | 0:c8a2256e02c2 | 20 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
| PixArtVY | 0:c8a2256e02c2 | 21 | |
| PixArtVY | 0:c8a2256e02c2 | 22 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
| PixArtVY | 0:c8a2256e02c2 | 23 | spi.frequency(1000000); // Set frequency for SPI communication. |
| PixArtVY | 0:c8a2256e02c2 | 24 | cs = 1; // Initialize chip select as inactive. |
| PixArtVY | 0:c8a2256e02c2 | 25 | |
| PixArtVY | 0:c8a2256e02c2 | 26 | pc.printf("Program START\n\r"); |
| PixArtVY | 0:c8a2256e02c2 | 27 | |
| PixArtVY | 0:c8a2256e02c2 | 28 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
| PixArtVY | 0:c8a2256e02c2 | 29 | if(readRegister(0x00) != 0x49) |
| PixArtVY | 0:c8a2256e02c2 | 30 | { |
| PixArtVY | 0:c8a2256e02c2 | 31 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
| PixArtVY | 0:c8a2256e02c2 | 32 | return 0; |
| PixArtVY | 0:c8a2256e02c2 | 33 | } |
| PixArtVY | 0:c8a2256e02c2 | 34 | |
| PixArtVY | 0:c8a2256e02c2 | 35 | |
| PixArtVY | 0:c8a2256e02c2 | 36 | startupCheck(); |
| PixArtVY | 0:c8a2256e02c2 | 37 | if(startupFail == 3) |
| PixArtVY | 0:c8a2256e02c2 | 38 | { |
| PixArtVY | 0:c8a2256e02c2 | 39 | pc.printf("Start-up failed! Power cycle the chip and try again.\n\r"); |
| PixArtVY | 0:c8a2256e02c2 | 40 | return 0; |
| PixArtVY | 0:c8a2256e02c2 | 41 | } |
| PixArtVY | 0:c8a2256e02c2 | 42 | |
| PixArtVY | 0:c8a2256e02c2 | 43 | initializeSensor(); |
| PixArtVY | 0:c8a2256e02c2 | 44 | |
| PixArtVY | 0:c8a2256e02c2 | 45 | while(1) |
| PixArtVY | 0:c8a2256e02c2 | 46 | { |
| PixArtVY | 0:c8a2256e02c2 | 47 | //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:c8a2256e02c2 | 48 | |
| PixArtVY | 0:c8a2256e02c2 | 49 | if(readRegister(0x02) & 0x80) |
| PixArtVY | 0:c8a2256e02c2 | 50 | { |
| PixArtVY | 0:c8a2256e02c2 | 51 | grabData(); |
| PixArtVY | 0:c8a2256e02c2 | 52 | printData(); |
| PixArtVY | 0:c8a2256e02c2 | 53 | } |
| PixArtVY | 0:c8a2256e02c2 | 54 | } |
| PixArtVY | 0:c8a2256e02c2 | 55 | } |
PAA5100 | Robotics Sensor With Cliff And Soft/Hard Surface Detection