test

Dependencies:   SimpleDMA mbed-rtos mbed

Fork of spiDMAtest by Siva ram

Committer:
Piasiv1206
Date:
Sun Jun 26 11:45:07 2016 +0000
Revision:
4:8e18509be6ff
Parent:
3:972fa06ef0aa
hello

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