Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
R66Y
Date:
Sat May 20 15:23:58 2017 +0000
Revision:
3:1bb26049bdd1
Parent:
1:f3f702086a30
Programme de contr?le des AX12 avec rajout de l'MX12;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ClementBreteau 1:f3f702086a30 1 /* mbed Microcontroller Library - SPISlave
ClementBreteau 1:f3f702086a30 2 * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
ClementBreteau 1:f3f702086a30 3 */
ClementBreteau 1:f3f702086a30 4
ClementBreteau 1:f3f702086a30 5 #ifndef MBED_SPISLAVE_H
ClementBreteau 1:f3f702086a30 6 #define MBED_SPISLAVE_H
ClementBreteau 1:f3f702086a30 7
ClementBreteau 1:f3f702086a30 8 #include "device.h"
ClementBreteau 1:f3f702086a30 9
ClementBreteau 1:f3f702086a30 10 #if DEVICE_SPISLAVE
ClementBreteau 1:f3f702086a30 11
ClementBreteau 1:f3f702086a30 12 #include "platform.h"
ClementBreteau 1:f3f702086a30 13 #include "PinNames.h"
ClementBreteau 1:f3f702086a30 14 #include "PeripheralNames.h"
ClementBreteau 1:f3f702086a30 15 #include "Base.h"
ClementBreteau 1:f3f702086a30 16
ClementBreteau 1:f3f702086a30 17 namespace mbed {
ClementBreteau 1:f3f702086a30 18
ClementBreteau 1:f3f702086a30 19 /* Class: SPISlave
ClementBreteau 1:f3f702086a30 20 * A SPI slave, used for communicating with a SPI Master device
ClementBreteau 1:f3f702086a30 21 *
ClementBreteau 1:f3f702086a30 22 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
ClementBreteau 1:f3f702086a30 23 *
ClementBreteau 1:f3f702086a30 24 * Example:
ClementBreteau 1:f3f702086a30 25 * > // Reply to a SPI master as slave
ClementBreteau 1:f3f702086a30 26 * >
ClementBreteau 1:f3f702086a30 27 * > #include "mbed.h"
ClementBreteau 1:f3f702086a30 28 * >
ClementBreteau 1:f3f702086a30 29 * > SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
ClementBreteau 1:f3f702086a30 30 * >
ClementBreteau 1:f3f702086a30 31 * > int main() {
ClementBreteau 1:f3f702086a30 32 * > device.reply(0x00); // Prime SPI with first reply
ClementBreteau 1:f3f702086a30 33 * > while(1) {
ClementBreteau 1:f3f702086a30 34 * > if(device.receive()) {
ClementBreteau 1:f3f702086a30 35 * > int v = device.read(); // Read byte from master
ClementBreteau 1:f3f702086a30 36 * > v = (v + 1) % 0x100; // Add one to it, modulo 256
ClementBreteau 1:f3f702086a30 37 * > device.reply(v); // Make this the next reply
ClementBreteau 1:f3f702086a30 38 * > }
ClementBreteau 1:f3f702086a30 39 * > }
ClementBreteau 1:f3f702086a30 40 * > }
ClementBreteau 1:f3f702086a30 41 */
ClementBreteau 1:f3f702086a30 42 class SPISlave : public Base {
ClementBreteau 1:f3f702086a30 43
ClementBreteau 1:f3f702086a30 44 public:
ClementBreteau 1:f3f702086a30 45
ClementBreteau 1:f3f702086a30 46 /* Constructor: SPI
ClementBreteau 1:f3f702086a30 47 * Create a SPI slave connected to the specified pins
ClementBreteau 1:f3f702086a30 48 *
ClementBreteau 1:f3f702086a30 49 * Variables:
ClementBreteau 1:f3f702086a30 50 * mosi - SPI Master Out, Slave In pin
ClementBreteau 1:f3f702086a30 51 * miso - SPI Master In, Slave Out pin
ClementBreteau 1:f3f702086a30 52 * sclk - SPI Clock pin
ClementBreteau 1:f3f702086a30 53 * ssel - SPI chip select pin
ClementBreteau 1:f3f702086a30 54 * name - (optional) A string to identify the object
ClementBreteau 1:f3f702086a30 55 *
ClementBreteau 1:f3f702086a30 56 * Pin Options:
ClementBreteau 1:f3f702086a30 57 * (5, 6, 7i, 8) or (11, 12, 13, 14)
ClementBreteau 1:f3f702086a30 58 *
ClementBreteau 1:f3f702086a30 59 * mosi or miso can be specfied as NC if not used
ClementBreteau 1:f3f702086a30 60 */
ClementBreteau 1:f3f702086a30 61 SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel,
ClementBreteau 1:f3f702086a30 62 const char *name = NULL);
ClementBreteau 1:f3f702086a30 63
ClementBreteau 1:f3f702086a30 64 /* Function: format
ClementBreteau 1:f3f702086a30 65 * Configure the data transmission format
ClementBreteau 1:f3f702086a30 66 *
ClementBreteau 1:f3f702086a30 67 * Variables:
ClementBreteau 1:f3f702086a30 68 * bits - Number of bits per SPI frame (4 - 16)
ClementBreteau 1:f3f702086a30 69 * mode - Clock polarity and phase mode (0 - 3)
ClementBreteau 1:f3f702086a30 70 *
ClementBreteau 1:f3f702086a30 71 * > mode | POL PHA
ClementBreteau 1:f3f702086a30 72 * > -----+--------
ClementBreteau 1:f3f702086a30 73 * > 0 | 0 0
ClementBreteau 1:f3f702086a30 74 * > 1 | 0 1
ClementBreteau 1:f3f702086a30 75 * > 2 | 1 0
ClementBreteau 1:f3f702086a30 76 * > 3 | 1 1
ClementBreteau 1:f3f702086a30 77 */
ClementBreteau 1:f3f702086a30 78 void format(int bits, int mode = 0);
ClementBreteau 1:f3f702086a30 79
ClementBreteau 1:f3f702086a30 80 /* Function: frequency
ClementBreteau 1:f3f702086a30 81 * Set the spi bus clock frequency
ClementBreteau 1:f3f702086a30 82 *
ClementBreteau 1:f3f702086a30 83 * Variables:
ClementBreteau 1:f3f702086a30 84 * hz - SCLK frequency in hz (default = 1MHz)
ClementBreteau 1:f3f702086a30 85 */
ClementBreteau 1:f3f702086a30 86 void frequency(int hz = 1000000);
ClementBreteau 1:f3f702086a30 87
ClementBreteau 1:f3f702086a30 88 /* Function: receive
ClementBreteau 1:f3f702086a30 89 * Polls the SPI to see if data has been received
ClementBreteau 1:f3f702086a30 90 *
ClementBreteau 1:f3f702086a30 91 * Variables:
ClementBreteau 1:f3f702086a30 92 * returns - zero if no data, 1 otherwise
ClementBreteau 1:f3f702086a30 93 */
ClementBreteau 1:f3f702086a30 94 int receive(void);
ClementBreteau 1:f3f702086a30 95
ClementBreteau 1:f3f702086a30 96 /* Function: read
ClementBreteau 1:f3f702086a30 97 * Retrieve data from receive buffer as slave
ClementBreteau 1:f3f702086a30 98 *
ClementBreteau 1:f3f702086a30 99 * Variables:
ClementBreteau 1:f3f702086a30 100 * returns - the data in the receive buffer
ClementBreteau 1:f3f702086a30 101 */
ClementBreteau 1:f3f702086a30 102 int read(void);
ClementBreteau 1:f3f702086a30 103
ClementBreteau 1:f3f702086a30 104 /* Function: reply
ClementBreteau 1:f3f702086a30 105 * Fill the transmission buffer with the value to be written out
ClementBreteau 1:f3f702086a30 106 * as slave on the next received message from the master.
ClementBreteau 1:f3f702086a30 107 *
ClementBreteau 1:f3f702086a30 108 * Variables:
ClementBreteau 1:f3f702086a30 109 * value - the data to be transmitted next
ClementBreteau 1:f3f702086a30 110 */
ClementBreteau 1:f3f702086a30 111 void reply(int value);
ClementBreteau 1:f3f702086a30 112
ClementBreteau 1:f3f702086a30 113 protected:
ClementBreteau 1:f3f702086a30 114
ClementBreteau 1:f3f702086a30 115 SPIName _spi;
ClementBreteau 1:f3f702086a30 116
ClementBreteau 1:f3f702086a30 117 int _bits;
ClementBreteau 1:f3f702086a30 118 int _mode;
ClementBreteau 1:f3f702086a30 119 int _hz;
ClementBreteau 1:f3f702086a30 120
ClementBreteau 1:f3f702086a30 121 };
ClementBreteau 1:f3f702086a30 122
ClementBreteau 1:f3f702086a30 123 } // namespace mbed
ClementBreteau 1:f3f702086a30 124
ClementBreteau 1:f3f702086a30 125 #endif
ClementBreteau 1:f3f702086a30 126
ClementBreteau 1:f3f702086a30 127 #endif