OM5MI homepage

HY-STM32_100P - STM32F103VET6 - Cortex M3

Received this cheap dev board with STM32F103VET6 MCU(ARM Cortex M3) from ebay. Some code examples are bellow. Feel free to use it in your project.

STM32 and AD9850

void MM_AD9850_Init()
{
	/*
		Initialize AD9850
	  	PA0 - W_CLK
		PA1 - FQ_UD
		PA2 - DATA
		PA3 - RESET
		All output 2Mhz
	*/
	
	// enable GPIOA
	RCC->APB2ENR = RCC_APB2ENR_IOPAEN;
	
	// set pin as output, 2Mhz
	GPIOA->CRL = GPIO_CRL_MODE0_1 | GPIO_CRL_MODE1_1 | GPIO_CRL_MODE2_1 | GPIO_CRL_MODE3_1;
	
	// enable serial mode (datasheet page 12 figure 10)
	// UP
	GPIOA->BSRR = 1<<3 | 1<<0 | 1<<1;
	//DOWN
	GPIOA->BRR = 1<<3 | 1<<0 | 1<<1;
}

void MM_AD9850_SetFreq(unsigned int frequency)
{
	int n=0;
	// frequency calc from datasheet page 8 =  * /2^32
	// AD9850 has 125Mhz clock
	frequency = (frequency * 4294967296) / 125000000;  
		
	for (n=0; n<32; n++)
	{
    		// set data pin (2) to 1 or 0
		if ((frequency & 0x1) == 1)
		{
			// set data pin (2) to 1
			GPIOA->BSRR = 1<<2;
		}
		else
		{
			// set data pin (2) to 0
			GPIOA->BRR = 1<<2;
		}
		
		// W_CLK pulse, so AD9850 can shift data in register
		GPIOA->BSRR = 1<<0;
		GPIOA->BRR = 1<<0;
		
		// shift one bit...
		frequency>>=1;
  	}
	
	// all 0 for ad9850
	GPIOA->BRR = 1<<2;
	for (n=0; n<8; n++)
	{
  		// W_CLK pulse, so AD9850 can shift data in register
		GPIOA->BSRR = 1<<0;
		GPIOA->BRR = 1<<0;
	}
	
	// should be done
	GPIOA->BSRR = 1<<1;
	GPIOA->BRR = 1<<1;
}


int main(void)
{	
	...
	...
	...

	MM_AD9850_Init();
	MM_AD9850_SetFreq(10000000);

	...
	...
	...
}