前几天刚收到彩云姐快递来的STM32,申通短信一到,就激动呀,终于到了(其实从申请到拿到板子也就历史5天左右吧,可能太期待的缘故,呵呵)不过,板子的确漂亮,好多大大都拍了照片,偶没相机,手机的像素也就13W,垃圾得很,就不献丑了。
最近一直在考试,而且还要稍微花点时间筹备9.8的省电子设计大赛。所以,要花点点时间在那边,这么一算,这段时间几乎没啥时间整STM32。
今天周末,又是四六级,伤心啊,四级还没过。下学期要努力了,唯一一次机会过四级了。
来到实验室,拿出了STM32板板,这个漂亮啊,哈哈。突然就想玩玩它了,说实话哦,刚开始俺还真不知道怎么下载程序^_^
不过,整捣着也就会了。软件默认安装,特别是驱动,改了路径之后麻烦。
---------------------------------------------------------------------------------
好了,废话就到此为止,STM32板的学习也将会在考试结束后陆续地进入状态了。
今天给自己这两天布置的任务是,熟悉IAR编程环境,已经了解STM32的编程结构和语言。
最简单的嘛,就是点亮一盏灯,然后再加强一下,流水等啊什么的。
———————下面将记录我的学习笔记^_^——————————————
先给上完整程序,等下午回来写注释等。
完整程序:
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
int chuan;
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
vu32 ret; /* for return of the interrupt handling */
int s;
volatile TestStatus TestRx;
/* Private functions ---------------------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void Led_RW_ON(void);
void Led_RW_OFF(void);
void delay(void);
void delay()
{
int i,j;
for (j=0; j<0x00003; j++)
for (i=0; i<0xfffff; i++) ;
}
EXTI_InitTypeDef EXTI_InitStructure;
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
RCC_Configuration();
GPIO_Configuration();
while(1){
delay();
Led_RW_ON();
}
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
/* RCC system reset(for debug purpose) */
// RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* ADCCLK = PCLK2/6 */
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 4MHz * 9 = 36 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
/* TIM2 clocks enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* CAN Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure PC.04 -- PC.11 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7
| GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure PD.03, PC.04, PC.11 -- PC.15 as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_11 | GPIO_Pin_12 |
GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure CAN pin: RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure CAN pin: TX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* CAN pin remap to PD0/PD1 */
GPIO_PinRemapConfig(GPIO_Remap2_CAN,ENABLE);
/* Configure PE.00 -- PE.15 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
void Led_RW_ON(void)
{
if(chuan==0){
Led_RW_OFF();
GPIO_SetBits(GPIOC, GPIO_Pin_4);
chuan++;}
else if(chuan==1){
Led_RW_OFF();
GPIO_SetBits(GPIOC, GPIO_Pin_5);
chuan++;}
else if(chuan==2){
Led_RW_OFF();
GPIO_SetBits(GPIOC, GPIO_Pin_6);
chuan++;}
else if(chuan==3){
Led_RW_OFF();
GPIO_SetBits(GPIOC, GPIO_Pin_7);
chuan="0";}
}
void Led_RW_OFF(void)
{
GPIO_ResetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_4 | GPIO_Pin_5);
}
用户225144 2009-5-14 14:16