cancel
Showing results for 
Search instead for 
Did you mean: 

AS5047 SPI live expression not updating

kavinkumar
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
	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

View solution in original post

4 REPLIES 4
SofLit
ST Employee

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.

Both data[] and angle are not updating

GB_ST
Associate

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.

	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