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.
Revision 0:ed3c161e6715, committed 2015-02-04
- Comitter:
- ms523
- Date:
- Wed Feb 04 14:19:14 2015 +0000
- Child:
- 1:ae562ccce5bd
- Commit message:
- working
Changed in this revision
| iC_MU.cpp | Show annotated file Show diff for this revision Revisions of this file |
| iC_MU.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/iC_MU.cpp Wed Feb 04 14:19:14 2015 +0000
@@ -0,0 +1,84 @@
+#include "mbed.h"
+#include "iC_MU.h"
+
+iC_MU::iC_MU(PinName MOSI, PinName MISO, PinName CLK, PinName nCS) : _spi(MOSI, MISO, CLK), _ncs(nCS) {
+
+ // Set up the SPI port...
+ _spi.frequency(10000000); // 10MHz is the fastest mbed frequency supported by the iC_MU
+ _spi.format(16,3); // Set for mode 3 16_bits
+
+ // To start with I need the chip select high and wait 1ms after powering up
+ _ncs = 1;
+ wait(0.001);
+}
+
+int iC_MU::RequestSTATUS()
+{
+ int reply = 0;
+
+ _spi.format(8,3); // Set to 8_bit mode 3
+ _ncs = 0; // Bring nCS low to start write
+ reply = _spi.write(0xAD); // Write REGISTER status/data cmd
+ reply = reply << 8; // bit shift reply
+ reply += _spi.write(0x00); // Send dummy byte
+ reply = reply << 8; // bit shift reply
+ reply += _spi.write(0x00); // Send dummy byte
+ _ncs = 1; // Set nCS high to send write
+ _spi.format(16,3); // Set back to 16_bit mode 3
+ return(reply);
+}
+
+int iC_MU::ReadREGISTER(char reg)
+{
+ int reply = 0;
+ int msg = 0x9700 + reg;
+
+ _ncs = 0; // Bring nCS low to start write
+ reply = _spi.write(msg); // Write ACTIVATE cmd
+ _ncs = 1; // Set nCS high to send write
+ return(reply);
+}
+
+int iC_MU::WriteREGISTER(char reg, char data)
+{
+ int reply = 0;
+
+ _spi.format(8,3); // Set to 8_bit mode 3
+ _ncs = 0; // Bring nCS low to start write
+ reply = _spi.write(0xD2); // Write REGISTER status/data cmd
+ reply = reply << 8; // bit shift reply
+ reply += _spi.write(reg); // Send the register addres to be written to
+ reply = reply << 8; // bit shift reply
+ reply += _spi.write(data); // Send the data to be written
+ _ncs = 1; // Set nCS high to send write
+ _spi.format(16,3); // Set back to 16_bit mode 3
+ return(reply);
+}
+
+int iC_MU::ACTIVATE(char reg)
+{
+ int reply = 0;
+ int msg = 0xB000 + reg;
+
+ _ncs = 0; // Bring nCS low to start write
+ reply = _spi.write(msg); // Write ACTIVATE cmd
+ _ncs = 1; // Set nCS high to send write
+ return(reply);
+}
+
+int iC_MU::ReadPOSITION()
+{
+ int reply = 0;
+
+ _ncs = 0; // Bring nCS low to start write
+ reply = _spi.write(0xA600); // Write REGISTER status/data cmd
+ reply = reply << 16; // bit shift reply
+ reply += _spi.write(0x0000); // Send dummy byte
+ _ncs = 1; // Set nCS high to send write
+
+ // Shift around data
+ reply = (reply & 0x00FFFFFF); // Mask out top byte
+ reply = reply >> 5; // Cut off last nibble
+
+ return(reply);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/iC_MU.h Wed Feb 04 14:19:14 2015 +0000
@@ -0,0 +1,61 @@
+#ifndef MBED_IC_MU_H
+#define MBED_IC_MU_H
+
+#include "mbed.h"
+
+class iC_MU {
+public:
+ /**
+ * Constructor.
+ */
+ iC_MU(PinName mosi, PinName miso, PinName sclk, PinName cs);
+
+ /**
+ * Request the device status
+ *
+ * returns the current status
+ */
+ int RequestSTATUS();
+
+ /**
+ * Reads the specified reg
+ *
+ * @returns the reg contents
+ */
+ int ReadREGISTER(char reg);
+
+ /**
+ * Writes to the specified reg.
+ *
+ * @returns the device reply
+ */
+ int WriteREGISTER(char reg, char data);
+
+ /**
+ * Send the activate cmd
+ *
+ * @returns the device reply
+ */
+ int ACTIVATE(char reg);
+
+ /**
+ * Read the current position
+ *
+ * @returns the position as an int
+ */
+ int ReadPOSITION();
+
+ /**
+ * Sets the iC_MU up as the eval board was sniffed.
+ * Not sure we need to do this???
+ *
+ * @returns 1
+ */
+ int initalise();
+
+private:
+ SPI _spi;
+ DigitalOut _ncs;
+};
+
+#endif
\ No newline at end of file