⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 arm7 STR711的SPI操作的功能源代码.保证可用
💻 C
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 03/07/2003
* Description        : This file demonstrates how to use the BSPI software library
********************************************************************************
* History:
*  03/07/03 : First Version
*******************************************************************************/
#include "71x_lib.h"

void Main(void)
{
	// Word to be transmitted
	u8 bArray[] = "BSPI_Test";

	// Pointers to transmitter and emitter buffers
	u8 *pTxBuffer;
	u8 *pRxBuffer;

#ifdef DEBUG
	debug();
#endif

//---------------------------------------------------------------------------------------
//Communication between BSPI0(master) and BSPI1(slave)
//              *BSPI0 send five words of pbuffer to BSPI1 : BSPI0 ----- BSPI ----> BSPI1
//              *BSPI1 receive four words from BSPI0 : BSPI1 <---- BSPI ---- BSPI0
//---------------------------------------------------------------------------------------

	GPIO_Config(GPIO0, 0x0077, GPIO_AF_PP);	//Configure GPI00 on mode Alternate function Push Pull
	BSPI_BSPI0Conf(ENABLE);					//Enable the BSPI0 interface

//-------------------------------------------
//Configure BSPI0 as a Master
//-------------------------------------------

	BSPI_Init(BSPI0);						//Initialize BSPI0
	BSPI_ClockDividerConfig(BSPI0, 6);		//Configure Baud rate Frequency: ---> APB1/6
	BSPI_Enable(BSPI0, ENABLE);				//Enable BSPI0
	BSPI_MasterEnable(BSPI0, ENABLE);		//Configure BSPI0 as a Master
	BSPI_ClkActiveHigh(BSPI0, ENABLE);		//Configure the clock to be active high
	BSPI_ClkFEdge(BSPI0, DISABLE);			//Enable capturing the first Data sample on the first edge of SCK
	BSPI_8bLEn(BSPI0, ENABLE);				//Set the word length to 16 bit
	BSPI_TrFifoDepth(BSPI0, 7);				//Configure the depth of transmit to 7 words
	pTxBuffer = bArray;						//Point on the word to transit

//-------------------------------------------
//Configue BSPI1 as a Slave
//-------------------------------------------

	BSPI_Init(BSPI1);						//Initialize BSPI1
	BSPI_ClockDividerConfig(BSPI1, 8);		//Configure Baud rate Frequency :-->APB1/8
	BSPI_Enable(BSPI1, ENABLE);				//Enable BSPI1
	BSPI_MasterEnable(BSPI1, DISABLE);		//Configure BSPI0 as a Slave
	BSPI_ClkActiveHigh(BSPI1, ENABLE);		//Configure the clock to be active high
	BSPI_ClkFEdge(BSPI1, DISABLE);			//Enable capturing the first Data sample on the first edge of SCK
	BSPI_8bLEn(BSPI1, ENABLE);				//Set the word length to 16 bit
	BSPI_RcFifoDepth(BSPI1, 5);				//Configure the depth of receive to 5 word

//---------------------------------------------
//Send five words of buffer ---> BSPI0
//---------------------------------------------
	BSPI_BufferSend(BSPI0, pTxBuffer, 5);

//---------------------------------------------
//Receive four words to buffer <--- BSPI1
//---------------------------------------------
	BSPI_BufferReceive(BSPI1, pRxBuffer, 4);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -