DMA for Science thread

Dependencies:   SimpleDMA mbed-rtos mbed

Fork of spiDMAtest by Shreesha S

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SimpleDMA.h"
00003 #include "dmaSPIslave.h"
00004 #define PAYLOAD_LENGTH 6723
00005      #define PAY_SPI_MOSI PTE18
00006     #define PAY_SPI_MISO PTE19
00007     #define PAY_SPI_CLK PTE17
00008     #define PAY_SPI_CS PTE16
00009 Timer T;
00010 dmaSPISlave spi(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS);
00011 RawSerial pc(USBTX, USBRX);
00012 DigitalOut ledg(PTB11);
00013 
00014 bool flag = false;
00015 
00016 void do_this(void){
00017     flag = true;
00018 }
00019 
00020 int main(){
00021     pc.baud(1200);
00022     pc.printf("inside main\r\n");
00023     spi.format(8,0);
00024     spi.frequency(1000000);
00025     
00026     uint8_t buffer[PAYLOAD_LENGTH] = {0};
00027     pc.printf("welcome to dma test, start sending data now\r\n");
00028 
00029 //    initialise the buffer for dma
00030     spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this);
00031 //    start dma read
00032     spi.bulkRead_start();
00033     T.start();
00034     while(true){
00035         if(flag){
00036             flag = false;
00037             ledg = !ledg;
00038             pc.printf("re %f\n",T.read());
00039             /*for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){
00040                 pc.printf("%02x ", buffer[i]);
00041             }
00042             pc.printf("\r\n");*/
00043 
00044 //            start dma again after handling the data
00045             spi.bulkRead_start();
00046         }
00047     }
00048     
00049 }