Home > other >  Stm32f407 SPI3 drive TMC5160 SCK abnormal waveform
Stm32f407 SPI3 drive TMC5160 SCK abnormal waveform

Time:11-25

I small white one, just began to MCU, want to use stm32f407 SPI3 drive TMC5160, now found that the problem is the SPI read back has been zero, even if you don't pick up TMC5160 read back is 0, use an oscilloscope to see CLK16 already start up, SCK return frequency is wrong, want to consult everybody a great god what is this problem,
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 know

CodePudding user response:

You can find a normal first to read and write procedures, let TMC5160 run up and look again

CodePudding user response:

refer to the second floor dceacho response:
you can find a normal first to read and write procedures, let TMC5160 ran to see
not found routines

CodePudding user response:

https://download.csdn.net/download/yishuicanhong/10350346

CodePudding user response:

SPI this shouldn't be a problem, you look at the manual of the TMC5160, see if you like set a SPI is feasible.
In addition of spi IO mouth I usually up after initialization, don't know how to use!

CodePudding user response:

Can email me [email protected] I have example code can for your reference

CodePudding user response:

Spi has nothing to do with the peripherals, first the spi, reference TMC262:
https://blog.csdn.net/qq_20553613/article/details/80210813

CodePudding user response:

refer to 6th floor TMC_CHINA response:
can email me [email protected] I have example code can for your reference
can send me a copy? Thank you, I WeChat 13588268763, paid, thank you!

CodePudding user response:

SPI is very simple, just a sender and receiver is connected into a cycle of shift register, under the clock pulse drive both exchange data each other;
You can't read data check is optional signal connection is correct, read from the machine address is correct?

CodePudding user response:

Hi the building Lord, I now on the use of ST32 and TMC5160 encountered some problems, because white is technology, so has been no progress, can you please send me a copy of the reference code? My mailbox 874542972 @qq.com. Thank you!

CodePudding user response:

Have a TMC5160_BOB_v1. 2 module, code examples can be sent to you? 991403552 @qq.com

CodePudding user response:

Please fully pay attention to the pin, don't conflict with another function, especially pay attention to whether or not to use jtag tube feet
  • Related