The configuration code is as follows:
void SPI23_Init (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOC, ENABLE);//can make GPIOB clock
RCC_APB1PeriphClockCmd (RCC_APB1Periph_SPI3, ENABLE);//can make SPI3 clock
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10;//SCK
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;//multiplexing function
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//100 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_NOPULL;//pull
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_11;//MISO
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;//multiplexing function
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//50 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_NOPULL;//pull
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_12;//MOSI
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;//multiplexing function
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//50 MHZ
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_NOPULL;//pull
GPIO_Init (GPIOC, & amp; GPIO_InitStructure);
GPIO_PinAFConfig (GPIOC, GPIO_PinSource10 GPIO_AF_SPI3);//PC10 reuse for SPI3
GPIO_PinAFConfig (GPIOC, GPIO_PinSource12 GPIO_AF_SPI3);//PC11 reuse for SPI3
GPIO_PinAFConfig (GPIOC, GPIO_PinSource13 GPIO_AF_SPI3);//PC12 reuse for SPI3
//SPI mouth initialization
SPI_InitStructure. SPI_Direction=SPI_Direction_2Lines_FullDuplex;//set the SPI one-way or two-way data model: the SPI is set to double bidirectional full-duplex
SPI_InitStructure. SPI_Mode=SPI_Mode_Master;//set the SPI work mode: set give priority to SPI
SPI_InitStructure. SPI_DataSize=SPI_DataSize_8b;//set the SPI data size: SPI to send and receive eight frame structure
SPI_InitStructure. SPI_CPOL=SPI_CPOL_High;//the idle state of serial synchronous clock for the high level
SPI_InitStructure. SPI_CPHA=SPI_CPHA_2Edge;//the second jump along the serial synchronous clock (up or down) data by sampling
SPI_InitStructure. SPI_NSS=SPI_NSS_Soft;//NSS signal by the hardware (NSS pin) or software (use SSI) management: internal NSS signal with SSI control
SPI_InitStructure. SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_32;//define the baud rate of the preassigned frequency value: baud rate preassigned frequency value of 256
SPI_InitStructure. SPI_FirstBit=SPI_FirstBit_LSB;//specified data transmission from the MSB position or LSB: data transmission from the MSB start
SPI_InitStructure. SPI_CRCPolynomial=0;//CRC value calculated polynomial
SPI_Init (SPI3, & amp; SPI_InitStructure);//set according to the specified parameters in SPI_InitStruct initial non-greeks SPIx register
SPI_Cmd (SPI3, ENABLE);//can make SPI peripheral
SPI3_ReadWriteByte (0 XFF);//start transmission
}
U8 SPI3_ReadWriteByte (u8 writeData)
{
U8 waitnum=0, I=0;
While (SPI_I2S_GetFlagStatus (SPI3, SPI_I2S_FLAG_TXE)==RESET)//area waiting to send an empty
{
Waitnum++;
If (waitnum> 200) return 0;
}
SPI_I2S_SendData (SPI3, writeData);//a byte sent by a peripheral SPI3
Waitnum=0;
While (SPI_I2S_GetFlagStatus (SPI3, SPI_I2S_FLAG_RXNE)==RESET)//wait for a byte to the
{
Waitnum++;
If (waitnum> 200) return 0;
}
Return SPI_I2S_ReceiveData (SPI3);//return SPI3 received data
}
CodePudding user response:
Their top once, don't sink, do you have a great god knowCodePudding user response:
You can find a normal first to read and write procedures, let TMC5160 run up and look againCodePudding user response: