test

Dependencies:   SimpleDMA mbed-rtos mbed

Fork of spiDMAtest by Shreesha S

Revision:
1:3cceef118195
Parent:
0:f0f5102ed9ca
Child:
2:16545dbc88ae
--- a/main.cpp	Wed Jul 15 11:16:13 2015 +0000
+++ b/main.cpp	Thu Jul 16 05:19:02 2015 +0000
@@ -3,33 +3,55 @@
 #include "SimpleDMA.h"
 #include "dmaSPIslave.h"
 
+#define PAYLOAD_LENGTH 1024
+
 dmaSPISlave spi(PTA16, PTA17, PTA15, PTA14);
 RawSerial pc(USBTX, USBRX);
 DigitalOut ledg(LED_GREEN);
 
+bool flag = false;
+
+void do_this(void){
+    flag = true;
+}
+
 int main(){
     pc.baud(9600);
     pc.printf("inside main\r\n");
-    spi.format(8,3);
-    spi.frequency(1000000);
+    spi.format(8,0);
+//    spi.frequency(16000000);
     
-    uint8_t buffer[100] = {0};
+    uint8_t buffer[PAYLOAD_LENGTH] = {0};
     pc.printf("welcome to dma test, start sending data now\r\n");
     
-//    int i = 0;
-//    while(i < 100){
-//        if(spi.receive()){
-//            buffer[i] = spi.read();
-//            ++i;
-//            ledg = !ledg;
+//    while(true){
+//        int i = 0;
+//        while(i < PAYLOAD_LENGTH){
+//            if(spi.receive()){
+//                buffer[i] = spi.read();
+//                ++i;
+//                ledg = !ledg;
+//            }
 //        }
+//        for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){
+//            pc.printf("%02x ", buffer[i]);
+//        }
+//        pc.printf("\r\n");
+//
 //    }
-    spi.bulkRead(buffer, 100);
-    
-    for(int i = 0 ; i < 100 ; ++i){
-        pc.printf("%02x ", buffer[i]);
+
+    spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this);
+    spi.bulkRead_start();
+    while(true){
+        if(flag){
+            flag = false;
+            ledg = !ledg;
+            for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){
+                pc.printf("%02x ", buffer[i]);
+            }
+            pc.printf("\r\n");
+            spi.bulkRead_start();
+        }
     }
-    pc.printf("\r\n");
     
-    return 0;
 }
\ No newline at end of file