-
Notifications
You must be signed in to change notification settings - Fork 304
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
Bootcamp: Lily Wang #165
base: master
Are you sure you want to change the base?
Bootcamp: Lily Wang #165
Conversation
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.
Great work so far! Just a few small changes and adding the tx data left
|
||
//adc value is 10 bits so rxData[1] stores 2 MSBs and rxData[2] stores the 8 remaining since data can only be sent in 8 bits | ||
uint16_t adcValue = ((rxData[1]&0x03)<<8 | rxData[2]); | ||
compareValue = (adcValue * maxTimerCounts)/maxADCValue; |
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.
Remember to shift this to be from 5% to 10% of your PWM period
//bring CS to low to select ADC | ||
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | ||
//transmit and receive data from ADC simultaneously | ||
HAL_SPI_TransmitReceive(&hspi1,txData,rxData,2,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.
Since you're sending and receiving 3 bytes, you would need to update the size value
|
||
uint8_t txData[3] = {0}; | ||
uint8_t rxData[3] = {0}; | ||
uint16_t adcValue = 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.
Looks like you redeclare the variable down below
/* USER CODE BEGIN 2 */ | ||
|
||
uint8_t txData[3] = {0}; |
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.
Check out page 21 of https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf to see what value you need to send
uint16_t adcValue = 0x00; | ||
uint16_t compareValue = 0x00; | ||
uint16_t maxTimerCounts = 10000; //Auto-reload register | ||
uint16_t maxADCValue = 1023; //10 bits | ||
/* USER CODE END 2 */ | ||
|
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.
Make sure you call the appropriate HAL PWM start function here (you should be able to find it with a quick google search)
No description provided.