MSP430 DriverLib for MSP430F5xx_6xx Devices  2.80.00.01
 All Data Structures Functions Variables Modules Pages
usci_a_spi.h
1 //*****************************************************************************
2 //
3 // usci_a_spi.h - Driver for the USCI_A_SPI Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_USCI_A_SPI_H__
8 #define __MSP430WARE_USCI_A_SPI_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_USCI_Ax__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include "inc/hw_memmap.h"
26 //*****************************************************************************
27 //
28 //! \brief Used in the USCI_A_SPI_initMaster() function as the param parameter.
29 //
30 //*****************************************************************************
32  //! Selects Clock source.
33  //! \n Valid values are:
34  //! - \b USCI_A_SPI_CLOCKSOURCE_ACLK
35  //! - \b USCI_A_SPI_CLOCKSOURCE_SMCLK
37  //! Is the frequency of the selected clock source
39  //! Is the desired clock rate for SPI communication
40  uint32_t desiredSpiClock;
41  //! Controls the direction of the receive and transmit shift register.
42  //! \n Valid values are:
43  //! - \b USCI_A_SPI_MSB_FIRST
44  //! - \b USCI_A_SPI_LSB_FIRST [Default]
45  uint8_t msbFirst;
46  //! Is clock phase select.
47  //! \n Valid values are:
48  //! - \b USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
49  //! - \b USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
50  uint8_t clockPhase;
51  //! \n Valid values are:
52  //! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
53  //! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
54  uint8_t clockPolarity;
56 
57 //*****************************************************************************
58 //
59 //! \brief Used in the USCI_A_SPI_changeMasterClock() function as the param
60 //! parameter.
61 //
62 //*****************************************************************************
64  //! Is the frequency of the selected clock source
66  //! Is the desired clock rate for SPI communication
67  uint32_t desiredSpiClock;
69 
70 
71 //*****************************************************************************
72 //
73 // The following are values that can be passed to the clockPhase parameter for
74 // functions: USCI_A_SPI_initSlave(), and
75 // USCI_A_SPI_changeClockPhasePolarity(); the param parameter for functions:
76 // USCI_A_SPI_initMaster().
77 //
78 //*****************************************************************************
79 #define USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT 0x00
80 #define USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT UCCKPH
81 
82 //*****************************************************************************
83 //
84 // The following are values that can be passed to the msbFirst parameter for
85 // functions: USCI_A_SPI_initSlave(); the param parameter for functions:
86 // USCI_A_SPI_initMaster().
87 //
88 //*****************************************************************************
89 #define USCI_A_SPI_MSB_FIRST UCMSB
90 #define USCI_A_SPI_LSB_FIRST 0x00
91 
92 //*****************************************************************************
93 //
94 // The following are values that can be passed to the param parameter for
95 // functions: USCI_A_SPI_initMaster(); the clockPolarity parameter for
96 // functions: USCI_A_SPI_initSlave(), and
97 // USCI_A_SPI_changeClockPhasePolarity().
98 //
99 //*****************************************************************************
100 #define USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH UCCKPL
101 #define USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW 0x00
102 
103 //*****************************************************************************
104 //
105 // The following are values that can be passed to the param parameter for
106 // functions: USCI_A_SPI_initMaster().
107 //
108 //*****************************************************************************
109 #define USCI_A_SPI_CLOCKSOURCE_ACLK UCSSEL__ACLK
110 #define USCI_A_SPI_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
111 
112 //*****************************************************************************
113 //
114 // The following are values that can be passed to the mask parameter for
115 // functions: USCI_A_SPI_enableInterrupt(), USCI_A_SPI_disableInterrupt(),
116 // USCI_A_SPI_getInterruptStatus(), and USCI_A_SPI_clearInterrupt() as well as
117 // returned by the USCI_A_SPI_getInterruptStatus() function.
118 //
119 //*****************************************************************************
120 #define USCI_A_SPI_TRANSMIT_INTERRUPT UCTXIE
121 #define USCI_A_SPI_RECEIVE_INTERRUPT UCRXIE
122 
123 //*****************************************************************************
124 //
125 // The following are values that can be passed toThe following are values that
126 // can be returned by the USCI_A_SPI_isBusy() function.
127 //
128 //*****************************************************************************
129 #define USCI_A_SPI_BUSY UCBUSY
130 #define USCI_A_SPI_NOT_BUSY 0x00
131 
132 //*****************************************************************************
133 //
134 // Prototypes for the APIs.
135 //
136 //*****************************************************************************
137 
138 //*****************************************************************************
139 //
140 //! \brief Initializes the SPI Master block.
141 //!
142 //! Upon successful initialization of the SPI master block, this function will
143 //! have set the bus speed for the master, but the SPI Master block still
144 //! remains disabled and must be enabled with USCI_A_SPI_enable()
145 //!
146 //! \param baseAddress is the base address of the I2C Master module.
147 //! \param param is the pointer to struct for master initialization.
148 //!
149 //! Modified bits are \b UCCKPH, \b UCCKPL, \b UC7BIT and \b UCMSB of \b
150 //! UCAxCTL0 register; bits \b UCSSELx and \b UCSWRST of \b UCAxCTL1 register.
151 //!
152 //! \return STATUS_SUCCESS
153 //
154 //*****************************************************************************
155 extern bool USCI_A_SPI_initMaster(uint16_t baseAddress,
157 
158 //*****************************************************************************
159 //
160 //! \brief Initializes the SPI Master clock.At the end of this function call,
161 //! SPI module is left enabled.
162 //!
163 //! \param baseAddress is the base address of the I2C Master module.
164 //! \param param is the pointer to struct for master clock setting.
165 //!
166 //! Modified bits of \b UCAxBRW register.
167 //!
168 //! \return None
169 //
170 //*****************************************************************************
171 extern void USCI_A_SPI_changeMasterClock(uint16_t baseAddress,
173 
174 //*****************************************************************************
175 //
176 //! \brief Initializes the SPI Slave block.
177 //!
178 //! Upon successful initialization of the SPI slave block, this function will
179 //! have initialized the slave block, but the SPI Slave block still remains
180 //! disabled and must be enabled with USCI_A_SPI_enable()
181 //!
182 //! \param baseAddress is the base address of the SPI Slave module.
183 //! \param msbFirst controls the direction of the receive and transmit shift
184 //! register.
185 //! Valid values are:
186 //! - \b USCI_A_SPI_MSB_FIRST
187 //! - \b USCI_A_SPI_LSB_FIRST [Default]
188 //! \param clockPhase is clock phase select.
189 //! Valid values are:
190 //! - \b USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
191 //! [Default]
192 //! - \b USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
193 //! \param clockPolarity
194 //! Valid values are:
195 //! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
196 //! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
197 //!
198 //! Modified bits are \b UCMSB, \b UCMST, \b UC7BIT, \b UCCKPL, \b UCCKPH and
199 //! \b UCMODE of \b UCAxCTL0 register; bits \b UCSWRST of \b UCAxCTL1 register.
200 //!
201 //! \return STATUS_SUCCESS
202 //
203 //*****************************************************************************
204 extern bool USCI_A_SPI_initSlave(uint16_t baseAddress,
205  uint8_t msbFirst,
206  uint8_t clockPhase,
207  uint8_t clockPolarity);
208 
209 //*****************************************************************************
210 //
211 //! \brief Changes the SPI clock phase and polarity.At the end of this function
212 //! call, SPI module is left enabled.
213 //!
214 //! \param baseAddress is the base address of the I2C Master module.
215 //! \param clockPhase is clock phase select.
216 //! Valid values are:
217 //! - \b USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
218 //! [Default]
219 //! - \b USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
220 //! \param clockPolarity
221 //! Valid values are:
222 //! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
223 //! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
224 //!
225 //! Modified bits are \b UCCKPL and \b UCCKPH of \b UCAxCTL0 register.
226 //!
227 //! \return None
228 //
229 //*****************************************************************************
230 extern void USCI_A_SPI_changeClockPhasePolarity(uint16_t baseAddress,
231  uint8_t clockPhase,
232  uint8_t clockPolarity);
233 
234 //*****************************************************************************
235 //
236 //! \brief Transmits a byte from the SPI Module.
237 //!
238 //! This function will place the supplied data into SPI transmit data register
239 //! to start transmission
240 //!
241 //! \param baseAddress is the base address of the SPI module.
242 //! \param transmitData data to be transmitted from the SPI module
243 //!
244 //! \return None
245 //
246 //*****************************************************************************
247 extern void USCI_A_SPI_transmitData(uint16_t baseAddress,
248  uint8_t transmitData);
249 
250 //*****************************************************************************
251 //
252 //! \brief Receives a byte that has been sent to the SPI Module.
253 //!
254 //! This function reads a byte of data from the SPI receive data Register.
255 //!
256 //! \param baseAddress is the base address of the SPI module.
257 //!
258 //! \return Returns the byte received from by the SPI module, cast as an
259 //! uint8_t.
260 //
261 //*****************************************************************************
262 extern uint8_t USCI_A_SPI_receiveData(uint16_t baseAddress);
263 
264 //*****************************************************************************
265 //
266 //! \brief Enables individual SPI interrupt sources.
267 //!
268 //! Enables the indicated SPI interrupt sources. Only the sources that are
269 //! enabled can be reflected to the processor interrupt; disabled sources have
270 //! no effect on the processor. Does not clear interrupt flags.
271 //!
272 //! \param baseAddress is the base address of the SPI module.
273 //! \param mask is the bit mask of the interrupt sources to be enabled.
274 //! Mask value is the logical OR of any of the following:
275 //! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
276 //! - \b USCI_A_SPI_RECEIVE_INTERRUPT
277 //!
278 //! Modified bits of \b UCAxIE register.
279 //!
280 //! \return None
281 //
282 //*****************************************************************************
283 extern void USCI_A_SPI_enableInterrupt(uint16_t baseAddress,
284  uint8_t mask);
285 
286 //*****************************************************************************
287 //
288 //! \brief Disables individual SPI interrupt sources.
289 //!
290 //! Disables the indicated SPI interrupt sources. Only the sources that are
291 //! enabled can be reflected to the processor interrupt; disabled sources have
292 //! no effect on the processor.
293 //!
294 //! \param baseAddress is the base address of the SPI module.
295 //! \param mask is the bit mask of the interrupt sources to be disabled.
296 //! Mask value is the logical OR of any of the following:
297 //! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
298 //! - \b USCI_A_SPI_RECEIVE_INTERRUPT
299 //!
300 //! Modified bits of \b UCAxIE register.
301 //!
302 //! \return None
303 //
304 //*****************************************************************************
305 extern void USCI_A_SPI_disableInterrupt(uint16_t baseAddress,
306  uint8_t mask);
307 
308 //*****************************************************************************
309 //
310 //! \brief Gets the current SPI interrupt status.
311 //!
312 //! This returns the interrupt status for the SPI module based on which flag is
313 //! passed.
314 //!
315 //! \param baseAddress is the base address of the SPI module.
316 //! \param mask is the masked interrupt flag status to be returned.
317 //! Mask value is the logical OR of any of the following:
318 //! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
319 //! - \b USCI_A_SPI_RECEIVE_INTERRUPT
320 //!
321 //! \return The current interrupt status as the mask of the set flags
322 //! Return Logical OR of any of the following:
323 //! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
324 //! - \b USCI_A_SPI_RECEIVE_INTERRUPT
325 //! \n indicating the status of the masked interrupts
326 //
327 //*****************************************************************************
328 extern uint8_t USCI_A_SPI_getInterruptStatus(uint16_t baseAddress,
329  uint8_t mask);
330 
331 //*****************************************************************************
332 //
333 //! \brief Clears the selected SPI interrupt status flag.
334 //!
335 //! \param baseAddress is the base address of the SPI module.
336 //! \param mask is the masked interrupt flag to be cleared.
337 //! Mask value is the logical OR of any of the following:
338 //! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
339 //! - \b USCI_A_SPI_RECEIVE_INTERRUPT
340 //!
341 //! Modified bits of \b UCAxIFG register.
342 //!
343 //! \return None
344 //
345 //*****************************************************************************
346 extern void USCI_A_SPI_clearInterrupt(uint16_t baseAddress,
347  uint8_t mask);
348 
349 //*****************************************************************************
350 //
351 //! \brief Enables the SPI block.
352 //!
353 //! This will enable operation of the SPI block.
354 //!
355 //! \param baseAddress is the base address of the USCI SPI module.
356 //!
357 //! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
358 //!
359 //! \return None
360 //
361 //*****************************************************************************
362 extern void USCI_A_SPI_enable(uint16_t baseAddress);
363 
364 //*****************************************************************************
365 //
366 //! \brief Disables the SPI block.
367 //!
368 //! This will disable operation of the SPI block.
369 //!
370 //! \param baseAddress is the base address of the USCI SPI module.
371 //!
372 //! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
373 //!
374 //! \return None
375 //
376 //*****************************************************************************
377 extern void USCI_A_SPI_disable(uint16_t baseAddress);
378 
379 //*****************************************************************************
380 //
381 //! \brief Returns the address of the RX Buffer of the SPI for the DMA module.
382 //!
383 //! Returns the address of the SPI RX Buffer. This can be used in conjunction
384 //! with the DMA to store the received data directly to memory.
385 //!
386 //! \param baseAddress is the base address of the SPI module.
387 //!
388 //! \return the address of the RX Buffer
389 //
390 //*****************************************************************************
391 extern uint32_t USCI_A_SPI_getReceiveBufferAddressForDMA(uint16_t baseAddress);
392 
393 //*****************************************************************************
394 //
395 //! \brief Returns the address of the TX Buffer of the SPI for the DMA module.
396 //!
397 //! Returns the address of the SPI TX Buffer. This can be used in conjunction
398 //! with the DMA to obtain transmitted data directly from memory.
399 //!
400 //! \param baseAddress is the base address of the SPI module.
401 //!
402 //! \return the address of the TX Buffer
403 //
404 //*****************************************************************************
405 extern uint32_t USCI_A_SPI_getTransmitBufferAddressForDMA(uint16_t baseAddress);
406 
407 //*****************************************************************************
408 //
409 //! \brief Indicates whether or not the SPI bus is busy.
410 //!
411 //! This function returns an indication of whether or not the SPI bus is
412 //! busy.This function checks the status of the bus via UCBBUSY bit
413 //!
414 //! \param baseAddress is the base address of the SPI module.
415 //!
416 //! \return USCI_A_SPI_BUSY if the SPI module transmitting or receiving is
417 //! busy; otherwise, returns USCI_A_SPI_NOT_BUSY.
418 //! Return one of the following:
419 //! - \b USCI_A_SPI_BUSY
420 //! - \b USCI_A_SPI_NOT_BUSY
421 //! \n indicating if the USCI_A_SPI is busy
422 //
423 //*****************************************************************************
424 extern uint8_t USCI_A_SPI_isBusy(uint16_t baseAddress);
425 
426 //*****************************************************************************
427 //
428 // Mark the end of the C bindings section for C++ compilers.
429 //
430 //*****************************************************************************
431 #ifdef __cplusplus
432 }
433 #endif
434 
435 #endif
436 #endif // __MSP430WARE_USCI_A_SPI_H__
uint32_t clockSourceFrequency
Is the frequency of the selected clock source.
Definition: usci_a_spi.h:65
uint32_t clockSourceFrequency
Is the frequency of the selected clock source.
Definition: usci_a_spi.h:38
void USCI_A_SPI_changeClockPhasePolarity(uint16_t baseAddress, uint8_t clockPhase, uint8_t clockPolarity)
Changes the SPI clock phase and polarity.At the end of this function call, SPI module is left enabled...
Definition: usci_a_spi.c:102
uint8_t USCI_A_SPI_receiveData(uint16_t baseAddress)
Receives a byte that has been sent to the SPI Module.
Definition: usci_a_spi.c:129
uint32_t USCI_A_SPI_getReceiveBufferAddressForDMA(uint16_t baseAddress)
Returns the address of the RX Buffer of the SPI for the DMA module.
Definition: usci_a_spi.c:174
uint8_t selectClockSource
Definition: usci_a_spi.h:36
uint8_t USCI_A_SPI_getInterruptStatus(uint16_t baseAddress, uint8_t mask)
Gets the current SPI interrupt status.
Definition: usci_a_spi.c:148
void USCI_A_SPI_enable(uint16_t baseAddress)
Enables the SPI block.
Definition: usci_a_spi.c:162
void USCI_A_SPI_transmitData(uint16_t baseAddress, uint8_t transmitData)
Transmits a byte from the SPI Module.
Definition: usci_a_spi.c:122
void USCI_A_SPI_clearInterrupt(uint16_t baseAddress, uint8_t mask)
Clears the selected SPI interrupt status flag.
Definition: usci_a_spi.c:155
bool USCI_A_SPI_initSlave(uint16_t baseAddress, uint8_t msbFirst, uint8_t clockPhase, uint8_t clockPolarity)
Initializes the SPI Slave block.
Definition: usci_a_spi.c:72
uint8_t USCI_A_SPI_isBusy(uint16_t baseAddress)
Indicates whether or not the SPI bus is busy.
Definition: usci_a_spi.c:184
Used in the USCI_A_SPI_initMaster() function as the param parameter.
Definition: usci_a_spi.h:31
uint8_t clockPhase
Definition: usci_a_spi.h:50
uint32_t desiredSpiClock
Is the desired clock rate for SPI communication.
Definition: usci_a_spi.h:40
uint32_t USCI_A_SPI_getTransmitBufferAddressForDMA(uint16_t baseAddress)
Returns the address of the TX Buffer of the SPI for the DMA module.
Definition: usci_a_spi.c:179
void USCI_A_SPI_disable(uint16_t baseAddress)
Disables the SPI block.
Definition: usci_a_spi.c:168
uint8_t msbFirst
Definition: usci_a_spi.h:45
Used in the USCI_A_SPI_changeMasterClock() function as the param parameter.
Definition: usci_a_spi.h:63
void USCI_A_SPI_disableInterrupt(uint16_t baseAddress, uint8_t mask)
Disables individual SPI interrupt sources.
Definition: usci_a_spi.c:141
uint32_t desiredSpiClock
Is the desired clock rate for SPI communication.
Definition: usci_a_spi.h:67
uint8_t clockPolarity
Definition: usci_a_spi.h:54
void USCI_A_SPI_enableInterrupt(uint16_t baseAddress, uint8_t mask)
Enables individual SPI interrupt sources.
Definition: usci_a_spi.c:134
bool USCI_A_SPI_initMaster(uint16_t baseAddress, USCI_A_SPI_initMasterParam *param)
Initializes the SPI Master block.
Definition: usci_a_spi.c:21
void USCI_A_SPI_changeMasterClock(uint16_t baseAddress, USCI_A_SPI_changeMasterClockParam *param)
Initializes the SPI Master clock.At the end of this function call, SPI module is left enabled...
Definition: usci_a_spi.c:60

Copyright 2016, Texas Instruments Incorporated