STM32F103C8T6 ARM Development Board Documentation
The STM32F103C8T6 is a popular ARM-based microcontroller development board, part of the STM32 family of 32-bit microcontrollers from STMicroelectronics. This board is widely used in IoT projects, robotics, and embedded system applications due to its high performance, low power consumption, and rich peripheral set.
Cortex-M3 32-bit RISC processor with 64 KB of Flash memory and 20 KB of SRAM
Operating frequency up to 72 MHz
12-bit ADC with 16 channels
2 x 12-bit DAC
3 x USART, 2 x UART, 2 x SPI, 2 x I2C, 1 x I2S, 1 x CAN
3 x Timers, 1 x Watchdog timer, 1 x RTC
USB 2.0 FS device, SD/MMC interface
Power management: 2.0 V to 3.6 V power supply, low power modes
### Example 1: Blinking LED using GPIO
In this example, we will use the GPIO peripheral to blink an LED connected to pin PA5.
STM32F103C8T6 development board
LED
Resistor (1 k)
Breadboard and jumper wires
Keil Vision IDE or STM32CubeMX
ARM GCC compiler
Code
```c
#include "stm32f10x.h"
int main(void)
{
// Initialize GPIOA peripheral
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
// Configure PA5 as output
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);
while (1)
{
// Set PA5 high (LED on)
GPIO_SetBits(GPIOA, GPIO_Pin_5);
delay(500); // 500 ms delay
// Set PA5 low (LED off)
GPIO_ResetBits(GPIOA, GPIO_Pin_5);
delay(500); // 500 ms delay
}
}
void delay(uint32_t time)
{
volatile uint32_t i;
for (i = 0; i < time; i++);
}
```
Explanation
We first enable the GPIOA peripheral clock using the `RCC_AHBPeriphClockCmd` function.
We then configure PA5 as an output using the `GPIO_Init` function.
In the main loop, we toggle the state of PA5 using the `GPIO_SetBits` and `GPIO_ResetBits` functions, which control the LED connected to this pin.
The `delay` function is used to introduce a 500 ms delay between each toggle operation.
### Example 2: UART Communication using USART1
In this example, we will use the USART1 peripheral to send and receive data over the serial interface.
STM32F103C8T6 development board
Serial terminal software (e.g., PuTTY)
USB-to-TTL serial adapter (e.g., FT232R)
Keil Vision IDE or STM32CubeMX
ARM GCC compiler
Code
```c
#include "stm32f10x.h"
int main(void)
{
// Initialize USART1 peripheral
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
// Configure USART1 as asynchronous mode
USART_InitTypeDef USART_InitStruct;
USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStruct);
while (1)
{
char buff[10];
// Receive data from serial terminal
USART_ReceiveData(USART1, (uint16_t)buff);
// Process received data
printf("Received: %s
", buff);
// Send response back to serial terminal
USART_SendData(USART1, (uint16_t )"Hello, STM32!
");
delay(1000); // 1 second delay
}
}
void delay(uint32_t time)
{
volatile uint32_t i;
for (i = 0; i < time; i++);
}
```
Explanation
We first enable the USART1 peripheral clock using the `RCC_APB2PeriphClockCmd` function.
We then configure USART1 as an asynchronous mode using the `USART_Init` function.
In the main loop, we receive data from the serial terminal using the `USART_ReceiveData` function and process it.
We then send a response back to the serial terminal using the `USART_SendData` function.
The `delay` function is used to introduce a 1 second delay between each transmission.
These examples demonstrate the basic usage of the STM32F103C8T6 development board's GPIO and USART peripherals. You can build upon these examples to create more complex IoT projects using this board.