mod_dac_max5500.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2016-17, Universidad de Almeria
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*Beginning of Auto generated code by Atmel studio */
36 #include <Arduino.h>
37 /*End of auto generated code by Atmel studio */
38 
39 #include <Wire.h>
40 #include <SPI.h>
41 
42 #include "mod_dac_max5500.h"
43 
44 #include "config.h" // Fixed pins configuration for this hardware
45 
46 /* SPI frames for the MAX5500 chip
47  16 bits
48  MSB --- LSB (MSB first)
49 |A1 A0 | C1 C0 | D11 ... D0 |
50 
51 Commands C1.C0:
52  * 0 1: Load DAC, do NOT update DAC output.
53  * 1 1: Load DAC, update ALL DAC outputs.
54 
55 - POLARITY: CPOL=0 (inactive SCK=low level)
56 - PHASE: CPHA=1 (master changes data on the falling edge of clock)
57  ==> SPI_MODE_0 (1?)
58 
59 */
60 
62 {
63  // start the SPI library:
64  SPI.begin();
67  // Set all chip outputs to 0V
69 }
70 
71 void mod_dac_max5500_send_spi_word(uint16_t tx_word)
72 {
73  // Send HiByte:
75 
76  // nCS -> 0
78  delayMicroseconds(1); // Min. 40ns: nCS->0 to SCK
79 
80  SPI.transfer16 (tx_word);
81 
83 
84  // nCS -> 1
86 
88 }
89 
90 void mod_dac_max5500_update_single_DAC(uint8_t dac_idx, uint16_t dac_value)
91 {
92  // See word format at the top of this file
93  const uint16_t tx_word =
94  (((uint16_t)dac_idx) << 14) |
95  (((uint16_t)0x03) << 12) |
96  (dac_value & 0x0fff);
97 
99 }
100 
SPIClass SPI
Definition: SPI.cpp:16
static uint16_t transfer16(uint16_t data)
Definition: SPI.h:220
void mod_dac_max5500_init()
void pinMode(uint8_t, uint8_t)
void delayMicroseconds(unsigned int us)
Definition: wiring.c:120
const int PIN_DAC_MAX5500_CS
Definition: config.h:39
#define MSBFIRST
Definition: Arduino.h:58
#define OUTPUT
Definition: Arduino.h:44
#define HIGH
Definition: Arduino.h:40
static void endTransaction(void)
Definition: SPI.h:260
static void begin()
Definition: SPI.cpp:26
void digitalWrite(uint8_t, uint8_t)
#define LOW
Definition: Arduino.h:41
static void beginTransaction(SPISettings settings)
Definition: SPI.h:178
#define SPI_MODE0
Definition: SPI.h:54
void mod_dac_max5500_send_spi_word(uint16_t tx_word)
void mod_dac_max5500_update_single_DAC(uint8_t dac_idx, uint16_t dac_value)


arduino_daq
Author(s):
autogenerated on Mon Jun 10 2019 12:46:03