-
Notifications
You must be signed in to change notification settings - Fork 406
BOOTCAMP: Alyan #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
BOOTCAMP: Alyan #251
Conversation
| uint8_t rx[3]; | ||
|
|
||
| tx[0] = 0x01; | ||
| tx[1] = 0x90; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
No description provided.