Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LT_SPI.h
Go to the documentation of this file.
1 //! @todo Review this document.
2 /*!
3 LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
4 
5 
6 Copyright 2018(c) Analog Devices, Inc.
7 
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12  - Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14  - Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions and the following disclaimer in
16  the documentation and/or other materials provided with the
17  distribution.
18  - Neither the name of Analog Devices, Inc. nor the names of its
19  contributors may be used to endorse or promote products derived
20  from this software without specific prior written permission.
21  - The use of this software may or may not infringe the patent rights
22  of one or more patent holders. This license does not release you
23  from the requirement that you obtain separate licenses from these
24  patent holders to use this software.
25  - Use of the software either in source or binary form, must be run
26  on or directly connected to an Analog Devices Inc. component.
27 
28 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39 
40 /*! @file
41  @ingroup LT_SPI
42  Library Header File for LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
43 */
44 
45 #ifndef LT_SPI_H
46 #define LT_SPI_H
47 
48 #include <stdint.h>
49 #include <SPI.h>
50 
51 // Uncomment the following to use functions that implement LTC SPI routines
52 
53 // //! @name SPI CLOCK DIVIDER CONSTANTS
54 // //! @{
55 // #define SPI_CLOCK_DIV4 0x00 // 4 Mhz
56 // #define SPI_CLOCK_DIV16 0x01 // 1 Mhz
57 // #define SPI_CLOCK_DIV64 0x02 // 250 khz
58 // #define SPI_CLOCK_DIV128 0x03 // 125 khz
59 // #define SPI_CLOCK_DIV2 0x04 // 8 Mhz
60 // #define SPI_CLOCK_DIV8 0x05 // 2 Mhz
61 // #define SPI_CLOCK_DIV32 0x06 // 500 khz
62 // //! @}
63 //
64 // //! @name SPI HARDWARE MODE CONSTANTS
65 // //! @{
66 // #define SPI_MODE0 0x00
67 // #define SPI_MODE1 0x04
68 // // #define SPI_MODE2 0x08
69 // #define SPI_MODE3 0x0C
70 // //! @}
71 //
72 // //! @name SPI SET MASKS
73 //! @{
74 // #define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
75 // #define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
76 // #define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
77 // //! @}
78 
79 //! Reads and sends a byte
80 //! @return void
81 void spi_transfer_byte(uint8_t cs_pin, //!< Chip select pin
82  uint8_t tx, //!< Byte to be transmitted
83  uint8_t *rx //!< Byte to be received
84  );
85 
86 //! Reads and sends a word
87 //! @return void
88 void spi_transfer_word(uint8_t cs_pin, //!< Chip select pin
89  uint16_t tx, //!< Byte to be transmitted
90  uint16_t *rx //!< Byte to be received
91  );
92 
93 //! Reads and sends a byte array
94 //! @return void
95 void spi_transfer_block(uint8_t cs_pin, //!< Chip select pin
96  uint8_t *tx, //!< Byte array to be transmitted
97  uint8_t *rx, //!< Byte array to be received
98  uint8_t length //!< Length of array
99  );
100 
101 //! Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C.
102 void quikeval_SPI_connect();
103 
104 //! Configure the SPI port for 4Mhz SCK.
105 //! This function or spi_enable() must be called
106 //! before using the other SPI routines.
107 void quikeval_SPI_init();
108 
109 //! Setup the processor for hardware SPI communication.
110 //! Must be called before using the other SPI routines.
111 //! Alternatively, call quikeval_SPI_connect(), which automatically
112 //! calls this function.
113 void spi_enable(uint8_t spi_clock_divider //!< Configures SCK frequency. Use constant defined in header file.
114  );
115 
116 //! Disable the SPI hardware port
117 void spi_disable();
118 
119 //! Write a data byte using the SPI hardware
120 void spi_write(int8_t data //!< Byte to be written to SPI port
121  );
122 
123 //! Read and write a data byte using the SPI hardware
124 //! @return the data byte read
125 int8_t spi_read(int8_t data //!< The data byte to be written
126  );
127 
128 #endif // LT_SPI_H
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
Definition: LT_SPI.cpp:98
void spi_transfer_block(uint8_t cs_pin, uint8_t *tx, uint8_t *rx, uint8_t length)
Reads and sends a byte array.
Definition: LT_SPI.cpp:125
void spi_transfer_byte(uint8_t cs_pin, uint8_t tx, uint8_t *rx)
Reads and sends a byte.
Definition: LT_SPI.cpp:87
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
Definition: LT_SPI.cpp:138
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
int8_t spi_read(int8_t data)
Read and write a data byte using the SPI hardware.
Definition: LT_SPI.cpp:189
void quikeval_SPI_init()
Configure the SPI port for 4Mhz SCK.
Definition: LT_SPI.cpp:151
void spi_write(int8_t data)
Write a data byte using the SPI hardware.
Definition: LT_SPI.cpp:176
void spi_disable()
Disable the SPI hardware port.
Definition: LT_SPI.cpp:170
void spi_enable(uint8_t spi_clock_divider)
Setup the processor for hardware SPI communication.
Definition: LT_SPI.cpp:160