Skip to content

Conversation

@ApilaashY
Copy link

No description provided.


/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
#define MIN_DUTY_TIME 0.05
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid using floats as best as you can

// Setup bits for ADC
SPI_TX[0] = 0b00000001;
SPI_TX[1] = 0b10000000;
SPI_TX[2] = 0b00000000;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be in the loop?

ADC_Value = (SPI_RX[1] & 0b00000011 << 8) | SPI_RX[2];

// Converts the ADC value into an appropriate value to set the register
Register_Value = MIN_DUTY_TIME + (ADC_Value / MAX_ADC_VALUE) * (MAX_DUTY_TIME-MIN_DUTY_TIME);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't mesh with what you defined the MAX and MIN duty time constants to be



// Set the CS pin to low
HAL_GPIO_WritePin(CS_PIN_GPIO_Port, CS_PIN_Pin, 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved a bit up in your program

while (1)
{
// Set the CS pin to high
HAL_GPIO_WritePin(CS_PIN_GPIO_Port, CS_PIN_Pin, 1);
Copy link

@dechair3 dechair3 Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is how you initiate a SPI data transfer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants