Skip to main content
Associate III
September 2, 2024
Solved

AS5047 SPI live expression not updating

  • September 2, 2024
  • 2 replies
  • 1184 views

kavinkumar_0-1725269572527.png

I'm writing a code for getting angle from a AS5047u magentic encoder to get the angle but the value from the angle not seems to be updating in the live expressions

    Best answer by kavinkumar
    	uint16_t spi_RX=0;
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
    	HAL_SPI_Transmit(&hspi1, (uint8_t*) &COMMAND, 1, 100);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
    	HAL_Delay(1);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
    	HAL_SPI_Receive(&hspi1, (uint8_t*) &spi_RX, 1, 100);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
    	uint16_t ANGLEUNC = spi_RX & 0x3FFF;
    	enc.m_angle = (float)ANGLEUNC * (360.0f / 16383.0f);
    	enc.spi_RX = AS5047U_ANGLECOM;

    this is the code that worked for me if you're using AS5047 you should receive the data in the second call

    2 replies

    mƎALLEm
    Technical Moderator
    September 2, 2024

    Both data[] and angle are not updating or just angle?

    "To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
    Associate III
    September 2, 2024

    Both data[] and angle are not updating

    Visitor II
    September 6, 2024

    I also use the ADC DMA function, but the ADC data value does not change in real time for Live Expression, and it stops at the voltage value first measured. I want to know a solution, too.

    kavinkumarAuthorBest answer
    Associate III
    September 6, 2024
    	uint16_t spi_RX=0;
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
    	HAL_SPI_Transmit(&hspi1, (uint8_t*) &COMMAND, 1, 100);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
    	HAL_Delay(1);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
    	HAL_SPI_Receive(&hspi1, (uint8_t*) &spi_RX, 1, 100);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
    	uint16_t ANGLEUNC = spi_RX & 0x3FFF;
    	enc.m_angle = (float)ANGLEUNC * (360.0f / 16383.0f);
    	enc.spi_RX = AS5047U_ANGLECOM;

    this is the code that worked for me if you're using AS5047 you should receive the data in the second call