1 | |
2 | |
3 | /* |
4 | * Include Files |
5 | * |
6 | */ |
7 | #if defined(MATLAB_MEX_FILE) |
8 | #include "tmwtypes.h" |
9 | #include "simstruc_types.h" |
10 | #else |
11 | #include "rtwtypes.h" |
12 | #endif |
13 | |
14 | |
15 | |
16 | /* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ |
17 | #include <math.h> |
18 | |
19 | #ifndef MATLAB_MEX_FILE |
20 | |
21 | #define Arduino 100 |
22 | #define NOP __asm__ __volatile__ ("nop\n\t") |
23 | |
24 | #include "Arduino.h" |
25 | |
26 | #include "spi.h" |
27 | #include "spi.cpp" |
28 | |
29 | const byte MAX1_CS = 24; // CS pin 24 |
30 | |
31 | // SO pin 50 Mega 2560 |
32 | // CLK pin 52 Mega 2560 |
33 | |
34 | float MAX_6675(int CS) |
35 | { |
36 | unsigned int KTemp = 0; |
37 | float Celius = 0; |
38 | digitalWrite(CS, LOW); |
39 | NOP; // delay 62.5ns on a 16MHz AtMega, 100ns erforderlich |
40 | NOP; |
41 | byte MSB = SPI.transfer(0); // höherwertiges Byte einlesen, D15 ... D8 |
42 | byte LSB = SPI.transfer(0); // niederwertiges Byte einlesen, D7 ... D0 |
43 | digitalWrite(CS, HIGH); |
44 | KTemp = MSB << 8; |
45 | KTemp = KTemp | LSB; |
46 | KTemp = KTemp >> 3; |
47 | Celius = (float) (KTemp * 0.25); |
48 | return Celius; |
49 | } |
50 | |
51 | #endif |
52 | /* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */ |
53 | #define y_width 1 |
54 | /* |
55 | * Create external references here. |
56 | * |
57 | */ |
58 | /* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */ |
59 | /* extern double func(double a); */ |
60 | /* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ |
61 | |
62 | /* |
63 | * Output functions |
64 | * |
65 | */ |
66 | extern "C" void TEMP_SPI_S_FUNCTION_Outputs_wrapper(real_T *y0, |
67 | const real_T *xD) |
68 | { |
69 | /* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ |
70 | /* This sample sets the output equal to the input |
71 | y0[0] = u0[0]; |
72 | For complex signals use: y0[0].re = u0[0].re; |
73 | y0[0].im = u0[0].im; |
74 | y1[0].re = u1[0].re; |
75 | y1[0].im = u1[0].im; |
76 | */ |
77 | |
78 | if(xD[0]==1) |
79 | { |
80 | #ifndef MATLAB_MEX_FILE |
81 | |
82 | y0[0]((MAX6675(MAX1_CS),2)); |
83 | |
84 | |
85 | #endif |
86 | } |
87 | /* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ |
88 | } |
89 | |
90 | /* |
91 | * Updates function |
92 | * |
93 | */ |
94 | extern "C" void TEMP_SPI_S_FUNCTION_Update_wrapper(real_T *y0, |
95 | real_T *xD) |
96 | { |
97 | /* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */ |
98 | /* |
99 | * Code example |
100 | * xD[0] = u0[0]; |
101 | */ |
102 | |
103 | |
104 | if (xD[0] !=1) |
105 | { |
106 | #ifndef MATLAB_MEX_FILE |
107 | |
108 | SPI.begin(); |
109 | |
110 | pinMode(53, OUTPUT); // wegen SPI Funktion notwendig |
111 | |
112 | digitalWrite(MAX1_CS, HIGH); // CS High Pegel |
113 | // digitalWrite(MAX2_CS, HIGH); |
114 | // digitalWrite(MAX3_CS, HIGH); |
115 | |
116 | pinMode(MAX1_CS, OUTPUT); // CS Pin Ausgang |
117 | // pinMode(MAX2_CS, OUTPUT); |
118 | // pinMode(MAX3_CS, OUTPUT); |
119 | |
120 | #endif |
121 | |
122 | xD[0]=1; |
123 | |
124 | } |
125 | |
126 | |
127 | /* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */ |
128 | } |
129 | |