SPI slave program to enable communication between the FPGA and the STM32L432 board.

Dependencies:   mbed

Revision:
13:c7e8e277f884
Parent:
12:3e7da86a49ff
Child:
14:7bbaafa22f8d
--- a/DMA_SPI.cpp	Mon Mar 25 02:15:44 2019 +0000
+++ b/DMA_SPI.cpp	Fri Apr 19 18:43:39 2019 +0000
@@ -3,6 +3,7 @@
 
 int16_t data_to_transmit[12];
 int16_t received_data[12];
+int16_t IMU_Data_Array[12];
 
 
 int16_t SampleFIFO[10][12];
@@ -10,6 +11,8 @@
 extern int pointerNS = 0;
 extern int pointerFS = 0;
 extern char newDataFlag = 0;
+volatile extern char dataRequestFlag = 0;
+volatile extern char dataLoadedFlag = 0;
 
 
 void SPI_DMA_init() {
@@ -255,12 +258,30 @@
 extern "C" void DMA1_Channel3_IRQHandler(void) {     
     if(DMA1->ISR&(1u<<9)) {                                                    //Check whteher data transmit transfer is complete  
         //Read data from the array that stores received data
-        /*
-        for(int x = 0; x <= 11; x++) {
-            data_to_transmit[x] = x+1;
+        if(dataRequestFlag == 1 && dataLoadedFlag == 1) {
+            for(int x = 0; x <= 11; x++) {
+                if(x < 7) {                                                     //Data is only loaded in first 7 places
+                    if(x == 0) {                                                //IMU ID is loaded in array position 0
+                        data_to_transmit[x] = IMU_Data_Array[x];                 //Load the IMU data for transmission
+                       // data_to_transmit[x] = 1;                                //Test Input
+                    }
+                    else {                                                      //Rest is loaded in the following order: x, y, z
+                        data_to_transmit[x] = IMU_Data_Array[x];                 //Load the IMU data for transmission
+                        //data_to_transmit[x] = 48+x;                             //Test Input
+                    }
+                }
+                else {                                                          //After 7 positions have been filled, the rest is filled with zeros
+                    data_to_transmit[x] = 0;                                    //Above 6 there is nothing more to send so send zeros.
+                } 
+            }
+            dataRequestFlag = 0;                                                //Data request has been fulfilled and therefore clear the flag
         }
-        */
+        else {                                                                  //if the two flags arent 1 then load this transmission with zeros
+             for(int x = 0; x <= 11; x++) {
+                data_to_transmit[x] = 0;
+            } 
+        }
         CLEAR_DMA1_CH3_IFCR_GFLAG();                                            //Clear global channel interrupt flag for channel 3
-     }                                            //Clear Global Interrupt flag             
+     }                                                                          //Clear Global Interrupt flag             
 }