yoshinari kou
/
WW_SPI_Uni_TEST_Ver2
White Wizard Board SPI module chip select TEST program
wwChipSelect.cpp@0:747306a9d2ad, 2011-08-26 (annotated)
- Committer:
- halfpitch
- Date:
- Fri Aug 26 15:34:03 2011 +0000
- Revision:
- 0:747306a9d2ad
RevA
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
halfpitch | 0:747306a9d2ad | 1 | //Nest Egg Inc. |
halfpitch | 0:747306a9d2ad | 2 | //http://nestegg.jp/ |
halfpitch | 0:747306a9d2ad | 3 | //White Wizard Board SPI Chip Select Code |
halfpitch | 0:747306a9d2ad | 4 | //Auther : Yoshinari kou |
halfpitch | 0:747306a9d2ad | 5 | //2010/10/03 |
halfpitch | 0:747306a9d2ad | 6 | |
halfpitch | 0:747306a9d2ad | 7 | #include "wwChipSelect.h" |
halfpitch | 0:747306a9d2ad | 8 | //#define NORMAL //if you want to use normal chipselect, you should enable this code. |
halfpitch | 0:747306a9d2ad | 9 | |
halfpitch | 0:747306a9d2ad | 10 | wwChipSelect :: wwChipSelect(PinName cs): |
halfpitch | 0:747306a9d2ad | 11 | ChipSelect(cs){ |
halfpitch | 0:747306a9d2ad | 12 | } |
halfpitch | 0:747306a9d2ad | 13 | |
halfpitch | 0:747306a9d2ad | 14 | void wwChipSelect :: wwCSwrite(int ch){ |
halfpitch | 0:747306a9d2ad | 15 | |
halfpitch | 0:747306a9d2ad | 16 | #ifdef NORMAL |
halfpitch | 0:747306a9d2ad | 17 | if(ch == 0){//reset code |
halfpitch | 0:747306a9d2ad | 18 | ChipSelect.write(1); |
halfpitch | 0:747306a9d2ad | 19 | }else{ |
halfpitch | 0:747306a9d2ad | 20 | ChipSelect.write(0); |
halfpitch | 0:747306a9d2ad | 21 | } |
halfpitch | 0:747306a9d2ad | 22 | |
halfpitch | 0:747306a9d2ad | 23 | #else |
halfpitch | 0:747306a9d2ad | 24 | //start |
halfpitch | 0:747306a9d2ad | 25 | ChipSelect.write(1); |
halfpitch | 0:747306a9d2ad | 26 | wait_us(20); |
halfpitch | 0:747306a9d2ad | 27 | |
halfpitch | 0:747306a9d2ad | 28 | ChipSelect.write(0); |
halfpitch | 0:747306a9d2ad | 29 | |
halfpitch | 0:747306a9d2ad | 30 | wait_us(26);//26 |
halfpitch | 0:747306a9d2ad | 31 | |
halfpitch | 0:747306a9d2ad | 32 | //A1 |
halfpitch | 0:747306a9d2ad | 33 | ChipSelect.write(0x01 & ch); |
halfpitch | 0:747306a9d2ad | 34 | wait_us(20);//46 |
halfpitch | 0:747306a9d2ad | 35 | |
halfpitch | 0:747306a9d2ad | 36 | //A2 |
halfpitch | 0:747306a9d2ad | 37 | ChipSelect.write((0x02 & ch)>>1); |
halfpitch | 0:747306a9d2ad | 38 | wait_us(20);//66 |
halfpitch | 0:747306a9d2ad | 39 | |
halfpitch | 0:747306a9d2ad | 40 | //A3 |
halfpitch | 0:747306a9d2ad | 41 | ChipSelect.write((0x04 & ch)>>2); |
halfpitch | 0:747306a9d2ad | 42 | wait_us(20);//86 |
halfpitch | 0:747306a9d2ad | 43 | |
halfpitch | 0:747306a9d2ad | 44 | //A4 |
halfpitch | 0:747306a9d2ad | 45 | ChipSelect.write((0x08 & ch)>>3); |
halfpitch | 0:747306a9d2ad | 46 | wait_us(20);//106 |
halfpitch | 0:747306a9d2ad | 47 | |
halfpitch | 0:747306a9d2ad | 48 | ChipSelect.write(1); |
halfpitch | 0:747306a9d2ad | 49 | #endif |
halfpitch | 0:747306a9d2ad | 50 | } |
halfpitch | 0:747306a9d2ad | 51 |