Skip to content

Conversation

@AlyanSal
Copy link

No description provided.

uint8_t rx[3];

tx[0] = 0x01;
tx[1] = 0x90;

Choose a reason for hiding this comment

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

The transmit values are incorrect, recheck the ADC documentation for the crrect configuration!


tx[0] = 0x01;
tx[1] = 0x90;
tx[2] = 0x00;

Choose a reason for hiding this comment

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

I would also suggest having lines 64 to 69 (variable declarations and initializations) be outside of this function because their values are unchanging throughout the while loop.


HAL_GPIO_WritePin(CS_GPIO_PORT, CS_PIN, GPIO_PIN_RESET);

HAL_SPI_TransmitReceive(&hspi1, tx, rx, 3, HAL_MAX_DELAY);

Choose a reason for hiding this comment

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

  • Use the error value returned from the TransmitReceive function to determine whether to continue with the rest of the code or not.
  • Size must be in bytes and dependent on your tx size. sizeof(tx) ensures this.
  • Assign the size to a variable -- no magic numbers! Improves readability.

while (1)
{
uint16_t adc_val = ADC_Read();
uint16_t PWM_val = 3200 + (adc_val * 3200) / 1023;

Choose a reason for hiding this comment

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

  • Variable declarations should not be looped unnecessarily. Declare them outside of the while loop!
  • Refer to previous comment on magic numbers.

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