uranyumx
Advanced Member level 4
Hello guys,
Now I try to generate a sine wave with STM32F7 microprocessor with using external 8 bit DAC (DAC082S085). The microprocessor and DAC is communicated each other with SPI transmit only master mode. Now, there is a generated sine wave which looks like an interrupted shape. Do you have any idea to solve this problem?
Thank you,
Here is my code:
Now I try to generate a sine wave with STM32F7 microprocessor with using external 8 bit DAC (DAC082S085). The microprocessor and DAC is communicated each other with SPI transmit only master mode. Now, there is a generated sine wave which looks like an interrupted shape. Do you have any idea to solve this problem?
Thank you,
Here is my code:
Code:
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);
}