![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
DMA for Science thread
Dependencies: SimpleDMA mbed-rtos mbed
Fork of spiDMAtest by
main.cpp
- Committer:
- shreeshas95
- Date:
- 2016-04-22
- Revision:
- 3:e59d61aac1e1
- Parent:
- 2:16545dbc88ae
File content as of revision 3:e59d61aac1e1:
#include "mbed.h" #include "SimpleDMA.h" #include "dmaSPIslave.h" #define PAYLOAD_LENGTH 6723 #define PAY_SPI_MOSI PTE18 #define PAY_SPI_MISO PTE19 #define PAY_SPI_CLK PTE17 #define PAY_SPI_CS PTE16 dmaSPISlave spi(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS); RawSerial pc(USBTX, USBRX); //DigitalOut ledg(LED_GREEN); //DigitalOut ledr(LED_RED); bool flag = false; void do_this(void){ flag = true; } void do_this2(void){ flag = true; } int main(){ // ledr = 1; // ledg = 1; pc.baud(1200); pc.printf("inside main\r\n"); spi.format(8,0); spi.frequency(1000000); uint8_t buffer[PAYLOAD_LENGTH] = {0}; pc.printf("welcome to dma test, start sending data now\r\n"); // initialise the buffer for dma spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this); // start dma read spi.bulkRead_start(); int count = 0; while(true){ // int i = 0; // while(i < PAYLOAD_LENGTH){ // if(spi.receive()){ // buffer[i] = spi.read(); // ++i; // } // } // ledr = !ledr; // for(int j = 0 ; j < PAYLOAD_LENGTH ; ++j){ // printf("%02x ", buffer[j]); // } if(flag){ count++; flag = false; // ledg = !ledg; // for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){ // pc.printf("%02x ", buffer[i]); // } pc.printf("DATA RECEIVED\r\n"); // start dma again after handling the data if(count == 3){ count = 0; spi.bulkRead_end(); pc.printf("tried END\r\n"); wait(1); pc.printf("restarting the procedure\r\n"); spi.bulkRead_restart(); spi.bulkRead_start(); } else{ spi.bulkRead_start(); } } } }