White Wizard Board SPI module chip select TEST program

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
halfpitch
Date:
Fri Aug 26 15:34:03 2011 +0000
Commit message:
RevA

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
wwChipSelect.cpp Show annotated file Show diff for this revision Revisions of this file
wwChipSelect.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 747306a9d2ad main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 26 15:34:03 2011 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#include "wwChipSelect.h"
+
+//Nest Egg Inc.
+//http://wizard.nestegg.jp/
+//channel No must be A1 A2 A3 A4
+
+//#define ch_num 0x05  //channel No 0101, depend on your SPI module setting.
+//#define ch_num1 0x08  //channel No 1000, depend on your SPI module setting.
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+
+void LEDbit(int ch){
+        
+    //A1
+        myled1 = (0x01 & ch); 
+        
+    //A2    
+        myled2 =((0x02 & ch)>>1);
+        
+    //A3    
+        myled3 =((0x04 & ch)>>2);
+        
+    //A4    
+        myled4 =((0x08 & ch)>>3);
+
+}
+
+int main() {
+
+        wwChipSelect wwcs(p8);
+        int ch_num=1;
+        
+    while(1) {
+        for(ch_num=0;ch_num<16;ch_num++){
+            //myled1 =! myled1;
+            LEDbit(ch_num);
+            wwcs.wwCSwrite(ch_num);
+            printf("ch No.%d\n",ch_num);
+            wait(0.7);
+        }
+    }
+}
+
diff -r 000000000000 -r 747306a9d2ad mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 26 15:34:03 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/32af5db564d4
diff -r 000000000000 -r 747306a9d2ad wwChipSelect.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wwChipSelect.cpp	Fri Aug 26 15:34:03 2011 +0000
@@ -0,0 +1,51 @@
+//Nest Egg Inc.
+//http://nestegg.jp/
+//White Wizard Board SPI Chip Select Code
+//Auther : Yoshinari kou
+//2010/10/03
+
+#include "wwChipSelect.h"
+//#define NORMAL    //if you want to use normal chipselect, you should enable this code.
+
+wwChipSelect :: wwChipSelect(PinName cs):
+ ChipSelect(cs){
+ }
+ 
+void wwChipSelect :: wwCSwrite(int ch){
+
+#ifdef NORMAL
+    if(ch == 0){//reset code
+        ChipSelect.write(1);
+    }else{
+        ChipSelect.write(0);
+    }
+    
+#else
+    //start
+    ChipSelect.write(1);   
+    wait_us(20); 
+    
+    ChipSelect.write(0);
+        
+    wait_us(26);//26
+    
+//A1
+    ChipSelect.write(0x01 & ch);    
+    wait_us(20);//46  
+    
+//A2    
+    ChipSelect.write((0x02 & ch)>>1);
+    wait_us(20);//66  
+    
+//A3    
+    ChipSelect.write((0x04 & ch)>>2);
+    wait_us(20);//86 
+    
+//A4    
+    ChipSelect.write((0x08 & ch)>>3);
+    wait_us(20);//106
+    
+    ChipSelect.write(1);
+#endif
+}
+
diff -r 000000000000 -r 747306a9d2ad wwChipSelect.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wwChipSelect.h	Fri Aug 26 15:34:03 2011 +0000
@@ -0,0 +1,16 @@
+//Nest Egg Inc.
+//http://nestegg.jp/
+//White Wizard Board SPI Chip Select Code
+//Auther : Yoshinari kou
+//2010/10/03
+
+#include "mbed.h"
+
+class wwChipSelect
+{
+    private:
+        DigitalOut  ChipSelect;
+    public:
+        wwChipSelect(PinName);  //constructor
+        void wwCSwrite(int);
+};
\ No newline at end of file