summaryrefslogtreecommitdiff
path: root/SPI.h
blob: 64a492f835c0ed5c7364377c0e1863e6a8968a43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/* 
 * File: SPI.h
 * Author: Joshua Ellis Drake
 */

// This is a guard condition so that contents of this file are not included
// more than once.  
#ifndef XC_SPI_H
#define	XC_SPI_H 

#include "mcc_generated_files/mssp1_spi.h"

#define MY_BUFFER_SIZE 6 //3 Devices, each of which is 16 bit. (16/8)*3=6
   
    enum messages
    {
       OUT = 0, //Output control On or Off
       BIM,     //Sets Latch off or Auto Restart Mode
       MAPIN0,  //Mapping of IN0 to OUTx
       MAPIN1,  //Mapping of IN1 to OUTx
       INST,    //Reports Transmission Bit Errors and Reports INx pin Status
       OLDCC,   //Open Load Diagnostic Current Control
       OSM,     //Output Status Monitor | Reports open circuit conditions in OFF sate | Reports output status in the ON state.
       OLOM,    //Open Load On Monitor 
       HWCR,    //Hardware Configuration Register | HWCR.ACT Active Mode Transitions | HWCR.RST SPI Register Reset | HWCR.PAR Sets Parallel Channel Operation
       OCL,     //Output Clear Latch | Clears the error latch for a selected output
       PWMCR,   //PWM Configuration Register | HWCR_PWM.ADJ Base PWM frequency adjust | HWCR_PWM.PWM1 PWM Generator 1 Activation | HWCR_PWM.PWM0 PWM Generator 0 Activation
       PWMGC0,  //PWM_CR0.FREQ Sets internal divide by clock of PWM generator for Gen 0 | PWM_CR0.DC Sets PWM Generator 0 duty cycle
       PWMGC1,  //PWM_CR1.FREQ Sets internal divide by clock of PWM generator for Gen 1 | PWM_CR1.DC Sets PWM Generator 1 duty cycle
       PWMOC,   //Selects the active PWM generator for OUTx
       PWMMAP  //Selects one of the two PWM generators
    };

    void Message_OUT(uint8_t Ohm_150, uint8_t Ohm_68, bool testLED);
/**
  @Summary
 Enables a selected quantity of 150 ohm resistors and 68 ohm resistors.

  @Description
 In 400V mode the user can select a certain quantity of both 68 and 150 ohm resistors to be enabled,
 while in 550V mode the user can only access the 150ohm resistors. A test LED can also be enabled.

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance. System must be in 400V mode for 68 ohm resistors to be accessible.

  @Param
    150Ohm         - Number of 150 ohm resistors to enable (up to 15).
    68Ohm          - Number of 68 ohm resistors to enable (up to 5).
    testLED        - True enables the test LED.

  @Returns
    Void.

  @Example 
   Message_OUT(15, 5, false);	//Max Load with testLED turned off.
 
*/
        void Message_BIM(uint8_t outputs[3]);
/**
  @Summary
 Chooses whether an output pin will latch off in the event of an overload or restart.

  @Description
Bulb Inrush Mode bits (BIM.OUTn)
0B (default) Output latches off with overload
1B Output restarts with overload
DATA = Channel number 7 to 0 (7:0)

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[]         - An array containing the data to be written to each of the three registers.

  @Returns
    Void.

  @Example 
   Message_BIM({0xFF, 0x11, 0x00});	//All outputs of the first chip will restart with overload, two of the second chip's outputs will restart on overload,
 and all of the remaining pins will latch off with overload.
 
*/
        void Message_MAPIN0(uint8_t outputs[3]);
/**
  @Summary
 Chooses which output pins are controlled by IN0.

  @Description
Input Mapping (IN0) bits (MAPIN0.OUTn)
0B (default) No connection to input pin
1B Output is connected to the input pin
DATA = Channel number 7 to 0 (7:0)
Note ? Channel 2 has the corresponding bit set to ?1? by default

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[]         - An array containing the data to be written to each of the three registers.

  @Returns
    Void.

  @Example 
   Message_MAPIN0({0x00, 0x00, 0x00});  //All outputs of each of the three driver ICs are not connected to IN0.
 
*/

        void Message_MAPIN1(uint8_t outputs[3]);
/**
  @Summary
 Chooses which output pins are controlled by IN0.

  @Description
Input Mapping (IN1) bits (MAPIN1.OUTn)
0B (default) No connection to input pin
1B Output is connected to the input pin
DATA = Channel number 7 to 0 (7:0)
Note ? Channel 3 has the corresponding bit set to ?1? by default

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[]         - An array containing the data to be written to each of the three registers.

  @Returns
    Void.

  @Example 
   Message_MAPIN1({0x00, 0x00, 0x00});  //All outputs of each of the three driver ICs are not connected to IN1.
 
*/
        void Message_INST(void);
/**
  @Summary
 Retrieves data regarding the input pins and TER bit.

  @Description
Input Status Monitor
TER bit bit (TER) (7)
0B Previous transmission was successful
1B (default) Previous transmission failed
 * 
Inx Bit bits (INST.RES) (6:2) ? reserved, bits (INST.INn) (1:0)
0B (default) The input pin is set low
1B The input pin is set high

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    Void.

  @Returns
    Void.

  @Example 
    Message_INST(void); // :)
 
*/
        void Message_DAGIOL(uint8_t outputs[3]);
/**
  @Summary
 Open Load Diagnostic Current Control

  @Description
bits (DIAG_IOL.OUTn)
0B (default) Diagnostic current is not enabled
1B Diagnostic current is enabled
DATA = Channel number 7 to 0 (7:0)

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[]         - An array containing the channel numbers from which to write or obtain information.

  @Returns
    Void.

  @Example 
   Message_DAGIOL({0xFF, 0xFF, 0xFF});  //Obtains information from all channels of the three connected devices.
 
*/
                void Message_DAGOSM(void);
/**
  @Summary
 Output Status Monitor Bits (DIAG_OSM.OUTn)

  @Description
0B (default) Voutx is less than the Output Status Monitor Threshold Voltage 3.3 V (typ)
1B Voutx is more than the Output Status Monitor Threshold Voltage 3.3 V (typ)
DATA = Channel number 7 to 0 (7:0)

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    Void.

  @Returns
    Void.

  @Example 
    Message_DAGOSM(void);
 
*/
                void Message_DAGOLON(void);
/**
  @Summary
 Open Load On Monitor Bits (DIAG_OLON.OUTn)

  @Description
0B (default) Normal operation or diagnostic performed with channel off
1B Open load On detected
DATA = Channel number 7 to 0 (7:0)

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    Void.

  @Returns
    Void.

  @Example 
    Message_DAGOLON(void);
 
*/
                void Message_DAGOLONEN(uint8_t outputs[3]);
/**
  @Summary
 Open Load On Diagnostic Control

  @Description
bits (7:4) ? reserved,
bits 1000B , 1001B , 1011B , 1100B , 1101B , 1100B ? reserved
bits (DIAG_OLONEN.MUX) (3:0)
0000B Open Load ON active channel 0
0001B Open Load ON active channel 1
0010B Open Load ON active channel 2
0011B Open Load ON active channel 3
0100B Open Load ON active channel 4
0101B Open Load ON active channel 5
0110B Open Load ON active channel 6
0111B Open Load ON active channel 7
1010B Open Load ON Diagnostic Loop Start
1111B (default) Open Load ON not active

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - An array containing the status of the specified channel of each of the three ICs.

  @Returns
    Void.

  @Example 
    Message_DAGOLONEN({0b00000000, 0xFF, 0xFF}); //Open Load ON active on channel 0 of the first IC.
 
*/     
                void Message_HWCR(uint8_t outputs[3]);
/**
  @Summary
 Hardware Configuration Register Bits

  @Description
Active Mode bits (HWCR.ACT) (7)
0B (default) Normal operation
or device leaves Active Mode
1B Device enters Active Mode
 * 
SPI Register Reset bits (HWCR.RST) (6)
0B (default) Normal operation
1B Reset command executed
ERRn bits are not cleared by a reset command for safety reasons
 * 
Channels Operating in Parallel bits (HWCR.PAR) (3:0)
0B (default) Normal operation
1B Two neighboring channels have overload and overtemperature
synchronized. See section ?Outputs in Parallel? for output combinations

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - An array containing the Active Mode, SPI Register, and "Channels Operating in Parallel" bits for each device.

  @Returns
    Void.

  @Example 
   Message_DAGOLONEN({0b11xx0000, 0b00xx0000, 0b00xx0000}); //Device 1 enters active mode, resets SPI operation, and maintains normal latch operation.
 
*/ 
                void Message_HWCROCL(uint8_t outputs[3]);
/**
  @Summary
 Output Latch (ERRn) Clear bits (HWCR_OCL.OUTn)

  @Description
0B (default) Normal operation
1B Clear the error latch for the selected output
The HWCR_OCL.OUTn bit is set back to ?0? internally after de?latching the
channel
DATA = 7 to 0 (7:0)

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - An array containing bits corresponding to the latch error reset of each channel.

  @Returns
    Void.

  @Example 
   Message_DAGOLONEN({0xFF, 0xFF, 0xFF}); //Reset Latch Errors are reset.
 
*/ 
                void Message_HWCRPWM(uint8_t outputs[3]);
/**
  @Summary
 Hardware Clear for all PWM registers. 

  @Description
PWM Configuration Register (HWCR_PWM.RES) (3:2) (reserved)
PWM Adjustment bits (HWCR_PWM.ADJ) (7:4)
HWCR_PWM.ADJ Bit
Absolute delta for fINT Relative delta between steps
0000B (reserved)
0001B Base Frequency ?35.0% ?35.0% (66.3 kHz[typ])
0010B Base Frequency ?30.0%
0011B Base Frequency ?25.0%
0100B Base Frequency ?20.0%
0101B Base Frequency ?15.0%
0110B Base Frequency ?10.0%
0111B Base Frequency ?5.0%
1000B Base Frequency fINT (102 kHz [typ])(default)
1001B Base Frequency +5.0%
1010B Base Frequency +10.0%
1011B Base Frequency +15.0%
1100B Base Frequency +20.0%
1101B Base Frequency +25.0%
1110B Base Frequency +30.0%
1111B Base Frequency +35.0% +35.0 (137.7 kHz[typ])

PWM1 Active bits (HWCR_PWM.PWM1) (1)
0B (default) PWM Generator 1 not active
1B PWM Generator 1 active
PWM0 Active (HWCR_PWM.PWM0) (0)
0B (default) PWM Generator 0 not active
1B PWM Generator 0 active

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - An array containing bits corresponding to the PWM Hardware.

  @Returns
    Void.

  @Example 
   Message_HWCRPWM({0b1000xx00, 0b1000xx00, 0b1000xx00}); //Set all three ICs to typical base frequency and disable both PWM Generators.
 
*/ 
                void Message_PWMCR0(uint16_t outputs[3]);
/**
  @Summary
 PWM Generator 0 Configuration 

  @Description
CR0 Frequency (PWM_CR0.FREQ) (9:8)
00B Internal clock divided by 1024 (100 Hz) (default)
01B Internal clock divided by 512 (200 Hz)
10B Internal clock divided by 256 (400 Hz)
11B 100% Duty Cycle.
CR0 generator on/off control (PWM_CRO.DC) (7:0)
00000000B PWM generator is off. (default)
11111111B PWM generator is On (99.61% DC).

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - A 16 bit array containing bits which adjust the PWM0 frequency as well as enable/disable the generator itself.

  @Returns
    Void.

  @Example 
   Message_PWMCR0({0xX000, 0xX000, 0xX000}); //Set the PWM frequency to be 100Hz and disable PWM0.
 
*/ 
                void Message_PWMCR1(uint16_t outputs[3]);
/**
  @Summary
 PWM Generator 1 Configuration 

  @Description
CR0 Frequency (PWM_CR1.FREQ) (9:8)
00B Internal clock divided by 1024 (100 Hz) (default)
01B Internal clock divided by 512 (200 Hz)
10B Internal clock divided by 256 (400 Hz)
11B 100% Duty Cycle.
CR1 generator on/off control (PWM_CR1.DC) (7:0)
00000000B PWM generator is off. (default)
11111111B PWM generator is On (99.61% DC).

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - A 16 bit array containing bits which adjust the PWM1 frequency as well as enable/disable the generator itself.

  @Returns
    Void.

  @Example 
   Message_PWMCR1({0xX000, 0xX000, 0xX000}); //Set the PWM frequency to be 100Hz and disable PWM1.
 
*/ 
                void Message_PWMOUT(uint8_t outputs[3]);
/**
  @Summary
 Select which outputs are connected to any PWM generator. 

  @Description
PWM Generator Output Control (PWM_OUT.OUTn)
0B (default) The selected output is not driven by one of the two PWM generators
1B The selected output is connected to a PWM generator
DATA = Channel number 0 to 7

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - An array containing bits which determine which, if any, outputs are connected to the PWM generators.

  @Returns
    Void.

  @Example 
   Message_PWMOUT({0x00, 0x00, 0x00}); //All outputs are not connected to any of the PWM generators.
 
*/ 
                void Message_PWMMAP(uint8_t outputs[3]);
/**
  @Summary
 Select which PWM generator corresponds to which output. 

  @Description
PWM Generator Output Mapping (PWM_MAP.OUTn)
0B (default) The selected output is connected to PWM Generator 0
1B The selected output is connected to PWM Generator 1
DATA = Channel number 0 to 7
Works in conjunction with PWM_OUT

  @Preconditions
    The MSSP1_SPI_Initialize routine must have been called for the specified
    MSSP1_SPI driver instance.

  @Param
    outputs[] - An array containing bits which map the PWM generators to specific outputs.

  @Returns
    Void.

  @Example 
   Message_PWMMAP({0x00, 0x00, 0x00}); //All outputs are connected to PWM0.
 
*/ 
                
                
#endif	/* XC_SPI_H */