SPI slave DMA-read program for FRDMKL46Z, verified, working
Dependencies: SimpleDMA mbed-rtos mbed
main.cpp@4:33fc4fec3087, 2016-09-27 (annotated)
- Committer:
- shreeshas95
- Date:
- Tue Sep 27 10:39:48 2016 +0000
- Revision:
- 4:33fc4fec3087
- Parent:
- 3:e59d61aac1e1
Simple test program for spi-DMA
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:e59d61aac1e1 | 5 | #define PAYLOAD_LENGTH 6723 |
shreeshas95 | 1:3cceef118195 | 6 | |
shreeshas95 | 3:e59d61aac1e1 | 7 | #define PAY_SPI_MOSI PTE18 |
shreeshas95 | 3:e59d61aac1e1 | 8 | #define PAY_SPI_MISO PTE19 |
shreeshas95 | 3:e59d61aac1e1 | 9 | #define PAY_SPI_CLK PTE17 |
shreeshas95 | 3:e59d61aac1e1 | 10 | #define PAY_SPI_CS PTE16 |
shreeshas95 | 3:e59d61aac1e1 | 11 | |
shreeshas95 | 3:e59d61aac1e1 | 12 | dmaSPISlave spi(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS); |
shreeshas95 | 0:f0f5102ed9ca | 13 | RawSerial pc(USBTX, USBRX); |
shreeshas95 | 4:33fc4fec3087 | 14 | DigitalOut ledg(LED_GREEN); |
shreeshas95 | 3:e59d61aac1e1 | 15 | //DigitalOut ledr(LED_RED); |
shreeshas95 | 0:f0f5102ed9ca | 16 | |
shreeshas95 | 1:3cceef118195 | 17 | bool flag = false; |
shreeshas95 | 1:3cceef118195 | 18 | |
shreeshas95 | 1:3cceef118195 | 19 | void do_this(void){ |
shreeshas95 | 1:3cceef118195 | 20 | flag = true; |
shreeshas95 | 1:3cceef118195 | 21 | } |
shreeshas95 | 1:3cceef118195 | 22 | |
shreeshas95 | 0:f0f5102ed9ca | 23 | int main(){ |
shreeshas95 | 3:e59d61aac1e1 | 24 | // ledr = 1; |
shreeshas95 | 3:e59d61aac1e1 | 25 | // ledg = 1; |
shreeshas95 | 3:e59d61aac1e1 | 26 | pc.baud(1200); |
shreeshas95 | 0:f0f5102ed9ca | 27 | pc.printf("inside main\r\n"); |
shreeshas95 | 1:3cceef118195 | 28 | spi.format(8,0); |
shreeshas95 | 3:e59d61aac1e1 | 29 | spi.frequency(1000000); |
shreeshas95 | 0:f0f5102ed9ca | 30 | |
shreeshas95 | 1:3cceef118195 | 31 | uint8_t buffer[PAYLOAD_LENGTH] = {0}; |
shreeshas95 | 0:f0f5102ed9ca | 32 | pc.printf("welcome to dma test, start sending data now\r\n"); |
shreeshas95 | 2:16545dbc88ae | 33 | |
shreeshas95 | 2:16545dbc88ae | 34 | // initialise the buffer for dma |
shreeshas95 | 2:16545dbc88ae | 35 | spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this); |
shreeshas95 | 2:16545dbc88ae | 36 | // start dma read |
shreeshas95 | 2:16545dbc88ae | 37 | spi.bulkRead_start(); |
shreeshas95 | 0:f0f5102ed9ca | 38 | |
shreeshas95 | 1:3cceef118195 | 39 | while(true){ |
shreeshas95 | 4:33fc4fec3087 | 40 | |
shreeshas95 | 3:e59d61aac1e1 | 41 | // int i = 0; |
shreeshas95 | 3:e59d61aac1e1 | 42 | // while(i < PAYLOAD_LENGTH){ |
shreeshas95 | 3:e59d61aac1e1 | 43 | // if(spi.receive()){ |
shreeshas95 | 3:e59d61aac1e1 | 44 | // buffer[i] = spi.read(); |
shreeshas95 | 3:e59d61aac1e1 | 45 | // ++i; |
shreeshas95 | 3:e59d61aac1e1 | 46 | // } |
shreeshas95 | 3:e59d61aac1e1 | 47 | // } |
shreeshas95 | 3:e59d61aac1e1 | 48 | // ledr = !ledr; |
shreeshas95 | 3:e59d61aac1e1 | 49 | // for(int j = 0 ; j < PAYLOAD_LENGTH ; ++j){ |
shreeshas95 | 3:e59d61aac1e1 | 50 | // printf("%02x ", buffer[j]); |
shreeshas95 | 3:e59d61aac1e1 | 51 | // } |
shreeshas95 | 3:e59d61aac1e1 | 52 | |
shreeshas95 | 3:e59d61aac1e1 | 53 | |
shreeshas95 | 1:3cceef118195 | 54 | if(flag){ |
shreeshas95 | 1:3cceef118195 | 55 | flag = false; |
shreeshas95 | 3:e59d61aac1e1 | 56 | |
shreeshas95 | 2:16545dbc88ae | 57 | // start dma again after handling the data |
shreeshas95 | 4:33fc4fec3087 | 58 | spi.bulkRead_start(); |
shreeshas95 | 4:33fc4fec3087 | 59 | ledg = !ledg; |
shreeshas95 | 1:3cceef118195 | 60 | } |
shreeshas95 | 4:33fc4fec3087 | 61 | } |
shreeshas95 | 0:f0f5102ed9ca | 62 | } |