Making Streaming Light with STM32F103C8T6

Catalog 1. Topic Content 2. Download of Project Templates...
1. Familiarity with the interior of the project
2. Adding and Writing Project Files
3. Simulations
1. About the connection method between USB-TTL and board
2. Development Board BOOT Configuration
  3. Driver and burning program

Catalog

1. Topic Content

2. Download of Project Templates

3. Programming

1. Familiarity with the interior of the project

2. Adding and Writing Project Files

3. Simulations

4. Recording of Procedures

1. About the connection method between USB-TTL and board

2. Development Board BOOT Configuration

  3. Driver and burning program

5. Connecting Circuits

6. Operation results  

7. Experience

8. Reference Links

1. Topic Content

The circuit is built with STM32 Minimum System Core Panel (STM32F103C8T6) +Panel+3 red, green and blue LEDs. The LED lights are controlled by three ports: GPIOA, GPIOB and GPIOC, which flash in turn and take one second apart.

2. Download of Project Templates

The project template used here is the "Walnut Electronics" version, which can be downloaded at the following website: http://www.doyoung.net/YT/xx3.html

Download the zipped package in the red box above.  

3. Programming

1. Familiarity with the interior of the project

Unzip the downloaded project template into the corresponding folder.

Open the project and you can see the main function in the main file, where you will call the function you want to use.

2. Adding and Writing Project Files

  First, create a led.c file to store our initialization code.

led.c

#include "led.h" void LED_Init(void){ //Interface initialization of LED lamp GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //Turn on the clock GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //Initialization pin GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //Set output mode, push-pull output mode GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Set Output Rate GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_ResetBits(GPIOA,GPIO_Pin_0); //Define this pin initial value as low level RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_ResetBits(GPIOB,GPIO_Pin_0); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_ResetBits(GPIOC,GPIO_Pin_15); }

The output mode set here is push-pull output mode.

Create another header file led.h function:

led.h

#include "stm32f10x.h" void LED_Init(void);//Initialization

After writing these two files, save them and import them into our project as follows:

Double-click the Hardware folder in the left project bar and find the led.c file we just saved. Click add

Writing main functions  :

main.c

#include "stm32f10x.h" #include "delay.h" #include "led.h" int main (void){//main program RCC_Configuration(); //Clock Settings LED_Init(); while(1){ GPIO_SetBits(GPIOA,GPIO_Pin_0); //This is to set the IO port to high level, which is 3.3V delay_ms(500); GPIO_ResetBits(GPIOA,GPIO_Pin_0);//This is to set the IO port to low level or 0V delay_ms(500); GPIO_SetBits(GPIOB,GPIO_Pin_0); //This is to set the IO port to high level, which is 3.3V delay_ms(500); GPIO_ResetBits(GPIOB,GPIO_Pin_0);//This is to set the IO port to low level or 0V delay_ms(500); GPIO_SetBits(GPIOC,GPIO_Pin_15); //This is to set the IO port to high level, which is 3.3V delay_ms(500); GPIO_ResetBits(GPIOC,GPIO_Pin_15);//This is to set the IO port to low level or 0V delay_ms(500); } }

3. Simulations

Before starting the simulation, you need to configure keil in a series of configurations, click on the "fairy stick", then select the software simulator in the Debug option, and change the following settings to the corresponding chip.  

Run the simulation again, call up the logical window, add the pin number you need to see in the logical window.  

Click setup to add the corresponding pin number.

Click Add Document Number and enter the pin number you want to see, for example: porta.0

Start the simulation, get the results, and observe the simulated waveform.  

4. Recording of Procedures

  After writing the program, you need to burn the program into the board. At this time, you need to use special burning hardware and software. Hardware is USB to TTL, which is used for PC and board connection. Software is Fly MCU and CH340 driver, which can be downloaded by searching directly on CSDN. Install it.  

1. About the connection method between USB-TTL and board

Now looking closely at the USB-TTL and the board, you can see that there are five pins on the USB-TTL body, which are 5V power pin, 3.3V power pin, TXD (Data Transfer) pin, RXD (Data Receive) pin and GND pin. To connect the PC to the board, the corresponding pins are connected, that is, the TXD of the board connects the RX of the USB-TTL and the RXD connects the TX.
  After querying the data of STM32F103C8T6, we can find that PA9 corresponds to TX and PA10 to RX.


  So the corresponding relationship is:

PA9---RXD

PA10---TXD

You can also plug it directly into the breadboard for burning, just connect the lines.

2. Development Board BOOT Configuration

Note that there are two jumper caps on the board, BOOT0 and BOOT1. Before burning the program, the mode BOOT0 and BOOT1 must be changed to the system memory mode.  

That is, BOOT0 needs to be short-joined to 3.3V with jumper cap, and BOOT1 needs to be short-joined to GND with jumper cap, as shown in Fig.

  3. Driver and burning program

After installing the CH340 driver, you can find the corresponding connected device in the Device Manager:

Now you just need to turn on FlyMCU for some configuration before you can burn it. The configuration is as follows:

Click Start Programming to burn.  

Note: Press the RESET button on the board before each burn starts, otherwise the burn may not go in.

5. Connecting Circuits

After burning the program, you can connect the circuit. According to the diagram above, we can see that our LED lights are common, so we need to pull the GND from the board to the negative of the breadboard.

6. Operation results  

7. Experience

      Compared to the 51 single-chip computers that we came into contact with when we first started learning single-chip computers, 32 single-chip computers have more powerful functions and can enable us to achieve more functions. When writing 32 programs, we need to initialize the corresponding functions according to our own needs in order to work properly. Only with more practice can we use them correctly.

8. Reference Links

Making Streaming Light with STM32F103C8T6_ Blog for txmnQAQ - CSDN Blog


23 October 2021, 12:41 | Views: 4209

Add new comment

For adding a comment, please log in
or create account

0 comments