matise
Newbie level 4
- Joined
- Nov 15, 2012
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,321
that dds just doesent work.
Have i done something wrong with my code?
Anyone?
Any ideas?
Have i done something wrong with my code?
Anyone?
Any ideas?
Code:
#include <stm32f10x.h>
#include <stm32f10x_rcc.h>
#include <stm32f10x_gpio.h>
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE); // Enable Peripheral Clocks
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
GPIO_StructInit (& GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 |GPIO_Pin_8 | GPIO_Pin_7 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC , &GPIO_InitStructure);
GPIO_StructInit (& GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
while(1)
{
MM_AD9850_Init();
MM_AD9850_SetFreq();
}
}
void MM_AD9850_Init()
{
/*
Initialize AD9850
PC9 - W_CLK
PC8 - FQ_UD
PC7 - DATA
PC6 - RESET
All output 2Mhz
*/
// UP
GPIO_WriteBit(GPIOC, GPIO_Pin_9 |GPIO_Pin_8 | GPIO_Pin_6, Bit_SET);
//DOWN
GPIO_WriteBit(GPIOC, GPIO_Pin_9 | GPIO_Pin_8 | GPIO_Pin_6, Bit_RESET);
}
void MM_AD9850_SetFreq()
{
int n=0;
char frequency = 0x0A3D70A4; // 5MHz
for (n=0; n<32; n++)
{
// set data pin (2) to 1 or 0
if ((frequency & 0x1) == 1)
{
// set data pin (2) to 1
GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_SET);
}
else
{
// set data pin (2) to 0
GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_RESET);
}
// W_CLK pulse, so AD9850 can shift data in register
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);
// shift one bit...
frequency>>=1;
}
// all 0 for ad9850
GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_RESET);
for (n=0; n<8; n++)
{
// W_CLK pulse, so AD9850 can shift data in register
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);
}
// fq_ud
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET);
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file , uint32_t line)
{
/* Infinite loop */
/* Use GDB to find out why we're here */
while (1);
}
#endif
Last edited by a moderator: