2013-03-24 06:39 AM
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.2013-03-24 08:11 AM
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 ?2013-03-24 08:37 AM
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); }2013-03-24 09:28 AM
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?
2013-03-25 06:02 AM
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?
}
2013-03-25 02:00 PM
yea, and there is no while(1)
loop in main() so main() will execute ONCE, then return to what?