Bootcamp: SEAN WANG#285
Conversation
EemanAleem
left a comment
There was a problem hiding this comment.
Mostly correct, great job!!!
| adc_value = MAX_ADC; | ||
|
|
||
| /* USER CODE END 1 */ | ||
| uint16_t pwm_range = MAX_PWM - MIN_PWM; |
There was a problem hiding this comment.
Would suggest having this just predefined as a global var since you're deriving another constant from two constants.
| // Multiply before divide to avoid truncating to 0 | ||
| uint16_t ccr_value = | ||
| MIN_PWM + | ||
| (adc_value * pwm_range) / MAX_ADC; |
There was a problem hiding this comment.
Make sure to protect against integer division in abstracted calculations! Your calculation itself is correct tho, congrats :)
| &hspi1, | ||
| tx_buffer, | ||
| rx_buffer, | ||
| 3, |
There was a problem hiding this comment.
Make sure to not have magic numbers and allot a variable to this, or just have it depend on the size of your tx or rx buffers, upto you.
| tx_buffer, | ||
| rx_buffer, | ||
| 3, | ||
| HAL_MAX_DELAY |
There was a problem hiding this comment.
This is incorrect as this has a value of 0xFFFFFFFF, which effectively works as a poll until the process is successful. This is not beneficial since we'd like to timeout of the process if it doesn't work for a set period of time, say 100ms. You may assign a var for this too.
| rx_buffer, | ||
| 3, | ||
| HAL_MAX_DELAY | ||
| ); |
There was a problem hiding this comment.
Use the output of the HAL_SPI_TransmitReceive function to output whether the process was successful and move forward, or report the alternative output you get with a simple print statement.
Bootcamp: SEAN WANG
| HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | ||
|
|
||
| if (status != HAL_OK) | ||
| continue; |
There was a problem hiding this comment.
This if condition effectively achieves nothing lol, you need to either have everything from the HAL_GPIO_WritePin onwards in the if statement itself, otherwise it doesn't execute any other code. A print statement of some kind is usually useful here.
Done yo