2 * Copyright (c) 2014, Texas Instruments Incorporated
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
9 * * Redistributions of source code must retain the above copyright
\r
10 * notice, this list of conditions and the following disclaimer.
\r
12 * * Redistributions in binary form must reproduce the above copyright
\r
13 * notice, this list of conditions and the following disclaimer in the
\r
14 * documentation and/or other materials provided with the distribution.
\r
16 * * Neither the name of Texas Instruments Incorporated nor the names of
\r
17 * its contributors may be used to endorse or promote products derived
\r
18 * from this software without specific prior written permission.
\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
\r
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
\r
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
\r
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
\r
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
\r
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 //*****************************************************************************
\r
34 // eusci_a_spi.h - Driver for the EUSCI_A_SPI Module.
\r
36 //*****************************************************************************
\r
38 #ifndef __MSP430WARE_EUSCI_A_SPI_H__
\r
39 #define __MSP430WARE_EUSCI_A_SPI_H__
\r
41 #include "inc/hw_memmap.h"
\r
43 #ifdef __MSP430_HAS_EUSCI_Ax__
\r
45 //*****************************************************************************
\r
47 // If building with a C++ compiler, make all of the definitions in this header
\r
48 // have a C binding.
\r
50 //*****************************************************************************
\r
56 #include "inc/hw_regaccess.h"
\r
57 //*****************************************************************************
\r
59 //! \brief Used in the EUSCI_A_SPI_changeMasterClock() function as the param
\r
62 //*****************************************************************************
\r
63 typedef struct EUSCI_A_SPI_changeMasterClockParam
\r
65 //! Is the frequency of the selected clock source
\r
66 uint32_t clockSourceFrequency;
\r
67 //! Is the desired clock rate for SPI communication
\r
68 uint32_t desiredSpiClock;
\r
69 } EUSCI_A_SPI_changeMasterClockParam;
\r
71 //*****************************************************************************
\r
73 //! \brief Used in the EUSCI_A_SPI_initSlave() function as the param parameter.
\r
75 //*****************************************************************************
\r
76 typedef struct EUSCI_A_SPI_initSlaveParam
\r
78 //! Controls the direction of the receive and transmit shift register.
\r
79 //! \n Valid values are:
\r
80 //! - \b EUSCI_A_SPI_MSB_FIRST
\r
81 //! - \b EUSCI_A_SPI_LSB_FIRST [Default]
\r
83 //! Is clock phase select.
\r
84 //! \n Valid values are:
\r
85 //! - \b EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
\r
86 //! - \b EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
\r
87 uint16_t clockPhase;
\r
88 //! Is clock polarity select
\r
89 //! \n Valid values are:
\r
90 //! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
\r
91 //! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
\r
92 uint16_t clockPolarity;
\r
93 //! Is SPI mode select
\r
94 //! \n Valid values are:
\r
95 //! - \b EUSCI_A_SPI_3PIN
\r
96 //! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_HIGH
\r
97 //! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_LOW
\r
99 } EUSCI_A_SPI_initSlaveParam;
\r
101 //*****************************************************************************
\r
103 //! \brief Used in the EUSCI_A_SPI_initMaster() function as the param
\r
106 //*****************************************************************************
\r
107 typedef struct EUSCI_A_SPI_initMasterParam
\r
109 //! Selects Clock source.
\r
110 //! \n Valid values are:
\r
111 //! - \b EUSCI_A_SPI_CLOCKSOURCE_ACLK
\r
112 //! - \b EUSCI_A_SPI_CLOCKSOURCE_SMCLK
\r
113 uint8_t selectClockSource;
\r
114 //! Is the frequency of the selected clock source
\r
115 uint32_t clockSourceFrequency;
\r
116 //! Is the desired clock rate for SPI communication
\r
117 uint32_t desiredSpiClock;
\r
118 //! Controls the direction of the receive and transmit shift register.
\r
119 //! \n Valid values are:
\r
120 //! - \b EUSCI_A_SPI_MSB_FIRST
\r
121 //! - \b EUSCI_A_SPI_LSB_FIRST [Default]
\r
123 //! Is clock phase select.
\r
124 //! \n Valid values are:
\r
125 //! - \b EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
\r
126 //! - \b EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
\r
127 uint16_t clockPhase;
\r
128 //! Is clock polarity select
\r
129 //! \n Valid values are:
\r
130 //! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
\r
131 //! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
\r
132 uint16_t clockPolarity;
\r
133 //! Is SPI mode select
\r
134 //! \n Valid values are:
\r
135 //! - \b EUSCI_A_SPI_3PIN
\r
136 //! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_HIGH
\r
137 //! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_LOW
\r
139 } EUSCI_A_SPI_initMasterParam;
\r
141 //*****************************************************************************
\r
143 // The following are values that can be passed to the clockPhase parameter for
\r
144 // functions: EUSCI_A_SPI_changeClockPhasePolarity(); the param parameter for
\r
145 // functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave().
\r
147 //*****************************************************************************
\r
148 #define EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT 0x00
\r
149 #define EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT UCCKPH
\r
151 //*****************************************************************************
\r
153 // The following are values that can be passed to the param parameter for
\r
154 // functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave().
\r
156 //*****************************************************************************
\r
157 #define EUSCI_A_SPI_MSB_FIRST UCMSB
\r
158 #define EUSCI_A_SPI_LSB_FIRST 0x00
\r
160 //*****************************************************************************
\r
162 // The following are values that can be passed to the param parameter for
\r
163 // functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave(); the
\r
164 // clockPolarity parameter for functions:
\r
165 // EUSCI_A_SPI_changeClockPhasePolarity().
\r
167 //*****************************************************************************
\r
168 #define EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH UCCKPL
\r
169 #define EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW 0x00
\r
171 //*****************************************************************************
\r
173 // The following are values that can be passed to the param parameter for
\r
174 // functions: EUSCI_A_SPI_initMaster().
\r
176 //*****************************************************************************
\r
177 #define EUSCI_A_SPI_CLOCKSOURCE_ACLK UCSSEL__ACLK
\r
178 #define EUSCI_A_SPI_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
\r
180 //*****************************************************************************
\r
182 // The following are values that can be passed to the param parameter for
\r
183 // functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave().
\r
185 //*****************************************************************************
\r
186 #define EUSCI_A_SPI_3PIN UCMODE_0
\r
187 #define EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_HIGH UCMODE_1
\r
188 #define EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_LOW UCMODE_2
\r
190 //*****************************************************************************
\r
192 // The following are values that can be passed to the select4PinFunctionality
\r
193 // parameter for functions: EUSCI_A_SPI_select4PinFunctionality().
\r
195 //*****************************************************************************
\r
196 #define EUSCI_A_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS 0x00
\r
197 #define EUSCI_A_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE UCSTEM
\r
199 //*****************************************************************************
\r
201 // The following are values that can be passed to the mask parameter for
\r
202 // functions: EUSCI_A_SPI_enableInterrupt(), EUSCI_A_SPI_disableInterrupt(),
\r
203 // EUSCI_A_SPI_getInterruptStatus(), and EUSCI_A_SPI_clearInterrupt() as well
\r
204 // as returned by the EUSCI_A_SPI_getInterruptStatus() function.
\r
206 //*****************************************************************************
\r
207 #define EUSCI_A_SPI_TRANSMIT_INTERRUPT UCTXIE
\r
208 #define EUSCI_A_SPI_RECEIVE_INTERRUPT UCRXIE
\r
210 //*****************************************************************************
\r
212 // The following are values that can be passed toThe following are values that
\r
213 // can be returned by the EUSCI_A_SPI_isBusy() function.
\r
215 //*****************************************************************************
\r
216 #define EUSCI_A_SPI_BUSY UCBUSY
\r
217 #define EUSCI_A_SPI_NOT_BUSY 0x00
\r
219 //*****************************************************************************
\r
221 // Prototypes for the APIs.
\r
223 //*****************************************************************************
\r
225 //*****************************************************************************
\r
227 //! \brief Initializes the SPI Master block.
\r
229 //! Upon successful initialization of the SPI master block, this function will
\r
230 //! have set the bus speed for the master, but the SPI Master block still
\r
231 //! remains disabled and must be enabled with EUSCI_A_SPI_enable()
\r
233 //! \param baseAddress is the base address of the EUSCI_A_SPI Master module.
\r
234 //! \param param is the pointer to struct for master initialization.
\r
236 //! Modified bits are \b UCCKPH, \b UCCKPL, \b UC7BIT, \b UCMSB, \b UCSSELx and
\r
237 //! \b UCSWRST of \b UCAxCTLW0 register.
\r
239 //! \return STATUS_SUCCESS
\r
241 //*****************************************************************************
\r
242 extern void EUSCI_A_SPI_initMaster(uint16_t baseAddress,
\r
243 EUSCI_A_SPI_initMasterParam *param);
\r
245 //*****************************************************************************
\r
247 //! \brief Selects 4Pin Functionality
\r
249 //! This function should be invoked only in 4-wire mode. Invoking this function
\r
250 //! has no effect in 3-wire mode.
\r
252 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
253 //! \param select4PinFunctionality selects 4 pin functionality
\r
254 //! Valid values are:
\r
255 //! - \b EUSCI_A_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS
\r
256 //! - \b EUSCI_A_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE
\r
258 //! Modified bits are \b UCSTEM of \b UCAxCTLW0 register.
\r
262 //*****************************************************************************
\r
263 extern void EUSCI_A_SPI_select4PinFunctionality(uint16_t baseAddress,
\r
264 uint8_t select4PinFunctionality);
\r
266 //*****************************************************************************
\r
268 //! \brief Initializes the SPI Master clock. At the end of this function call,
\r
269 //! SPI module is left enabled.
\r
271 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
272 //! \param param is the pointer to struct for master clock setting.
\r
274 //! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
\r
278 //*****************************************************************************
\r
279 extern void EUSCI_A_SPI_changeMasterClock(uint16_t baseAddress,
\r
280 EUSCI_A_SPI_changeMasterClockParam *param);
\r
282 //*****************************************************************************
\r
284 //! \brief Initializes the SPI Slave block.
\r
286 //! Upon successful initialization of the SPI slave block, this function will
\r
287 //! have initialized the slave block, but the SPI Slave block still remains
\r
288 //! disabled and must be enabled with EUSCI_A_SPI_enable()
\r
290 //! \param baseAddress is the base address of the EUSCI_A_SPI Slave module.
\r
291 //! \param param is the pointer to struct for slave initialization.
\r
293 //! Modified bits are \b UCMSB, \b UCMST, \b UC7BIT, \b UCCKPL, \b UCCKPH, \b
\r
294 //! UCMODE and \b UCSWRST of \b UCAxCTLW0 register.
\r
296 //! \return STATUS_SUCCESS
\r
298 //*****************************************************************************
\r
299 extern void EUSCI_A_SPI_initSlave(uint16_t baseAddress,
\r
300 EUSCI_A_SPI_initSlaveParam *param);
\r
302 //*****************************************************************************
\r
304 //! \brief Changes the SPI clock phase and polarity. At the end of this
\r
305 //! function call, SPI module is left enabled.
\r
307 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
308 //! \param clockPhase is clock phase select.
\r
309 //! Valid values are:
\r
310 //! - \b EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
\r
312 //! - \b EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
\r
313 //! \param clockPolarity is clock polarity select
\r
314 //! Valid values are:
\r
315 //! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
\r
316 //! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
\r
318 //! Modified bits are \b UCCKPL, \b UCCKPH and \b UCSWRST of \b UCAxCTLW0
\r
323 //*****************************************************************************
\r
324 extern void EUSCI_A_SPI_changeClockPhasePolarity(uint16_t baseAddress,
\r
325 uint16_t clockPhase,
\r
326 uint16_t clockPolarity);
\r
328 //*****************************************************************************
\r
330 //! \brief Transmits a byte from the SPI Module.
\r
332 //! This function will place the supplied data into SPI transmit data register
\r
333 //! to start transmission.
\r
335 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
336 //! \param transmitData data to be transmitted from the SPI module
\r
340 //*****************************************************************************
\r
341 extern void EUSCI_A_SPI_transmitData(uint16_t baseAddress,
\r
342 uint8_t transmitData);
\r
344 //*****************************************************************************
\r
346 //! \brief Receives a byte that has been sent to the SPI Module.
\r
348 //! This function reads a byte of data from the SPI receive data Register.
\r
350 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
352 //! \return Returns the byte received from by the SPI module, cast as an
\r
355 //*****************************************************************************
\r
356 extern uint8_t EUSCI_A_SPI_receiveData(uint16_t baseAddress);
\r
358 //*****************************************************************************
\r
360 //! \brief Enables individual SPI interrupt sources.
\r
362 //! Enables the indicated SPI interrupt sources. Only the sources that are
\r
363 //! enabled can be reflected to the processor interrupt; disabled sources have
\r
364 //! no effect on the processor. Does not clear interrupt flags.
\r
366 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
367 //! \param mask is the bit mask of the interrupt sources to be enabled.
\r
368 //! Mask value is the logical OR of any of the following:
\r
369 //! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
\r
370 //! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
\r
372 //! Modified bits of \b UCAxIFG register and bits of \b UCAxIE register.
\r
376 //*****************************************************************************
\r
377 extern void EUSCI_A_SPI_enableInterrupt(uint16_t baseAddress,
\r
380 //*****************************************************************************
\r
382 //! \brief Disables individual SPI interrupt sources.
\r
384 //! Disables the indicated SPI interrupt sources. Only the sources that are
\r
385 //! enabled can be reflected to the processor interrupt; disabled sources have
\r
386 //! no effect on the processor.
\r
388 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
389 //! \param mask is the bit mask of the interrupt sources to be disabled.
\r
390 //! Mask value is the logical OR of any of the following:
\r
391 //! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
\r
392 //! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
\r
394 //! Modified bits of \b UCAxIE register.
\r
398 //*****************************************************************************
\r
399 extern void EUSCI_A_SPI_disableInterrupt(uint16_t baseAddress,
\r
402 //*****************************************************************************
\r
404 //! \brief Gets the current SPI interrupt status.
\r
406 //! This returns the interrupt status for the SPI module based on which flag is
\r
409 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
410 //! \param mask is the masked interrupt flag status to be returned.
\r
411 //! Mask value is the logical OR of any of the following:
\r
412 //! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
\r
413 //! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
\r
415 //! \return Logical OR of any of the following:
\r
416 //! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
\r
417 //! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
\r
418 //! \n indicating the status of the masked interrupts
\r
420 //*****************************************************************************
\r
421 extern uint8_t EUSCI_A_SPI_getInterruptStatus(uint16_t baseAddress,
\r
424 //*****************************************************************************
\r
426 //! \brief Clears the selected SPI interrupt status flag.
\r
428 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
429 //! \param mask is the masked interrupt flag to be cleared.
\r
430 //! Mask value is the logical OR of any of the following:
\r
431 //! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
\r
432 //! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
\r
434 //! Modified bits of \b UCAxIFG register.
\r
438 //*****************************************************************************
\r
439 extern void EUSCI_A_SPI_clearInterrupt(uint16_t baseAddress,
\r
442 //*****************************************************************************
\r
444 //! \brief Enables the SPI block.
\r
446 //! This will enable operation of the SPI block.
\r
448 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
450 //! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
\r
454 //*****************************************************************************
\r
455 extern void EUSCI_A_SPI_enable(uint16_t baseAddress);
\r
457 //*****************************************************************************
\r
459 //! \brief Disables the SPI block.
\r
461 //! This will disable operation of the SPI block.
\r
463 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
465 //! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
\r
469 //*****************************************************************************
\r
470 extern void EUSCI_A_SPI_disable(uint16_t baseAddress);
\r
472 //*****************************************************************************
\r
474 //! \brief Returns the address of the RX Buffer of the SPI for the DMA module.
\r
476 //! Returns the address of the SPI RX Buffer. This can be used in conjunction
\r
477 //! with the DMA to store the received data directly to memory.
\r
479 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
481 //! \return the address of the RX Buffer
\r
483 //*****************************************************************************
\r
484 extern uint32_t EUSCI_A_SPI_getReceiveBufferAddress(uint16_t baseAddress);
\r
486 //*****************************************************************************
\r
488 //! \brief Returns the address of the TX Buffer of the SPI for the DMA module.
\r
490 //! Returns the address of the SPI TX Buffer. This can be used in conjunction
\r
491 //! with the DMA to obtain transmitted data directly from memory.
\r
493 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
495 //! \return the address of the TX Buffer
\r
497 //*****************************************************************************
\r
498 extern uint32_t EUSCI_A_SPI_getTransmitBufferAddress(uint16_t baseAddress);
\r
500 //*****************************************************************************
\r
502 //! \brief Indicates whether or not the SPI bus is busy.
\r
504 //! This function returns an indication of whether or not the SPI bus is
\r
505 //! busy.This function checks the status of the bus via UCBBUSY bit
\r
507 //! \param baseAddress is the base address of the EUSCI_A_SPI module.
\r
509 //! \return One of the following:
\r
510 //! - \b EUSCI_A_SPI_BUSY
\r
511 //! - \b EUSCI_A_SPI_NOT_BUSY
\r
512 //! \n indicating if the EUSCI_A_SPI is busy
\r
514 //*****************************************************************************
\r
515 extern uint16_t EUSCI_A_SPI_isBusy(uint16_t baseAddress);
\r
517 //*****************************************************************************
\r
519 // Mark the end of the C bindings section for C++ compilers.
\r
521 //*****************************************************************************
\r
527 #endif // __MSP430WARE_EUSCI_A_SPI_H__
\r