Testing code for just temperature test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
vickygough
Date:
Mon Sep 04 10:15:45 2017 +0000
Commit message:
initial tempread test;

Changed in this revision

PINNAMES_mbed.h Show annotated file Show diff for this revision Revisions of this file
PROTOTYPES.h Show annotated file Show diff for this revision Revisions of this file
SPICOMMANDS.h Show annotated file Show diff for this revision Revisions of this file
TABLES.h Show annotated file Show diff for this revision Revisions of this file
main_temptest.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PINNAMES_mbed.h	Mon Sep 04 10:15:45 2017 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+
+// SPI pins
+#define MOSI p5
+#define MISO p6
+#define SCK p7
+
+SPI spi(p5, p6, p7); // mosi, miso, sclk
+DigitalOut chipSelect(p8);
+
+// CAN pins
+// FILL THIS IN.
+
+//CAN can(CANrd, CANtd);
+
+// LDRs
+AnalogIn LDR_SENSE1(p17);
+AnalogIn LDR_SENSE2(p18);
+
+// Switches
+DigitalIn TRACKING_SW(p21); 
+DigitalIn CANOPY_SW(p22); // Switch somewhere on array lifting mechanism. HIGH = 
+DigitalIn MODE_SW1(p23);
+DigitalIn MODE_SW2(p24);
+AnalogIn MANUAL_POSITION(p20);
+
+// Other
+DigitalOut StatusLED(LED1);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PROTOTYPES.h	Mon Sep 04 10:15:45 2017 +0000
@@ -0,0 +1,16 @@
+typedef enum OpModesym {Tracking_Off, Flat, Manual, Full, Error} OpModesym;
+typedef enum Errorsym {False,Switch_Error} Errorsym;
+
+
+OpModesym readswitches();
+void checkLDR(float &LDR1,float &LDR2);
+void checkMPPT(float *MMPT);
+bool shouldmove(float *MMPT,float LDR1,float LDR2,double Upperlimit,double Lowelimit,uint8_t *panel_locations);
+void getlocations(double Upperlimit, double Lowerlimit,uint8_t *panel_locations);
+void sendlocations(uint8_t *panel_locations);
+uint8_t toEncoder(double angle);
+void interruptHandler();
+void spi_send(uint8_t write_buf [8],uint8_t decoded_buf[7]);
+uint8_t GetSum();
+
+float byteToFloat(uint8_t a, uint8_t b, uint8_t c, uint8_t d); 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SPICOMMANDS.h	Mon Sep 04 10:15:45 2017 +0000
@@ -0,0 +1,26 @@
+//Slave list 
+
+#define ERROR 0x00
+
+// slave addresses
+#define MEGA1 0x01
+#define SPLITMEGA_FR 0x02 //split mega front right
+#define SPLITMEGA_FL 0x03
+#define MEGA4 0x04
+#define MEGA5 0x05
+
+// each mega needs its own number they must all be different.
+
+
+
+// NOTE:    This must match the command list in the MEGA headder. 
+
+
+//define commands
+#define do_nothing          0x00 // sent by mbed to just read whats currently in buffer on arduino. no action from arduino required
+#define read_position_only  0x01
+#define request_temps       0x02
+#define read_onetemp_only   0x03
+#define move_motor_position 0x04
+#define move_motor_manual   0x05
+#define set_zero            0x06 //calibration
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TABLES.h	Mon Sep 04 10:15:45 2017 +0000
@@ -0,0 +1,31 @@
+// Tables for positions and temperature measurements
+
+/****** POSITIONS *******/
+int numberOfBrackets = 5;
+
+// these need to be repopulated by calibration
+//CLOCKWISE, COUNTERCLOCKWISE
+int positionsCanopyOn[5][2] = {
+    {110, 18}, // module 1
+    {100, 64}, // split module 2
+    {64, 28}, //split module 3
+    {80, 48}, // module 4
+    {70, 58} // module 5
+};
+
+// these need to be repopulated by calibration
+int positionsCanopyOff[5][2] = {
+    {110, 18},
+    {110, 18},
+    {110, 18},
+    {110, 18},
+    {110, 18} 
+};
+/************************/
+
+/******TEMPERATURES *******/
+int probeNumberByModule[5] = {4,4,4,4,8}; // last module is larger
+int maxProbesOnModule = 8;
+float temperatureStoreFloats[5][8] = {0};
+/************************/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_temptest.cpp	Mon Sep 04 10:15:45 2017 +0000
@@ -0,0 +1,129 @@
+#include "mbed.h"
+#include "PINNAMES_mbed.h"
+#include "SPICOMMANDS.h"
+#include "PROTOTYPES.h"
+#include "TABLES.h"
+
+const int spiBitrate=250000;
+bool arduino_task_done = false;
+uint8_t write_buf [8];
+
+int main() {
+        
+    // initialise write_buf
+    write_buf[0] = 0xAA; //message start
+    write_buf[1] = MEGA1; //chip_ID
+    write_buf[2] = do_nothing; //command
+    write_buf[3] = 0x00;
+    write_buf[4] = 0x00;
+    write_buf[5] = 0x00; //temp device number
+    write_buf[6] = 0x00;
+    write_buf[7] = GetSum();
+    
+    char read_buf [8];
+    for (int i = 0; i < 8; ++i) {
+        read_buf[i] = 0;
+    }
+    
+    while(1) {
+        spi.format(8,3);
+        spi.frequency(spiBitrate);
+        
+        // REQUEST TEMPERATURES
+        write_buf[2] = request_temps;
+        write_buf[7] = GetSum();
+        
+        chipSelect = 0;
+        wait_us(70);
+        for (int i = 0; i < 8; ++i) {
+            spi.write(write_buf[i]);
+        }
+        
+        
+        while (!arduino_task_done) {
+            wait_us(10);
+            for (int i = 0; i < 8; ++i) {
+            read_buf[i] = (uint8_t) spi.write(0xFA);
+            }
+            if (read_buf[6] == 0x01) {
+                //task done
+                arduino_task_done = true;    
+            }
+        } 
+        chipSelect = 1;
+        wait_us(10);
+        
+        
+        //READ PROBE 1
+        write_buf[2] = read_onetemp_only;
+        write_buf[5] = 0x01;
+        write_buf[7] = GetSum();
+        chipSelect = 0;
+        wait_us(70);
+        for (int i = 0; i < 8; ++i) {
+            spi.write(write_buf[i]);
+        }
+        
+        while (!arduino_task_done) {
+            wait_us(10);
+            for (int i = 0; i < 8; ++i) {
+            read_buf[i] = (uint8_t) spi.write(0xFA);
+            }
+            if (read_buf[6] == 0x01) {
+                //task done
+                arduino_task_done = true;    
+            }
+        } 
+        chipSelect = 1;
+        wait_us(10);
+        
+        printf("Response from Arduino is ");
+        for (int i = 0; i < 8; ++i) {
+            printf("%d ", read_buf[i]);
+            //if (read_buf[i] == 32) printf("this is 32");
+            read_buf[i] = 0x00;
+        }
+        printf("\r\n");
+        
+        
+        //READ PROBE 2
+        write_buf[2] = read_onetemp_only;
+        write_buf[5] = 0x02;
+        write_buf[7] = GetSum();
+        chipSelect = 0;
+        wait_us(70);
+        for (int i = 0; i < 8; ++i) {
+            spi.write(write_buf[i]);
+        }
+        
+        while (!arduino_task_done) {
+            wait_us(10);
+            for (int i = 0; i < 8; ++i) {
+            read_buf[i] = (uint8_t) spi.write(0xFA);
+            }
+            if (read_buf[6] == 0x01) {
+                //task done
+                arduino_task_done = true;    
+            }
+        } 
+        
+        chipSelect = 1;
+        wait_us(10);
+        
+        printf("Response from Arduino is ");
+        for (int i = 0; i < 8; ++i) {
+            printf("%d ", read_buf[i]);
+            //if (read_buf[i] == 32) printf("this is 32");
+            read_buf[i] = 0x00;
+        }
+        printf("\r\n");
+        
+        
+        wait(1);
+    }
+
+}
+uint8_t GetSum() {
+    uint8_t sum = write_buf[0] + write_buf[1] + write_buf[2] + write_buf[3] + write_buf[4] + write_buf[5];
+    return sum;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Sep 04 10:15:45 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/64910690c574
\ No newline at end of file