기본프로젝트를 다운로드 받는다. 어디? 여기에!
OpenCR Board Schemetic 에서는 DAC를 사용하기 위하여 회로도를 찾아봤지만 DAC 정보를 찾을수가 없었습니다.
Datasheet 를 이용하여 핀번호를 확인 할 수 있습니다.

DAC 1 번 포트는 40번, DAC 2번 포트는 41번이 있다는것을 확인 했습니다…
저 귀여운놈들(?) 은 무슨놈에 묶여 있을까 회로도를 찾아보았습니다.


회로도를 보면 알겠지만 연구소에는 R1005 사이즈의 칩을 사용하지 않습니다.
그렇기 때문에 R52 저항을 가볍게 날려버리고 DAC 1번을 사용해 보도록 합시다.

프로젝트에 생성되어 있는 cube.ioc 아이콘을 더블클릭합니다.



extern void MX_DAC_Init(void); MX_DAC_Init();



#include "dac.h" DAC_HandleTypeDef hdac; void dacInit(void) { HAL_DAC_Start(&hdac, DAC1_CHANNEL_1); }

#include "hw_def.h" extern HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);

#include <math.h> #define PI 3.141592 #define SAMPLES 200 extern DAC_HandleTypeDef hdac; extern void MX_DAC_Init(void); extern void dacInit(void); uint16_t VI[SAMPLES]; uint16_t value; void apInit(void) { dacInit(); } void apMain(void) { for(int i=0; i<SAMPLES; i++){ value = (uint16_t)rint((sinf(((2*PI)/SAMPLES)*i)+1)*2048); VI[i] = value < 4096 ? value : 4095; } while(1) { for(int i=0; i < SAMPLES; i++){ HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, VI[i]); HAL_Delay(1); } } }
