test

Dependencies:   SimpleDMA mbed-rtos mbed

Fork of spiDMAtest by Siva ram

Committer:
Piasiv1206
Date:
Mon Dec 21 08:57:48 2015 +0000
Revision:
3:972fa06ef0aa
Parent:
2:16545dbc88ae
Child:
4:8e18509be6ff
gfkiuk

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shreeshas95 0:f0f5102ed9ca 1 #include "mbed.h"
shreeshas95 0:f0f5102ed9ca 2 #include "SimpleDMA.h"
shreeshas95 0:f0f5102ed9ca 3 #include "dmaSPIslave.h"
shreeshas95 0:f0f5102ed9ca 4
shreeshas95 1:3cceef118195 5 #define PAYLOAD_LENGTH 1024
shreeshas95 1:3cceef118195 6
Piasiv1206 3:972fa06ef0aa 7 dmaSPISlave spi(PTD6, PTD7, PTD5,PTD4 );
shreeshas95 0:f0f5102ed9ca 8 RawSerial pc(USBTX, USBRX);
Piasiv1206 3:972fa06ef0aa 9 //DigitalOut ledg(LED_GREEN);
shreeshas95 0:f0f5102ed9ca 10
shreeshas95 1:3cceef118195 11 bool flag = false;
shreeshas95 1:3cceef118195 12
shreeshas95 1:3cceef118195 13 void do_this(void){
shreeshas95 1:3cceef118195 14 flag = true;
shreeshas95 1:3cceef118195 15 }
shreeshas95 1:3cceef118195 16
shreeshas95 0:f0f5102ed9ca 17 int main(){
shreeshas95 0:f0f5102ed9ca 18 pc.baud(9600);
shreeshas95 0:f0f5102ed9ca 19 pc.printf("inside main\r\n");
shreeshas95 1:3cceef118195 20 spi.format(8,0);
shreeshas95 2:16545dbc88ae 21 spi.frequency(10000000);
shreeshas95 0:f0f5102ed9ca 22
shreeshas95 1:3cceef118195 23 uint8_t buffer[PAYLOAD_LENGTH] = {0};
shreeshas95 0:f0f5102ed9ca 24 pc.printf("welcome to dma test, start sending data now\r\n");
shreeshas95 2:16545dbc88ae 25
shreeshas95 2:16545dbc88ae 26 // initialise the buffer for dma
shreeshas95 2:16545dbc88ae 27 spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this);
shreeshas95 2:16545dbc88ae 28 // start dma read
shreeshas95 2:16545dbc88ae 29 spi.bulkRead_start();
shreeshas95 0:f0f5102ed9ca 30
shreeshas95 1:3cceef118195 31 while(true){
shreeshas95 1:3cceef118195 32 if(flag){
shreeshas95 1:3cceef118195 33 flag = false;
Piasiv1206 3:972fa06ef0aa 34 //ledg = !ledg;
Piasiv1206 3:972fa06ef0aa 35
shreeshas95 2:16545dbc88ae 36
Piasiv1206 3:972fa06ef0aa 37 for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){
Piasiv1206 3:972fa06ef0aa 38 pc.printf("data %d %d \r\n",i, buffer[i]); }
Piasiv1206 3:972fa06ef0aa 39 pc.printf("\r\n");
shreeshas95 2:16545dbc88ae 40
Piasiv1206 3:972fa06ef0aa 41 //start dma again after handling the data
shreeshas95 1:3cceef118195 42 spi.bulkRead_start();
shreeshas95 1:3cceef118195 43 }
shreeshas95 0:f0f5102ed9ca 44 }
shreeshas95 0:f0f5102ed9ca 45
shreeshas95 0:f0f5102ed9ca 46 }