MSP430 DriverLib for MSP430F5xx_6xx Devices  2.80.00.01
 All Data Structures Functions Variables Modules Pages
usci_b_spi.h
1 //*****************************************************************************
2 //
3 // usci_b_spi.h - Driver for the USCI_B_SPI Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_USCI_B_SPI_H__
8 #define __MSP430WARE_USCI_B_SPI_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_USCI_Bx__
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_B_SPI_initMaster() function as the param parameter.
29 //
30 //*****************************************************************************
32  //! Selects Clock source.
33  //! \n Valid values are:
34  //! - \b USCI_B_SPI_CLOCKSOURCE_ACLK
35  //! - \b USCI_B_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_B_SPI_MSB_FIRST
44  //! - \b USCI_B_SPI_LSB_FIRST [Default]
45  uint8_t msbFirst;
46  //! Is clock phase select.
47  //! \n Valid values are:
48  //! - \b USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
49  //! - \b USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
50  uint8_t clockPhase;
51  //! \n Valid values are:
52  //! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
53  //! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
54  uint8_t clockPolarity;
56 
57 //*****************************************************************************
58 //
59 //! \brief Used in the USCI_B_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_B_SPI_initSlave(), and
75 // USCI_B_SPI_changeClockPhasePolarity(); the param parameter for functions:
76 // USCI_B_SPI_initMaster().
77 //
78 //*****************************************************************************
79 #define USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT 0x00
80 #define USCI_B_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_B_SPI_initSlave(); the param parameter for functions:
86 // USCI_B_SPI_initMaster().
87 //
88 //*****************************************************************************
89 #define USCI_B_SPI_MSB_FIRST UCMSB
90 #define USCI_B_SPI_LSB_FIRST 0x00
91 
92 //*****************************************************************************
93 //
94 // The following are values that can be passed to the param parameter for
95 // functions: USCI_B_SPI_initMaster(); the clockPolarity parameter for
96 // functions: USCI_B_SPI_initSlave(), and
97 // USCI_B_SPI_changeClockPhasePolarity().
98 //
99 //*****************************************************************************
100 #define USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH UCCKPL
101 #define USCI_B_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_B_SPI_initMaster().
107 //
108 //*****************************************************************************
109 #define USCI_B_SPI_CLOCKSOURCE_ACLK UCSSEL__ACLK
110 #define USCI_B_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_B_SPI_enableInterrupt(), USCI_B_SPI_disableInterrupt(),
116 // USCI_B_SPI_getInterruptStatus(), and USCI_B_SPI_clearInterrupt() as well as
117 // returned by the USCI_B_SPI_getInterruptStatus() function.
118 //
119 //*****************************************************************************
120 #define USCI_B_SPI_TRANSMIT_INTERRUPT UCTXIE
121 #define USCI_B_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_B_SPI_isBusy() function.
127 //
128 //*****************************************************************************
129 #define USCI_B_SPI_BUSY UCBUSY
130 #define USCI_B_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_B_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 UCSSELx and \b UCSWRST of \b UCBxCTL1 register; bits
150 //! \b UCCKPH, \b UCCKPL, \b UC7BIT and \b UCMSB of \b UCBxCTL0 register.
151 //!
152 //! \return STATUS_SUCCESS
153 //
154 //*****************************************************************************
155 extern bool USCI_B_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_B_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_B_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_B_SPI_MSB_FIRST
187 //! - \b USCI_B_SPI_LSB_FIRST [Default]
188 //! \param clockPhase is clock phase select.
189 //! Valid values are:
190 //! - \b USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
191 //! [Default]
192 //! - \b USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
193 //! \param clockPolarity
194 //! Valid values are:
195 //! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
196 //! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
197 //!
198 //! Modified bits are \b UCSWRST of \b UCBxCTL1 register; bits \b UCMSB, \b
199 //! UCMST, \b UC7BIT, \b UCCKPL, \b UCCKPH and \b UCMODE of \b UCBxCTL0
200 //! register.
201 //!
202 //! \return STATUS_SUCCESS
203 //
204 //*****************************************************************************
205 extern bool USCI_B_SPI_initSlave(uint16_t baseAddress,
206  uint8_t msbFirst,
207  uint8_t clockPhase,
208  uint8_t clockPolarity);
209 
210 //*****************************************************************************
211 //
212 //! \brief Changes the SPI clock phase and polarity.At the end of this function
213 //! call, SPI module is left enabled.
214 //!
215 //! \param baseAddress is the base address of the I2C Master module.
216 //! \param clockPhase is clock phase select.
217 //! Valid values are:
218 //! - \b USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
219 //! [Default]
220 //! - \b USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
221 //! \param clockPolarity
222 //! Valid values are:
223 //! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
224 //! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
225 //!
226 //! Modified bits are \b UCCKPL and \b UCCKPH of \b UCAxCTL0 register.
227 //!
228 //! \return None
229 //
230 //*****************************************************************************
231 extern void USCI_B_SPI_changeClockPhasePolarity(uint16_t baseAddress,
232  uint8_t clockPhase,
233  uint8_t clockPolarity);
234 
235 //*****************************************************************************
236 //
237 //! \brief Transmits a byte from the SPI Module.
238 //!
239 //! This function will place the supplied data into SPI transmit data register
240 //! to start transmission
241 //!
242 //! \param baseAddress is the base address of the SPI module.
243 //! \param transmitData data to be transmitted from the SPI module
244 //!
245 //! \return None
246 //
247 //*****************************************************************************
248 extern void USCI_B_SPI_transmitData(uint16_t baseAddress,
249  uint8_t transmitData);
250 
251 //*****************************************************************************
252 //
253 //! \brief Receives a byte that has been sent to the SPI Module.
254 //!
255 //! This function reads a byte of data from the SPI receive data Register.
256 //!
257 //! \param baseAddress is the base address of the SPI module.
258 //!
259 //! \return Returns the byte received from by the SPI module, cast as an
260 //! uint8_t.
261 //
262 //*****************************************************************************
263 extern uint8_t USCI_B_SPI_receiveData(uint16_t baseAddress);
264 
265 //*****************************************************************************
266 //
267 //! \brief Enables individual SPI interrupt sources.
268 //!
269 //! Enables the indicated SPI interrupt sources. Only the sources that are
270 //! enabled can be reflected to the processor interrupt; disabled sources have
271 //! no effect on the processor. <b>Does not clear interrupt flags.
272 //!
273 //! \param baseAddress is the base address of the SPI module.
274 //! \param mask is the bit mask of the interrupt sources to be enabled.
275 //! Valid values are:
276 //! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
277 //! - \b USCI_B_SPI_RECEIVE_INTERRUPT
278 //!
279 //! Modified bits of \b UCBxIE register.
280 //!
281 //! \return None
282 //
283 //*****************************************************************************
284 extern void USCI_B_SPI_enableInterrupt(uint16_t baseAddress,
285  uint8_t mask);
286 
287 //*****************************************************************************
288 //
289 //! \brief Disables individual SPI interrupt sources.
290 //!
291 //! Disables the indicated SPI interrupt sources. Only the sources that are
292 //! enabled can be reflected to the processor interrupt; disabled sources have
293 //! no effect on the processor.
294 //!
295 //! \param baseAddress is the base address of the SPI module.
296 //! \param mask is the bit mask of the interrupt sources to be disabled.
297 //! Valid values are:
298 //! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
299 //! - \b USCI_B_SPI_RECEIVE_INTERRUPT
300 //!
301 //! Modified bits of \b UCBxIE register.
302 //!
303 //! \return None
304 //
305 //*****************************************************************************
306 extern void USCI_B_SPI_disableInterrupt(uint16_t baseAddress,
307  uint8_t mask);
308 
309 //*****************************************************************************
310 //
311 //! \brief Gets the current SPI interrupt status.
312 //!
313 //! This returns the interrupt status for the SPI module based on which flag is
314 //! passed.
315 //!
316 //! \param baseAddress is the base address of the SPI module.
317 //! \param mask is the masked interrupt flag status to be returned.
318 //! Valid values are:
319 //! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
320 //! - \b USCI_B_SPI_RECEIVE_INTERRUPT
321 //!
322 //! \return The current interrupt status as the mask of the set flags
323 //! Return Logical OR of any of the following:
324 //! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
325 //! - \b USCI_B_SPI_RECEIVE_INTERRUPT
326 //! \n indicating the status of the masked interrupts
327 //
328 //*****************************************************************************
329 extern uint8_t USCI_B_SPI_getInterruptStatus(uint16_t baseAddress,
330  uint8_t mask);
331 
332 //*****************************************************************************
333 //
334 //! \brief Clears the selected SPI interrupt status flag.
335 //!
336 //! \param baseAddress is the base address of the SPI module.
337 //! \param mask is the masked interrupt flag to be cleared.
338 //! Valid values are:
339 //! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
340 //! - \b USCI_B_SPI_RECEIVE_INTERRUPT
341 //!
342 //! Modified bits of \b UCBxIFG register.
343 //!
344 //! \return None
345 //
346 //*****************************************************************************
347 extern void USCI_B_SPI_clearInterrupt(uint16_t baseAddress,
348  uint8_t mask);
349 
350 //*****************************************************************************
351 //
352 //! \brief Enables the SPI block.
353 //!
354 //! This will enable operation of the SPI block.
355 //!
356 //! \param baseAddress is the base address of the USCI SPI module.
357 //!
358 //! Modified bits are \b UCSWRST of \b UCBxCTL1 register.
359 //!
360 //! \return None
361 //
362 //*****************************************************************************
363 extern void USCI_B_SPI_enable(uint16_t baseAddress);
364 
365 //*****************************************************************************
366 //
367 //! \brief Disables the SPI block.
368 //!
369 //! This will disable operation of the SPI block.
370 //!
371 //! \param baseAddress is the base address of the USCI SPI module.
372 //!
373 //! Modified bits are \b UCSWRST of \b UCBxCTL1 register.
374 //!
375 //! \return None
376 //
377 //*****************************************************************************
378 extern void USCI_B_SPI_disable(uint16_t baseAddress);
379 
380 //*****************************************************************************
381 //
382 //! \brief Returns the address of the RX Buffer of the SPI for the DMA module.
383 //!
384 //! Returns the address of the SPI RX Buffer. This can be used in conjunction
385 //! with the DMA to store the received data directly to memory.
386 //!
387 //! \param baseAddress is the base address of the SPI module.
388 //!
389 //! \return The address of the SPI RX buffer
390 //
391 //*****************************************************************************
392 extern uint32_t USCI_B_SPI_getReceiveBufferAddressForDMA(uint16_t baseAddress);
393 
394 //*****************************************************************************
395 //
396 //! \brief Returns the address of the TX Buffer of the SPI for the DMA module.
397 //!
398 //! Returns the address of the SPI TX Buffer. This can be used in conjunction
399 //! with the DMA to obtain transmitted data directly from memory.
400 //!
401 //! \param baseAddress is the base address of the SPI module.
402 //!
403 //! \return The address of the SPI TX buffer
404 //
405 //*****************************************************************************
406 extern uint32_t USCI_B_SPI_getTransmitBufferAddressForDMA(uint16_t baseAddress);
407 
408 //*****************************************************************************
409 //
410 //! \brief Indicates whether or not the SPI bus is busy.
411 //!
412 //! This function returns an indication of whether or not the SPI bus is
413 //! busy.This function checks the status of the bus via UCBBUSY bit
414 //!
415 //! \param baseAddress is the base address of the SPI module.
416 //!
417 //! \return USCI_B_SPI_BUSY if the SPI module transmitting or receiving is
418 //! busy; otherwise, returns USCI_B_SPI_NOT_BUSY.
419 //! Return one of the following:
420 //! - \b USCI_B_SPI_BUSY
421 //! - \b USCI_B_SPI_NOT_BUSY
422 //! \n indicating if the USCI_B_SPI is busy
423 //
424 //*****************************************************************************
425 extern uint8_t USCI_B_SPI_isBusy(uint16_t baseAddress);
426 
427 //*****************************************************************************
428 //
429 // Mark the end of the C bindings section for C++ compilers.
430 //
431 //*****************************************************************************
432 #ifdef __cplusplus
433 }
434 #endif
435 
436 #endif
437 #endif // __MSP430WARE_USCI_B_SPI_H__
uint32_t USCI_B_SPI_getTransmitBufferAddressForDMA(uint16_t baseAddress)
Returns the address of the TX Buffer of the SPI for the DMA module.
Definition: usci_b_spi.c:176
void USCI_B_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_b_spi.c:99
void USCI_B_SPI_changeMasterClock(uint16_t baseAddress, USCI_B_SPI_changeMasterClockParam *param)
Initializes the SPI Master clock.At the end of this function call, SPI module is left enabled...
Definition: usci_b_spi.c:58
bool USCI_B_SPI_initMaster(uint16_t baseAddress, USCI_B_SPI_initMasterParam *param)
Initializes the SPI Master block.
Definition: usci_b_spi.c:21
void USCI_B_SPI_transmitData(uint16_t baseAddress, uint8_t transmitData)
Transmits a byte from the SPI Module.
Definition: usci_b_spi.c:119
uint8_t msbFirst
Definition: usci_b_spi.h:45
void USCI_B_SPI_enable(uint16_t baseAddress)
Enables the SPI block.
Definition: usci_b_spi.c:159
uint8_t USCI_B_SPI_isBusy(uint16_t baseAddress)
Indicates whether or not the SPI bus is busy.
Definition: usci_b_spi.c:181
uint8_t clockPhase
Definition: usci_b_spi.h:50
uint32_t USCI_B_SPI_getReceiveBufferAddressForDMA(uint16_t baseAddress)
Returns the address of the RX Buffer of the SPI for the DMA module.
Definition: usci_b_spi.c:171
void USCI_B_SPI_disableInterrupt(uint16_t baseAddress, uint8_t mask)
Disables individual SPI interrupt sources.
Definition: usci_b_spi.c:138
uint8_t clockPolarity
Definition: usci_b_spi.h:54
void USCI_B_SPI_clearInterrupt(uint16_t baseAddress, uint8_t mask)
Clears the selected SPI interrupt status flag.
Definition: usci_b_spi.c:152
uint32_t clockSourceFrequency
Is the frequency of the selected clock source.
Definition: usci_b_spi.h:65
uint32_t desiredSpiClock
Is the desired clock rate for SPI communication.
Definition: usci_b_spi.h:67
bool USCI_B_SPI_initSlave(uint16_t baseAddress, uint8_t msbFirst, uint8_t clockPhase, uint8_t clockPolarity)
Initializes the SPI Slave block.
Definition: usci_b_spi.c:70
void USCI_B_SPI_disable(uint16_t baseAddress)
Disables the SPI block.
Definition: usci_b_spi.c:165
uint32_t desiredSpiClock
Is the desired clock rate for SPI communication.
Definition: usci_b_spi.h:40
uint8_t USCI_B_SPI_receiveData(uint16_t baseAddress)
Receives a byte that has been sent to the SPI Module.
Definition: usci_b_spi.c:126
uint32_t clockSourceFrequency
Is the frequency of the selected clock source.
Definition: usci_b_spi.h:38
uint8_t USCI_B_SPI_getInterruptStatus(uint16_t baseAddress, uint8_t mask)
Gets the current SPI interrupt status.
Definition: usci_b_spi.c:145
Used in the USCI_B_SPI_initMaster() function as the param parameter.
Definition: usci_b_spi.h:31
void USCI_B_SPI_enableInterrupt(uint16_t baseAddress, uint8_t mask)
Enables individual SPI interrupt sources.
Definition: usci_b_spi.c:131
uint8_t selectClockSource
Definition: usci_b_spi.h:36
Used in the USCI_B_SPI_changeMasterClock() function as the param parameter.
Definition: usci_b_spi.h:63

Copyright 2016, Texas Instruments Incorporated