Martin Smith
/
AS5045_Encoder_SPI
Interfacing the AS5045 using SPI
Revision 0:ce4a539ca1d4, committed 2010-10-22
- Comitter:
- ms523
- Date:
- Fri Oct 22 17:36:47 2010 +0000
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r ce4a539ca1d4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 22 17:36:47 2010 +0000 @@ -0,0 +1,40 @@ +/* This program is designed to interface with the AS5045 IC encoder + It calls a function to read the encoder value every second + The program then prints the vaule to a PC screen via hyperterminal*/ + +#include "mbed.h" + +Serial pc(USBTX, USBRX); +SPI spi(p5, p6, p7); // mosi, miso, sclk +DigitalOut cs(p25); + +long EncoderValue; +int Encoder; + +Ticker ReadEncoder; + +void Read(){ + + spi.format(9,2); // Setup the spi for 9 bit data, high steady state clock, + spi.frequency(500000); + cs = 0; // Select the device by seting chip select low + +// Send a dummy byte to receive the contents encoder + int upper = spi.write(0x00); + int lower = spi.write(0x00); + lower = lower >> 6; + upper = (upper << 6)+lower; + cs = 1; + + pc.printf("%d \r", upper); +} + + +int main() { + pc.printf("Hello World!\n"); + ReadEncoder.attach_us(&Read, 100000); // call flip every 100 milli-seconds + + while(1) { + } +} +
diff -r 000000000000 -r ce4a539ca1d4 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Oct 22 17:36:47 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0