📄 stm32f10x_spi.lst
字号:
219
220 if (NewState != DISABLE)
221 {
222 /* Enable the selected SPI interrupt */
223 SPIx->CR2 |= itmask;
224 }
225 else
226 {
227 /* Disable the selected SPI interrupt */
228 SPIx->CR2 &= (u16)~itmask;
229 }
230 }
231
232 /*******************************************************************************
233 * Function Name : SPI_DMACmd
234 * Description : Enables or disables the SPIx抯 DMA interface.
235 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
236 * - SPI_DMAReq: specifies the SPI DMA transfer request to be
237 * enabled or disabled.
238 * This parameter can be any combination of the following values:
239 * - SPI_DMAReq_Tx: Tx buffer DMA transfer request
240 * - SPI_DMAReq_Rx: Rx buffer DMA transfer request
241 * - NewState: new state of the selected SPI DMA transfer request.
242 * This parameter can be: ENABLE or DISABLE.
243 * Output : None
244 * Return : None
245 *******************************************************************************/
246 void SPI_DMACmd(SPI_TypeDef* SPIx, u16 SPI_DMAReq, FunctionalState NewState)
247 {
248 /* Check the parameters */
249 assert_param(IS_FUNCTIONAL_STATE(NewState));
250 assert_param(IS_SPI_DMA_REQ(SPI_DMAReq));
251
252 if (NewState != DISABLE)
253 {
254 /* Enable the selected SPI DMA requests */
255 SPIx->CR2 |= SPI_DMAReq;
256 }
257 else
258 {
259 /* Disable the selected SPI DMA requests */
260 SPIx->CR2 &= (u16)~SPI_DMAReq;
261 }
262 }
263
264 /*******************************************************************************
265 * Function Name : SPI_SendData
266 * Description : Transmits a Data through the SPIx peripheral.
267 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
268 * - Data : Data to be transmitted..
269 * Output : None
270 * Return : None
271 *******************************************************************************/
272 void SPI_SendData(SPI_TypeDef* SPIx, u16 Data)
273 {
274 /* Write in the DR register the data to be sent */
275 SPIx->DR = Data;
276 }
277
278 /*******************************************************************************
279 * Function Name : SPI_ReceiveData
280 * Description : Returns the most recent received data by the SPIx peripheral.
281 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
282 * Output : None
283 * Return : The value of the received data.
284 *******************************************************************************/
285 u16 SPI_ReceiveData(SPI_TypeDef* SPIx)
286 {
287 /* Return the data in the DR register */
288 return SPIx->DR;
289 }
290
291 /*******************************************************************************
292 * Function Name : SPI_NSSInternalSoftwareConfig
293 * Description : Configures internally by software the NSS pin for the selected
294 * SPI.
295 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
296 * - SPI_NSSInternalSoft: specifies the SPI NSS internal state.
297 * This parameter can be one of the following values:
298 * - SPI_NSSInternalSoft_Set: Set NSS pin internally
299 * - SPI_NSSInternalSoft_Reset: Reset NSS pin internally
300 * Output : None
301 * Return : None
302 *******************************************************************************/
303 void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, u16 SPI_NSSInternalSoft)
304 {
305 /* Check the parameters */
306 assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
307
308 if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
309 {
310 /* Set NSS pin internally by software */
311 SPIx->CR1 |= SPI_NSSInternalSoft_Set;
312 }
313 else
314 {
315 /* Reset NSS pin internally by software */
316 SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
317 }
318 }
319
320 /*******************************************************************************
321 * Function Name : SPI_SSOutputCmd
322 * Description : Enables or disables the SS output for the selected SPI.
323 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
324 * - NewState: new state of the SPIx SS output.
325 * This parameter can be: ENABLE or DISABLE.
326 * Output : None
327 * Return : None
328 *******************************************************************************/
329 void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
330 {
331 /* Check the parameters */
332 assert_param(IS_FUNCTIONAL_STATE(NewState));
333
334 if (NewState != DISABLE)
335 {
336 /* Enable the selected SPI SS output */
337 SPIx->CR2 |= CR2_SSOE_Set;
338 }
339 else
340 {
341 /* Disable the selected SPI SS output */
342 SPIx->CR2 &= CR2_SSOE_Reset;
343 }
344 }
345
346 /*******************************************************************************
347 * Function Name : SPI_DataSizeConfig
348 * Description : Configures the data size for the selected SPI.
349 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
350 * - SPI_DataSize: specifies the SPI data size.
351 * This parameter can be one of the following values:
352 * - SPI_DataSize_16b: Set data frame format to 16bit
353 * - SPI_DataSize_8b: Set data frame format to 8bit
354 * Output : None
355 * Return : None
356 *******************************************************************************/
357 void SPI_DataSizeConfig(SPI_TypeDef* SPIx, u16 SPI_DataSize)
358 {
359 /* Check the parameters */
360 assert_param(IS_SPI_DATASIZE(SPI_DataSize));
361
362 /* Clear DFF bit */
363 SPIx->CR1 &= (u16)~SPI_DataSize_16b;
364 /* Set new DFF bit value */
365 SPIx->CR1 |= SPI_DataSize;
366 }
367
368 /*******************************************************************************
369 * Function Name : SPI_TransmitCRC
370 * Description : Transmit the SPIx CRC value.
371 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
372 * Output : None
373 * Return : None
374 *******************************************************************************/
375 void SPI_TransmitCRC(SPI_TypeDef* SPIx)
376 {
377 /* Enable the selected SPI CRC transmission */
378 SPIx->CR1 |= CR1_CRCNext_Set;
379 }
380
381 /*******************************************************************************
382 * Function Name : SPI_CalculateCRC
383 * Description : Enables or disables the CRC value calculation of the
384 * transfered bytes.
385 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
386 * - NewState: new state of the SPIx CRC value calculation.
387 * This parameter can be: ENABLE or DISABLE.
388 * Output : None
389 * Return : None
390 *******************************************************************************/
391 void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
392 {
393 /* Check the parameters */
394 assert_param(IS_FUNCTIONAL_STATE(NewState));
395
396 if (NewState != DISABLE)
397 {
398 /* Enable the selected SPI CRC calculation */
399 SPIx->CR1 |= CR1_CRCEN_Set;
400 }
401 else
402 {
403 /* Disable the selected SPI CRC calculation */
404 SPIx->CR1 &= CR1_CRCEN_Reset;
405 }
406 }
407
408 /*******************************************************************************
409 * Function Name : SPI_GetCRC
410 * Description : Returns the transmit or the receive CRC register value for
411 * the specified SPI.
412 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
413 * - SPI_CRC: specifies the CRC register to be read.
414 * This parameter can be one of the following values:
415 * - SPI_CRC_Tx: Selects Tx CRC register
416 * - SPI_CRC_Rx: Selects Rx CRC register
417 * Output : None
418 * Return : The selected CRC register value..
419 *******************************************************************************/
420 u16 SPI_GetCRC(SPI_TypeDef* SPIx, u8 SPI_CRC)
421 {
422 u16 crcreg = 0;
423
424 /* Check the parameters */
425 assert_param(IS_SPI_CRC(SPI_CRC));
426
427 if (SPI_CRC != SPI_CRC_Rx)
428 {
429 /* Get the Tx CRC register */
430 crcreg = SPIx->TXCRCR;
431 }
432 else
433 {
434 /* Get the Rx CRC register */
435 crcreg = SPIx->RXCRCR;
436 }
437
438 /* Return the selected CRC register */
439 return crcreg;
440 }
441
442 /*******************************************************************************
443 * Function Name : SPI_GetCRCPolynomial
444 * Description : Returns the CRC Polynomial register value for the specified SPI.
445 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
446 * Output : None
447 * Return : The CRC Polynomial register value.
448 *******************************************************************************/
449 u16 SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
450 {
451 /* Return the CRC polynomial register */
452 return SPIx->CRCPR;
453 }
454
455 /*******************************************************************************
456 * Function Name : SPI_BiDirectionalLineConfig
457 * Description : Selects the data transfer direction in bi-directional mode
458 * for the specified SPI.
459 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
460 * - SPI_Direction: specifies the data transfer direction in
461 * bi-directional mode.
462 * This parameter can be one of the following values:
463 * - SPI_Direction_Tx: Selects Tx transmission direction
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -