cancel
Showing results for 
Search instead for 
Did you mean: 

Moved correct code doesn´t work

j3lda
Associate II
Posted on March 24, 2013 at 14:39

Hello, I have really strange problem.

1) I have correct working code placed in main() function (for example for generating DC signal). It is working, but when I move this part of code into some function for example generateDC(), it doesn´t generate anything. My code has about 20 kB. Is it possible that there is some problem with memory or ST-link? (wrong setted memory in target options)

2) Or I have function generateDC() in file main.c and it works. But when I move this function into another file on row 400, it doesnt work.

 Thank you for answeres.

Only for information I use STM32F3 Discovery kit.
5 REPLIES 5
frankmeyer9
Associate II
Posted on March 24, 2013 at 16:11

Where is your code ?

My kid dropped the magic crystal ball yesterday, so I can't do remote viewing ...

Have you tried to debug the ''nonworking'' code ?

Or is already the compiler bailing out ?

j3lda
Associate II
Posted on March 24, 2013 at 16:37

Yes, I debug this code and everything looks fine, only it isn´t generate anything.

My code is:

// file: main.c

int main(void)

{

  genDC(void);

}

// in file: main.c it works (generate 3V), in another file it doesnt work (not generate DC)

void genDC(void)

{

  DAC_InitTypeDef   DAC_InitStructure;

  GPIO_InitTypeDef   GPIO_InitStructure;

  

   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

   GPIO_Init(GPIOA, &GPIO_InitStructure);

   DAC_DeInit();

   DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;

   DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;

   DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;

   DAC_Init(DAC_Channel_1, &DAC_InitStructure);

 

   DAC_SetChannel1Data(DAC_Align_12b_R, 0xFFF);

   DAC_Cmd(DAC_Channel_1, ENABLE);

       

}

Posted on March 24, 2013 at 17:28

Perhaps you should also illustrate how this gets called in the condition it fails to work in? You could also perhaps use a printf() to indicate it was actually called, or assert another LED/GPIO. If it's not even being called you'll need to consider why?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
crt2
Associate II
Posted on March 25, 2013 at 14:02

Are you sure this compiles?

// file: main.c
int main(void)
{
genDC(void); //<--- This here looks wrong and compiler should complain. Check how functions are called in C?
}

dthedens23
Associate II
Posted on March 25, 2013 at 22:00

yea, and there is no while(1)

loop in main() so main() will execute ONCE, then return to what?