The sample code does not work on STM32F103C6

Viewed 29

experts. I am new to STM32. So I downloaded some sample code from github. https://github.com/yohanes-erwin/stm32f103-keil And I download the simple led blinking code of it to the STM32F103C6 developing board but it doesn't work at all. The original program embedded on the chip had been erased successfully ( originally the led was always on and LCD screen shows some text, but now after I download the code, the led is off and screen off. So I think the downloading is successful.) but the code does not work. When I download the original code to the chip, it works again. So I think the chip isn't broken. I think it's because of compatibility of sample code and my chip. The sample code was written for STM32F103C8. But it was a very simple code. What is the reason? Here is the code.

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"

void delay(unsigned int nCount);

GPIO_InitTypeDef GPIO_InitStruct;

int main (void)
{
    // Enable clock for GPIOA
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    
    // Configure PA4 as push-pull output
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &GPIO_InitStruct);
    
    while (1)
    {
        /* Toggle LED on PA0 */
        // Reset bit will turn on LED (because the logic is interved)
        GPIO_ResetBits(GPIOA, GPIO_Pin_4);
        delay(1000);
        // Set bit will turn off LED (because the logic is interved)
        GPIO_SetBits(GPIOA, GPIO_Pin_4);
        delay(1000);
    }
}

// Delay function
void delay(unsigned int nCount)
{
    unsigned int i, j;
    
    for (i = 0; i < nCount; i++)
        for (j = 0; j < 0x2AFF; j++);
}
0 Answers
Related