Dear all
I recently start programming STM32F103VB Arm based MCU, writing simple blinking led on my own HW for testing. it was OK, but i feel something goes wrong, for the reason writing so simple codes to test the outputs of mcu as follows:
#define ch1_led 8 void set_ports(void) { GPIO_PortClock(GPIOA,ENABLE); GPIO_PortClock(GPIOB,ENABLE); GPIO_PortClock(GPIOC,ENABLE); GPIO_PortClock(GPIOE,ENABLE); GPIOA->CRH &= ~(0xFul); // Set Port A.8 as USB_Mode Select GPIOA->CRH |= (0x1ul); // Output 10 Mhz PushPull Delay(1); GPIOB->CRH &= ~(0xFFul<<20); // Set Port B.13 as Sck and B13 as MISO GPIOB->CRH |= (0x83ul<<20); // Set Otput 50 Mhz PushPull for port B13 // Input for B14 GPIOB->ODR |= (1ul<<14); // Set Pullup input for Port B.14 GPIOB->BSRR |= (1ul<<29); // Set Sck to high GPIOC->CRL &= (0xFFul<<16); // Set Port C.0/C.1/C.2/C.3 as Channels LED and // C.6/C.7 as A2D C.S. and Fo Mode GPIOC->CRL |= (0x11001111ul); // Output 10 Mhz PushPull GPIOC->BSRR = (0x11ul<<6); // Set C.6 to disable A2D (CS Active Low) C.7 // to High Means Fo=50Hz GPIOC->CRH &= ~(0xFFul); // Set Port C.8 as A2d Gain and C.9 as USB LED GPIOC->CRH |= (0x11ul); // Output 10 Mhz PushPull GPIOE->CRH &= ~(0xFFFFul); // Set Port E.8/E.9/E.10/E.11 as MUX Selector GPIOE->CRH |= (0x1111ul); // Output 10 Mhz PushPull } void led_on(int ch) { unsigned long led; led=ch; GPIOC->BSRR=led; } int main(void) { SystemInit(); SystemCoreClockSetHSI(); SystemCoreClockUpdate(); set_ports(); led_on(ch1_led); while (1); }
it should turn on the led for ever but a 4 ms glitch on output with period of about 425 ms makes the led blink invisibly. does anyone could explain me why and how could prevent of such a glitches ?
best regards