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.
Dependencies: mbed
spi_nucleo.h@7:4f5cd0051db0, 2016-04-01 (annotated)
- Committer:
- username16248
- Date:
- Fri Apr 01 06:15:24 2016 +0000
- Revision:
- 7:4f5cd0051db0
- Parent:
- 6:bb86e2999be0
- Parent:
- 4:ef6f18eda3e2
removed speed_control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
baba2357 | 1:86d25c1c4bd5 | 1 | #ifndef SPI_NUCLEO_H |
baba2357 | 1:86d25c1c4bd5 | 2 | #define SPI_NUCLEO_H |
baba2357 | 2:bed6b204e64c | 3 | #include "pin_file.h" |
baba2357 | 2:bed6b204e64c | 4 | #include <string.h> |
baba2357 | 2:bed6b204e64c | 5 | |
baba2357 | 1:86d25c1c4bd5 | 6 | //SPI mbed |
baba2357 | 4:ef6f18eda3e2 | 7 | bool RR=0; |
baba2357 | 4:ef6f18eda3e2 | 8 | bool LR=0; |
baba2357 | 4:ef6f18eda3e2 | 9 | int speed_X; |
baba2357 | 4:ef6f18eda3e2 | 10 | int speed_Y; |
baba2357 | 3:6ab4e8e3aa02 | 11 | bool Xpm=0; |
baba2357 | 3:6ab4e8e3aa02 | 12 | bool Ypm=0; |
baba2357 | 1:86d25c1c4bd5 | 13 | //SPI NUCLEO |
baba2357 | 1:86d25c1c4bd5 | 14 | void spi_mbed(); |
baba2357 | 1:86d25c1c4bd5 | 15 | void spi_nucleo(); |
baba2357 | 2:bed6b204e64c | 16 | void getGyro(); |
baba2357 | 2:bed6b204e64c | 17 | void spiInit(); |
baba2357 | 4:ef6f18eda3e2 | 18 | typedef unsigned u16; |
baba2357 | 4:ef6f18eda3e2 | 19 | u16 FM; |
baba2357 | 2:bed6b204e64c | 20 | long int angle; |
baba2357 | 2:bed6b204e64c | 21 | double now_angle; |
baba2357 | 2:bed6b204e64c | 22 | Serial pc(USBTX,USBRX); |
baba2357 | 4:ef6f18eda3e2 | 23 | void spiInit(); |
baba2357 | 4:ef6f18eda3e2 | 24 | void spi_mbed(); |
baba2357 | 4:ef6f18eda3e2 | 25 | void getGyro(); |
baba2357 | 4:ef6f18eda3e2 | 26 | #endif |
baba2357 | 4:ef6f18eda3e2 | 27 | |
baba2357 | 4:ef6f18eda3e2 | 28 | void spiInit() |
baba2357 | 4:ef6f18eda3e2 | 29 | { |
baba2357 | 1:86d25c1c4bd5 | 30 | from_mbed.format(16,3); |
baba2357 | 1:86d25c1c4bd5 | 31 | from_gyro.format(16,3); |
baba2357 | 1:86d25c1c4bd5 | 32 | from_mbed.frequency(1000000); |
baba2357 | 1:86d25c1c4bd5 | 33 | from_gyro.frequency(1000000); |
baba2357 | 1:86d25c1c4bd5 | 34 | } |
baba2357 | 2:bed6b204e64c | 35 | |
baba2357 | 3:6ab4e8e3aa02 | 36 | void spi_mbed() |
baba2357 | 4:ef6f18eda3e2 | 37 | { |
baba2357 | 3:6ab4e8e3aa02 | 38 | if(from_mbed.receive()) { |
baba2357 | 4:ef6f18eda3e2 | 39 | RR=0; |
baba2357 | 4:ef6f18eda3e2 | 40 | LR=0; |
baba2357 | 3:6ab4e8e3aa02 | 41 | FM=from_mbed.read(); |
baba2357 | 3:6ab4e8e3aa02 | 42 | Xpm=FM>>13; |
baba2357 | 4:ef6f18eda3e2 | 43 | Ypm=(FM&0x40)>>6; |
baba2357 | 4:ef6f18eda3e2 | 44 | if(FM>>15==1) { |
baba2357 | 4:ef6f18eda3e2 | 45 | RR=1; |
baba2357 | 3:6ab4e8e3aa02 | 46 | } //右旋回の関数へ |
baba2357 | 4:ef6f18eda3e2 | 47 | else if(FM>>14==1) { |
baba2357 | 4:ef6f18eda3e2 | 48 | LR=1; |
baba2357 | 3:6ab4e8e3aa02 | 49 | } //左旋回の関数へ |
baba2357 | 3:6ab4e8e3aa02 | 50 | else if(Xpm==1) { //コントローラーのX方向成分入力 |
baba2357 | 3:6ab4e8e3aa02 | 51 | speed_X=FM&0x1F80; |
baba2357 | 3:6ab4e8e3aa02 | 52 | speed_X=speed_X>>7; |
baba2357 | 4:ef6f18eda3e2 | 53 | if(Ypm==0) speed_Y=FM&0x3F; |
baba2357 | 3:6ab4e8e3aa02 | 54 | else { |
baba2357 | 3:6ab4e8e3aa02 | 55 | speed_Y=FM&0x3F; |
baba2357 | 4:ef6f18eda3e2 | 56 | speed_Y=(-1)*speed_Y; |
baba2357 | 3:6ab4e8e3aa02 | 57 | } |
baba2357 | 3:6ab4e8e3aa02 | 58 | } |
baba2357 | 3:6ab4e8e3aa02 | 59 | else { |
baba2357 | 3:6ab4e8e3aa02 | 60 | speed_X=FM&0x1F80; |
baba2357 | 3:6ab4e8e3aa02 | 61 | speed_X=speed_X>>7; |
baba2357 | 3:6ab4e8e3aa02 | 62 | speed_X=(-1)*speed_X; |
baba2357 | 4:ef6f18eda3e2 | 63 | if(Ypm==0) speed_Y=FM&0x3F; |
baba2357 | 3:6ab4e8e3aa02 | 64 | else { |
baba2357 | 3:6ab4e8e3aa02 | 65 | speed_Y=FM&0x3F; |
baba2357 | 4:ef6f18eda3e2 | 66 | speed_Y=(-1)*speed_Y; |
baba2357 | 2:bed6b204e64c | 67 | } |
baba2357 | 1:86d25c1c4bd5 | 68 | } |
baba2357 | 2:bed6b204e64c | 69 | } |
baba2357 | 3:6ab4e8e3aa02 | 70 | } |
baba2357 | 4:ef6f18eda3e2 | 71 | |
baba2357 | 4:ef6f18eda3e2 | 72 | void getGyro() |
baba2357 | 4:ef6f18eda3e2 | 73 | { |
baba2357 | 4:ef6f18eda3e2 | 74 | int data; |
baba2357 | 4:ef6f18eda3e2 | 75 | if(from_gyro.receive()) { |
baba2357 | 2:bed6b204e64c | 76 | data = from_gyro.read(); |
baba2357 | 4:ef6f18eda3e2 | 77 | if(data >> 15) angle = -(data & 0x7fff); |
baba2357 | 1:86d25c1c4bd5 | 78 | else angle = data & 0x7fff; |
baba2357 | 1:86d25c1c4bd5 | 79 | now_angle = (double)angle / 10; |
baba2357 | 4:ef6f18eda3e2 | 80 | // pc.printf("%d\r\n",data); |
baba2357 | 1:86d25c1c4bd5 | 81 | } |
baba2357 | 4:ef6f18eda3e2 | 82 | } |
baba2357 | 4:ef6f18eda3e2 | 83 |