STM32F130C8T6(Cortex-M0)
(feat. TDCR1050M FND)
๋ชฉ์ฐจ
๐ SEGGER ์์ ๋ง๋ J-LINK EDU๋ฅผ ์ฌ์ฉํ์ฌ ํ์จ์ด ๋ค์ด๋ก๋๋ฅผ ์งํํ์๋ค.
๋ณด๋์์ ์ฐ๊ฒฐ์ SWDIO, SWCLK, RESET, VCC, GND ํ๋ง์ ์ฐ๊ฒฐํ์๋ค.
์๋ J-LINK Pin map ์ฐธ์กฐ.
Keil uVison V5.17.0.0 ์ ์ฌ์ฉํ์์ผ๋ฉฐ Target ์ต์ ์์ Debug ํญ ์ต์ ์ ์๋์ ๊ฐ์ด J-LINK PORT๋ฅผ SW๋ก ๋ณ๊ฒฝํ๋ค.
Flash Download ์ต์ ์์๋ ๋ค์ด๋ก๋ ํ๊ฒ ๋๋ฉด ์๋์ผ๋ก ๋์์ํฌ์ง๋ฅผ ๊ฒฐ์ ํ๋ Reset and Run ์ต์ ์ ์ฒดํฌํ๋ค.
๐ GPIO ์ฌ์ฉ ํ์ PB0~PB7 ๊น์ง ์ฐจ๋ก๋๋ก FND์ A~DP์ ์ฐ๊ฒฐ ํ๊ณ , PB12~PB15 ๊น์ง ์ฐจ๋ก๋๋ก FND D1~D4 ๊น์ง ์ฐ๊ฒฐํ์๋ค.
STM32F130 Pinout
TDCR1050M Pinout
๐ GPIO ์ด๊ธฐํ๋ฅผ ํ๊ณ FND๋ฅผ ์ปจํธ๋กค ํ๋ ค๋ค ๋ณด๋ D, E ํ๋ง ์ ํธ๊ฐ ๋ณํ์ง ์์๋ค.
์ด์ ๋ฅผ ์ดํด๋ณด๋ FND D, E ํ์ ์ฐ๊ฒฐ ๋์ด ์๋ PB3, PB4 ํ์ JTAG์ Debug์ ๊ด๋ จ๋ ํ์ผ๋ก ์ฌ์ฉ๋๊ณ ์์๋ค.
PB3, PB4 ํ์ GPIO ํ์ผ๋ก ์ฌ์ฉํ๊ธฐ ์ํด์๋ ์๋์ ์์ค์ ๊ฐ์ด GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ํ์ ๋ฆฌ๋งต์ํจ๋ค.
ํ๋ฆฌ๋งต์ ํ๊ธฐ ์ํด์๋ RCC_APB2Peripg_AFIO
ํ์ฑํ๊ฐ ํ์ํ๋ค.
gpio.c
๊ธฐ๋ณธ์ ์ผ๋ก LOW ์ ํธ์ FND๊ฐ ๋์ํ๋ฉฐ D1~D4 ๋ FND์ ์๋ฆฌ๋ฅผ ๋ํ๋ธ๋ค.
A~DP๋ ์ซ์๋ฅผ ํํํ๋ ๊ฐ ๋ณ์ ์๋ฏธํ๋ค. ์๋๋ฅผ ๊ทธ๋ฆผ์ ์ฐธ๊ณ .
TDCR1050M FND๋ฅผ ์ ์ดํ๋ ์์ค์ฝ๋๋ ์๋์ ๊ฐ๋ค.
FND_write(ENUM_DIGIT digit, uint32_t value)
ํจ์์ ์๋ฆฌ ์์น์ ๊ฐ์ ์ธ์๋ก ์ฃผ๋ฉด ๋์ํ๋ค.
TDCR1050M.h
#ifndef __TDCR1050M_H__
#define __TDCR1050M_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f10x.h" /* Device header */
typedef enum
{
DIGIT_1 = 1,
DIGIT_2,
DIGIT_3,
DIGIT_4
}ENUM_DIGIT;
/* FND LED NUMBER POSITION */
#define D1 0x1000
#define D2 0x2000
#define D3 0x4000
#define D4 0x8000
#define FND_A 0x0001 /* TOP */
#define FND_B 0x0002 /* TOP RIGHT */
#define FND_C 0x0004 /* BOTTOM RIGHT */
#define FND_D 0x0008 /* BOTTOM */
#define FND_E 0x0010 /* BOTTOM LEFT */
#define FND_F 0x0020 /* TOP LEFT */
#define FND_G 0x0040 /* MID */
#define FND_DP 0x0080 /* BOTTOM DOT */
#define FND_ALL (FND_A|FND_B|FND_C|FND_D|FND_E|FND_F|FND_G)
void FND_Init(void);
void FND_Write(ENUM_DIGIT digit, uint32_t value);
#ifdef __cplusplus
}
#endif
#endif /* __TDCR1050M_H__ */
TDCR1050M.c
#include "TDCR1050M.h"
#include "stm32f10x_gpio.h" /* Keil::Device:StdPeriph Drivers:GPIO */
static void FND_WriteNum(uint32_t value);
void FND_Init(void)
{
GPIO_WriteBit(GPIOB, D1, Bit_SET);
GPIO_WriteBit(GPIOB, D2, Bit_SET);
GPIO_WriteBit(GPIOB, D3, Bit_SET);
GPIO_WriteBit(GPIOB, D4, Bit_SET);
}
void FND_Write(ENUM_DIGIT digit, uint32_t value)
{
FND_Init();
switch(digit)
{
case DIGIT_1:
GPIO_WriteBit(GPIOB, D1, Bit_RESET);
break;
case DIGIT_2:
GPIO_WriteBit(GPIOB, D2, Bit_RESET);
break;
case DIGIT_3:
GPIO_WriteBit(GPIOB, D3, Bit_RESET);
break;
case DIGIT_4:
GPIO_WriteBit(GPIOB, D4, Bit_RESET);
break;
default: break;
}
FND_WriteNum(value);
return ;
}
static void FND_WriteNum(uint32_t value)
{
GPIO_WriteBit(GPIOB, FND_ALL, Bit_SET);
switch(value)
{
case 0:
GPIO_WriteBit(GPIOB, FND_A | FND_B | FND_C | FND_D | FND_E | FND_F, Bit_RESET);
break;
case 1:
GPIO_WriteBit(GPIOB, FND_B | FND_C, Bit_RESET);
break;
case 2:
GPIO_WriteBit(GPIOB, FND_A | FND_B | FND_D | FND_E | FND_G, Bit_RESET);
break;
case 3:
GPIO_WriteBit(GPIOB, FND_A | FND_B | FND_C | FND_D | FND_G, Bit_RESET);
break;
case 4:
GPIO_WriteBit(GPIOB, FND_B | FND_C | FND_F | FND_G, Bit_RESET);
break;
case 5:
GPIO_WriteBit(GPIOB, FND_A | FND_C | FND_D | FND_F | FND_G, Bit_RESET);
break;
case 6:
GPIO_WriteBit(GPIOB, FND_A | FND_C | FND_D | FND_E | FND_F | FND_G, Bit_RESET);
break;
case 7:
GPIO_WriteBit(GPIOB, FND_A | FND_B | FND_C | FND_F, Bit_RESET);
break;
case 8:
GPIO_WriteBit(GPIOB, FND_A | FND_B | FND_C | FND_D | FND_E | FND_F | FND_G, Bit_RESET);
break;
case 9:
GPIO_WriteBit(GPIOB, FND_A | FND_B | FND_C | FND_F | FND_G, Bit_RESET);
break;
default: break;
}
}
FND์ ํน์ฑ์ ํ์๋ฆฌ์ฉ ๋ฐ๋ณตํด์ ํํํด์ผ ํจ์ผ๋ก ๋ณ๋์ Thread๋ฅผ ๋ง๋ค์ด 4์๋ฆฌ์ ์ซ์๋ฅผ ๊ฐ ์๋ฆฌ์ ๋ณ๋ก ๋ฐ๋ณตํด์ ํํํ๋๋ก ํ์๋ค.
Keil5์์ Thread๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ Manage Run ์์ CMSIS < RTOS(API) < Keil RTX๋ฅผ ํ์ฑํ ํด์ค๋ค.
Thread ์ ์ฒด ์ฝ๋๋ ์๋์ ๊ฐ๋ค.
Thread.h
#ifndef __THTREAD_H__
#define __THTREAD_H__
#ifdef __cplusplus
extern "C" {
#endif
int Init_Thread(void);
#ifdef __cplusplus
}
#endif
#endif /* __THTREAD_H__ */
Thread.c
#include "thread.h"
#include "cmsis_os.h" // ARM::CMSIS:RTOS:Keil RTX
#include "TDCR1050M.h"
uint32_t timeValue;
void Thread_FND(void const *argument); // thread function
osThreadId tid_Thread_FND; // thread id
osThreadDef(Thread_FND, osPriorityNormal, 1, 0); // thread object
int Init_Thread(void)
{
tid_Thread_FND = osThreadCreate(osThread(Thread_FND), NULL);
if (!tid_Thread_FND) return(-1);
return (0);
}
void Thread_FND(void const *argument)
{
uint32_t temp = 0;
uint32_t timeValueTemp = 0;
volatile uint32_t delay = 0;
while(1)
{
timeValueTemp = timeValue;
osSignalWait(1U, 0); // Wait for signal
temp = timeValueTemp / 1000;
FND_Write(DIGIT_1, temp);
osDelay(1);
timeValueTemp %= 1000;
temp = timeValueTemp / 100;
FND_Write(DIGIT_2, temp);
osDelay(1);
timeValueTemp %= 100;
temp = timeValueTemp / 10;
FND_Write(DIGIT_3, temp);
osDelay(1);
timeValueTemp %= 10;
FND_Write(DIGIT_4, timeValueTemp);
osDelay(1);
}
}
๐ FND STOP, START, RESET ์ปจํธ๋กค์ ์ํด ์ค์์น๋ฅผ PA5~PA7ํ์ ๊ฐ๊ฐ ์ฐ๊ฒฐํ์๋ค.
gpio.c
๐ main()
ํจ์์์๋ ์ปค๋ ๋ฐ Thread ์ด๊ธฐํ, PORTA, PORTB๋ฅผ ์ด๊ธฐํ๋ฅผ ์ํจํ ์ธ๋ถ ์ธํฐ๋ฝํธ์์ํด ๋ณํ๋๋ ์ ์ญ๋ณ์ ๊ฐ์๋ฐ๋ผ FND ๊ฐ์ 0~9999๊น์ง 1์ด๋ง๋ค ์นด์ดํ
ํ๊ฑฐ๋ RESET ๋๋ STOPํ๋ ๋์์ ํ๋ค.
#include <stdio.h>
#include "stm32f10x.h" /* Device header */
#include "stm32f10x_exti.h" /* Keil::Device:StdPeriph Drivers:EXTI */
#include "gpio.h"
#include "thread.h"
#include "cmsis_os.h" /* ARM::CMSIS:RTOS:Keil RTX */
#include "TDCR1050M.h"
#define STOP 3
extern osThreadId tid_Thread_FND;
extern uint32_t timeValue;
char irq_Status;
void EXTI9_5_IRQHandler(void);
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5) != RESET) { /* STOP */
irq_Status = STOP;
EXTI_ClearITPendingBit(EXTI_Line5);
}
else if(EXTI_GetITStatus(EXTI_Line6) != RESET) { /* START */
irq_Status = SET;
EXTI_ClearITPendingBit(EXTI_Line6);
}
else if(EXTI_GetITStatus(EXTI_Line7) != RESET) { /* RESET */
irq_Status = RESET;
EXTI_ClearITPendingBit(EXTI_Line7);
}
}
int32_t main(void)
{
timeValue = 0;
irq_Status = RESET;
osKernelInitialize();
Init_Thread();
PORTA_Init();
PORTB_Init();
FND_Init();
osKernelStart();
SysTick_Config(SystemCoreClock / 1000);
while(1)
{
if(irq_Status == SET) {
osSignalSet(tid_Thread_FND, 1U);
osDelay(1000);
if(timeValue < 9999) {
timeValue++;
}
else {
timeValue = 0;
}
}
else if(irq_Status == RESET) {
timeValue = 0;
osDelay(1);
}
else {
osDelay(1);
}
}
return (0);
}
์ ๋ ธ๋์ ์บ์๋ ์ฐจ์ด์ (Anode Cathod) (0) | 2019.02.20 |
---|---|
Open103V(STM32F103VET) ๋นํธ๋งต ํ์ผ ๋ค๋ฃจ๊ธฐ (0) | 2019.02.01 |
nRF51422-QFAB(GPIO/ADC) (0) | 2018.11.01 |
MPU-9250 Module (2) | 2016.12.12 |
PLM-100 RF Module (6) | 2016.12.12 |