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@1:86d25c1c4bd5, 2016-03-25 (annotated)
- Committer:
- baba2357
- Date:
- Fri Mar 25 03:08:41 2016 +0000
- Revision:
- 1:86d25c1c4bd5
- Child:
- 2:bed6b204e64c
??????
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 | 1:86d25c1c4bd5 | 3 | //SPI mbed |
baba2357 | 1:86d25c1c4bd5 | 4 | SPI from_mbed(PA_5, PA_6, PA_7); |
baba2357 | 1:86d25c1c4bd5 | 5 | DigitalIn (PA_4); |
baba2357 | 1:86d25c1c4bd5 | 6 | int FM; |
baba2357 | 1:86d25c1c4bd5 | 7 | bool RR; |
baba2357 | 1:86d25c1c4bd5 | 8 | bool LR; |
baba2357 | 1:86d25c1c4bd5 | 9 | char speed_X; |
baba2357 | 1:86d25c1c4bd5 | 10 | char speed_Y; |
baba2357 | 1:86d25c1c4bd5 | 11 | //SPI NUCLEO |
baba2357 | 1:86d25c1c4bd5 | 12 | |
baba2357 | 1:86d25c1c4bd5 | 13 | |
baba2357 | 1:86d25c1c4bd5 | 14 | |
baba2357 | 1:86d25c1c4bd5 | 15 | SPI from_gyro(PB_13, PB_14, PB_15); |
baba2357 | 1:86d25c1c4bd5 | 16 | DigitalIn (PB_12); |
baba2357 | 1:86d25c1c4bd5 | 17 | int G; |
baba2357 | 1:86d25c1c4bd5 | 18 | void spi_mbed(); |
baba2357 | 1:86d25c1c4bd5 | 19 | void spi_nucleo(); |
baba2357 | 1:86d25c1c4bd5 | 20 | |
baba2357 | 1:86d25c1c4bd5 | 21 | #endif |
baba2357 | 1:86d25c1c4bd5 | 22 | void spiInit(){ |
baba2357 | 1:86d25c1c4bd5 | 23 | from_mbed.format(16,3); |
baba2357 | 1:86d25c1c4bd5 | 24 | from_gyro.format(16,3); |
baba2357 | 1:86d25c1c4bd5 | 25 | from_mbed.frequency(1000000); |
baba2357 | 1:86d25c1c4bd5 | 26 | from_gyro.frequency(1000000); |
baba2357 | 1:86d25c1c4bd5 | 27 | } |
baba2357 | 1:86d25c1c4bd5 | 28 | |
baba2357 | 1:86d25c1c4bd5 | 29 | void spi_mbed(){ |
baba2357 | 1:86d25c1c4bd5 | 30 | if(from_mbed.receive()){ |
baba2357 | 1:86d25c1c4bd5 | 31 | FM=from_mbed.read(); |
baba2357 | 1:86d25c1c4bd5 | 32 | RR=FM>>15; |
baba2357 | 1:86d25c1c4bd5 | 33 | LR=FM>>14; |
baba2357 | 1:86d25c1c4bd5 | 34 | if(RR==1) //右旋回の関数へ |
baba2357 | 1:86d25c1c4bd5 | 35 | else if(LR==1) //左旋回の関数へ |
baba2357 | 1:86d25c1c4bd5 | 36 | else if(FM>>13==1){ //コントローラーのX方向成分入力 |
baba2357 | 1:86d25c1c4bd5 | 37 | speed_X=FM>>7-128; |
baba2357 | 1:86d25c1c4bd5 | 38 | if(FM>>6==1) speed_Y=FM-128; |
baba2357 | 1:86d25c1c4bd5 | 39 | else speed_Y=FM; |
baba2357 | 1:86d25c1c4bd5 | 40 | } |
baba2357 | 1:86d25c1c4bd5 | 41 | else{ |
baba2357 | 1:86d25c1c4bd5 | 42 | speed_X=FM>>7*(-1); |
baba2357 | 1:86d25c1c4bd5 | 43 | if(FM>>6==1) speed_Y=FM-128; |
baba2357 | 1:86d25c1c4bd5 | 44 | else speed_Y=FM; |
baba2357 | 1:86d25c1c4bd5 | 45 | } |
baba2357 | 1:86d25c1c4bd5 | 46 | } |
baba2357 | 1:86d25c1c4bd5 | 47 | void getGyro(){ |
baba2357 | 1:86d25c1c4bd5 | 48 | u16 data; |
baba2357 | 1:86d25c1c4bd5 | 49 | if(from_gyro.receive()) { |
baba2357 | 1:86d25c1c4bd5 | 50 | data = gyro_gyro.read(); |
baba2357 | 1:86d25c1c4bd5 | 51 | if(data >> 15) angle = -(data & 0x7fff); |
baba2357 | 1:86d25c1c4bd5 | 52 | else angle = data & 0x7fff; |
baba2357 | 1:86d25c1c4bd5 | 53 | now_angle = (double)angle / 10; |
baba2357 | 1:86d25c1c4bd5 | 54 | } |
baba2357 | 1:86d25c1c4bd5 | 55 | } |