cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Communication problem of AS5048A based on STM32F405RGT6

YXian.1
Associate

0690X00000BuuSlQAJ.pngHello, everyone.

I am currently studying FOC for BLDCM.A motor with magnetic encoder AS5048A was used.The PWM output of the magnetic encoder works normally, but I failed to get the SPI interface to work normally.If you have ever used this magnetic encoder, please give me some advice.

Here is my spi configuration,my project and the data from the logic analyzer.

void SPI_Config()

{

   SPI_InitTypeDef spi;

 GPIO_InitTypeDef gpio;

   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);

   RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);

   gpio.GPIO_Pin = SPI_SCK_PIN|SPI_MISO_PIN|SPI_MOSI_PIN;

 gpio.GPIO_Speed = GPIO_Low_Speed;

 gpio.GPIO_Mode = GPIO_Mode_AF;

 gpio.GPIO_OType = GPIO_OType_PP;

 gpio.GPIO_PuPd = GPIO_PuPd_UP;

 GPIO_Init(SPI_GPIO_PORT, &gpio);

   GPIO_PinAFConfig(SPI_GPIO_PORT,SPI_SCK_PINSOURCE,GPIO_AF_SPI2);

   GPIO_PinAFConfig(SPI_GPIO_PORT,SPI_MISO_PINSOURCE,GPIO_AF_SPI2);

   GPIO_PinAFConfig(SPI_GPIO_PORT,SPI_MOSI_PINSOURCE,GPIO_AF_SPI2);

   gpio.GPIO_Pin = ICGCSB_PIN;

 gpio.GPIO_Mode = GPIO_Mode_OUT;

 gpio.GPIO_PuPd = GPIO_PuPd_UP;

 GPIO_Init(ICGCSB_PORT, &gpio);

   GPIO_SetBits(ICGCSB_PORT,ICGCSB_PIN);

   spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

 spi.SPI_Mode = SPI_Mode_Master;

 spi.SPI_DataSize = SPI_DataSize_16b;

 spi.SPI_CPOL = SPI_CPOL_Low;

 spi.SPI_CPHA = SPI_CPHA_2Edge;

 spi.SPI_NSS = SPI_NSS_Soft;//软件NSS SPI_NSS_Soft SPI_NSS_Hard

 spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;//fSCK = 42MHz/SPI_BaudRatePrescaler

 spi.SPI_FirstBit = SPI_FirstBit_MSB;

 spi.SPI_CRCPolynomial = 15;

 SPI_Init(SPI2, &spi);

 SPI_Cmd(SPI2, ENABLE);

   delay_ms(10);

}

2 REPLIES 2
Laurent Ca...
Lead II

Dear YXian.1

Do you have still this problem to solve?

Best regards

Laurent Ca...

Dear YXian.1

OK. I consider this post closed.

Do not hesitate to answer if it is not.

Best regards

Laurent Ca...