test
Dependencies: SimpleDMA mbed-rtos mbed
Fork of spiDMAtest by
main.cpp
- Committer:
- Piasiv1206
- Date:
- 2016-06-26
- Revision:
- 4:8e18509be6ff
- Parent:
- 3:972fa06ef0aa
File content as of revision 4:8e18509be6ff:
#include "mbed.h" #include "SimpleDMA.h" #include "dmaSPIslave.h" #define PAYLOAD_LENGTH 16 #define PAY_SPI_MOSI PTD6 #define PAY_SPI_MISO PTD7 #define PAY_SPI_CLK PTD5 #define PAY_SPI_CS PTE16 // dmaSPISlave spi(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS); dmaSPISlave spi(PTD6, PTD7, PTD5,PTD4 ); 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,0); spi.frequency(10000000); 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(); while(true){ if(flag){ flag = false; //ledg = !ledg; for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){ pc.printf("data %d %d \r\n",i, buffer[i]); } pc.printf("\r\n"); //start dma again after handling the data spi.bulkRead_start(); } } }