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@3:6ab4e8e3aa02, 2016-03-29 (annotated)
- Committer:
- baba2357
- Date:
- Tue Mar 29 12:36:50 2016 +0000
- Revision:
- 3:6ab4e8e3aa02
- Parent:
- 2:bed6b204e64c
- Child:
- 4:ef6f18eda3e2
???
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 | 3:6ab4e8e3aa02 | 7 | int FM=0; |
baba2357 | 1:86d25c1c4bd5 | 8 | bool RR; |
baba2357 | 1:86d25c1c4bd5 | 9 | bool LR; |
baba2357 | 1:86d25c1c4bd5 | 10 | char speed_X; |
baba2357 | 1:86d25c1c4bd5 | 11 | char speed_Y; |
baba2357 | 3:6ab4e8e3aa02 | 12 | bool Xpm=0; |
baba2357 | 3:6ab4e8e3aa02 | 13 | bool Ypm=0; |
baba2357 | 2:bed6b204e64c | 14 | |
baba2357 | 1:86d25c1c4bd5 | 15 | //SPI NUCLEO |
baba2357 | 1:86d25c1c4bd5 | 16 | void spi_mbed(); |
baba2357 | 1:86d25c1c4bd5 | 17 | void spi_nucleo(); |
baba2357 | 2:bed6b204e64c | 18 | void getGyro(); |
baba2357 | 2:bed6b204e64c | 19 | void spiInit(); |
baba2357 | 2:bed6b204e64c | 20 | typedef unsigned short u16; |
baba2357 | 2:bed6b204e64c | 21 | long int angle; |
baba2357 | 2:bed6b204e64c | 22 | double now_angle; |
baba2357 | 2:bed6b204e64c | 23 | Serial pc(USBTX,USBRX); |
baba2357 | 1:86d25c1c4bd5 | 24 | #endif |
baba2357 | 1:86d25c1c4bd5 | 25 | void spiInit(){ |
baba2357 | 1:86d25c1c4bd5 | 26 | from_mbed.format(16,3); |
baba2357 | 1:86d25c1c4bd5 | 27 | from_gyro.format(16,3); |
baba2357 | 1:86d25c1c4bd5 | 28 | from_mbed.frequency(1000000); |
baba2357 | 1:86d25c1c4bd5 | 29 | from_gyro.frequency(1000000); |
baba2357 | 1:86d25c1c4bd5 | 30 | } |
baba2357 | 2:bed6b204e64c | 31 | |
baba2357 | 3:6ab4e8e3aa02 | 32 | void spi_mbed() |
baba2357 | 3:6ab4e8e3aa02 | 33 | { |
baba2357 | 3:6ab4e8e3aa02 | 34 | if(from_mbed.receive()) { |
baba2357 | 3:6ab4e8e3aa02 | 35 | FM=from_mbed.read(); |
baba2357 | 3:6ab4e8e3aa02 | 36 | RR=FM>>15; |
baba2357 | 3:6ab4e8e3aa02 | 37 | LR=FM>>14; |
baba2357 | 3:6ab4e8e3aa02 | 38 | Xpm=FM>>13; |
baba2357 | 3:6ab4e8e3aa02 | 39 | Ypm=FM>>6; |
baba2357 | 3:6ab4e8e3aa02 | 40 | if(RR==1) { |
baba2357 | 3:6ab4e8e3aa02 | 41 | } //右旋回の関数へ |
baba2357 | 3:6ab4e8e3aa02 | 42 | else if(LR==1) { |
baba2357 | 3:6ab4e8e3aa02 | 43 | } //左旋回の関数へ |
baba2357 | 3:6ab4e8e3aa02 | 44 | else if(Xpm==1) { //コントローラーのX方向成分入力 |
baba2357 | 3:6ab4e8e3aa02 | 45 | speed_X=FM&0x1F80; |
baba2357 | 3:6ab4e8e3aa02 | 46 | speed_X=speed_X>>7; |
baba2357 | 3:6ab4e8e3aa02 | 47 | if(Ypm==1) speed_Y=FM&0x3F; |
baba2357 | 3:6ab4e8e3aa02 | 48 | else { |
baba2357 | 3:6ab4e8e3aa02 | 49 | speed_Y=FM&0x3F; |
baba2357 | 3:6ab4e8e3aa02 | 50 | speed_Y=speed_Y*(-1); |
baba2357 | 3:6ab4e8e3aa02 | 51 | } |
baba2357 | 3:6ab4e8e3aa02 | 52 | } |
baba2357 | 3:6ab4e8e3aa02 | 53 | else { |
baba2357 | 3:6ab4e8e3aa02 | 54 | speed_X=FM&0x1F80; |
baba2357 | 3:6ab4e8e3aa02 | 55 | speed_X=speed_X>>7; |
baba2357 | 3:6ab4e8e3aa02 | 56 | speed_X=(-1)*speed_X; |
baba2357 | 3:6ab4e8e3aa02 | 57 | if(Ypm==1) speed_Y=FM&0x3F; |
baba2357 | 3:6ab4e8e3aa02 | 58 | else { |
baba2357 | 3:6ab4e8e3aa02 | 59 | speed_Y=FM&0x3F; |
baba2357 | 3:6ab4e8e3aa02 | 60 | speed_Y=speed_Y*(-1); |
baba2357 | 2:bed6b204e64c | 61 | } |
baba2357 | 1:86d25c1c4bd5 | 62 | } |
baba2357 | 2:bed6b204e64c | 63 | } |
baba2357 | 3:6ab4e8e3aa02 | 64 | } |
baba2357 | 3:6ab4e8e3aa02 | 65 | |
baba2357 | 1:86d25c1c4bd5 | 66 | void getGyro(){ |
baba2357 | 1:86d25c1c4bd5 | 67 | u16 data; |
baba2357 | 2:bed6b204e64c | 68 | if(from_gyro.receive()){ |
baba2357 | 2:bed6b204e64c | 69 | data = from_gyro.read(); |
baba2357 | 1:86d25c1c4bd5 | 70 | if(data >> 15) angle = -(data & 0x7fff); |
baba2357 | 1:86d25c1c4bd5 | 71 | else angle = data & 0x7fff; |
baba2357 | 1:86d25c1c4bd5 | 72 | now_angle = (double)angle / 10; |
baba2357 | 2:bed6b204e64c | 73 | } |
baba2357 | 1:86d25c1c4bd5 | 74 | } |