2017-03-12 08:56 AM
I'm sorry in advance for such a stupid question, yet i can't find my error.
I have some chinese nameless 'stm32f103c8t6 system board' with F103C8T6 on board. I also use Coocoox IDE and ST-Link v2 programmer. The following code should blink a led, which is pulled up through 1k resistor. Also pin A1 is giving me only ~1.830 Volts when set to HIGH; however, when i set A1 to LOW it still shows ~1.830 Volts. Other pins are showing zero results. Did i get shady MC or am i missing something?
Also, i don't have oscilloscope, so i can't check what is going on with MCO pin, yet i get ~20-30 mVolts, which is not above ground level.
void InitGPIO()
{ RCC-> APB2ENR |= RCC_APB2ENR_AFIOEN; RCC-> APB2ENR |= RCC_APB2ENR_IOPAEN; GPIOA-> CRL &= ~GPIO_CRL_MODE1; // push-pull output GPIOA-> CRL &= ~GPIO_CRL_CNF1; // led init on pin a1 GPIOA-> CRL |= GPIO_CRL_MODE1_1; // 2mhz output GPIOA-> BSRR |= GPIO_BSRR_BR1; // rst a1 led pin GPIOA-> CRL &= ~GPIO_CRL_MODE2; // push-pull output GPIOA-> CRL &= ~GPIO_CRL_CNF2; // pin a2 GPIOA-> CRL |= GPIO_CRL_MODE2_0; // 10mhz output GPIOA-> BSRR |= GPIO_BSRR_BS2; // set a2 pin
GPIOA-> CRH &= ~GPIO_CRH_MODE8;
GPIOA-> CRH &= ~GPIO_CRH_CNF8; GPIOA-> CRH |= GPIO_CRH_CNF8_1; // af push pull output GPIOA-> CRH |= (GPIO_CRH_MODE8_1 | GPIO_CRH_MODE8_0); // 50mhz output// RCC-> CFGR |= RCC_CFGR_MCO_HSE; // hse clk on mco pin
// RCC-> CFGR |= RCC_CFGR_MCO_PLL; // pll clk on mco pin RCC-> CFGR |= RCC_CFGR_MCO_SYSCLK;// sysclk on mco pin}int main(void)
{ InitGPIO();; while(1) {} return 1;}Solved! Go to Solution.
2017-03-15 06:47 AM
Well, totally my fault here. I should have checked all the reset functions and other ticks in program. If someone would ever fall into such an easy trap, here's the answer for Keil:
Options for Target > Debug > Debugger Settings > Flash Download > 'Reset and Run'.
Thanks for your time, folks.
2017-03-12 09:09 AM
If you are using a debugger, show the HW register and manually edit them. No SW needed to toggle or read a pin level directly by hand. Read the schematic of the board and make sure the pin is the correct one as push pull setting. Check also the memory content such as the Chip ID 96 bit signature content.
2017-03-12 10:41 AM
1. LED is on PC13, you are trying to program PA.
2. Don't use |= when writing to BSRR registers, = is enough
2017-03-15 06:47 AM
Well, totally my fault here. I should have checked all the reset functions and other ticks in program. If someone would ever fall into such an easy trap, here's the answer for Keil:
Options for Target > Debug > Debugger Settings > Flash Download > 'Reset and Run'.
Thanks for your time, folks.