uint8_t DAC_A_Write = 0x1; // DAC's A output is selected 0 0 0 1
uint16_t DACA_Buf; // Output A of the DAC
short a;
double I;
uint16_t s[512];
uint16_t m=0;
for (I = 0 ; I < 512 ; I++)
{
s[m] = 127+round((sin( I * 6.28/360))/0.02); // 0.02 is the step size
if (m <= 512) m++;
HAL_GPIO_WritePin(DAC_CS_GPIO_Port, DAC_CS_Pin, GPIO_PIN_RESET);
DACA_Buf = DAC_A_Write<<12 | s[m]<<4;
HAL_SPI_Transmit(&hspi2,(uint8_t*)&DACA_Buf,2,100);
HAL_GPIO_WritePin(DAC_CS_GPIO_Port, DAC_CS_Pin, GPIO_PIN_SET);
}