




已阅读5页,还剩27页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
STM32各种函数的基本配置(功能是摄像头采集数据SD存储)/*#include stm32f4_discovery.h#include stm32f4xx_conf.h uint32_t Gb_TimingDelay;void Delay(uint32_t nTime);void main( ) SysTick_Config(SystemCoreClock / 1000); /设置systemtick 一毫秒中断 RCC-AHB1ENR |= 0x00000008; /使能GPIOD 时钟 RCC-APB2ENR |= (1MODER &= 0x00FFFFFF; /设置PD12,13,14,15 输出 GPIOD-MODER |= 0x55000000; GPIOD-OTYPER &= 0xFFFF0FFF; /设置PD12,13,14,15 推挽输出 GPIOD-OSPEEDR &= 0x00FFFFFF; /PD12,13,14,15 速度100m GPIOD-OSPEEDR |= 0xff000000; SYSCFG-CMPCR = 0x00000001; /使用IO 补偿单元, /当GPIO 速度超过50M 的时候要考虑使用此设置 GPIOD-PUPDR &= 0x00FFFFFF; /PD12,13,14,15 无上拉无下拉 GPIOD-BSRRH = 0xf000; /reset register GPIOx_BSRRH, write only /set register GPIOx_BSRRL, write only while(1) GPIOD-BSRRH = 0xf000; GPIOD-BSRRL = 0x1000; Delay(100); GPIOD-BSRRH = 0xf000; GPIOD-BSRRL = 0x1000BSRRH = 0xf000; GPIOD-BSRRL = 0x1000BSRRH = 0xf000; GPIOD-BSRRL = 0x1000BSRRL = GPIO_Pin_12; while(1) / /GPIOD-ODR = GPIO_Pin_12; /GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); GPIO_ToggleBits(GPIOD, GPIO_Pin_12); /Insert a delay Delay(10); void Delay(uint32_t nTime) Gb_TimingDelay = nTime; while(Gb_TimingDelay != 0);void SysTick_Handler(void) if (Gb_TimingDelay != 0x00) Gb_TimingDelay-; */*#include stm32f4_discovery.h#include stm32f4xx_conf.h#include stm32f4xx_rcc.huint32_t xiande=0;uint32_t Gb_TimingDelay;void Delay(uint32_t nTime);void main( ) /Configure the system clocks RCC_ClocksTypeDef RCC_Clocks; /SysTick end of count event each 10ms SysTick_Config(SystemCoreClock / 1000); /设置systemtick 一毫秒中断 /Initialize LEDs mounted on STM32F4-Discovery board STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /Turn on LED4 and LED5 STM_EVAL_LEDOn(LED4); STM_EVAL_LEDOn(LED5); RCC_GetClocksFreq(&RCC_Clocks); xiande = RCC_Clocks.SYSCLK_Frequency; xiande = RCC_Clocks.HCLK_Frequency; xiande = RCC_Clocks.PCLK1_Frequency; xiande = RCC_Clocks.PCLK2_Frequency; while(1) /Toggle LED3 and LED6 STM_EVAL_LEDToggle(LED3); STM_EVAL_LEDToggle(LED6); /Insert a delay Delay(10); void Delay(uint32_t nTime) Gb_TimingDelay = nTime; while(Gb_TimingDelay != 0);void SysTick_Handler(void) if (Gb_TimingDelay != 0x00) Gb_TimingDelay-; */#include stm32f4_discovery.h#include stm32f4xx_conf.h#include stm32f4xx_rcc.h/*定义USART6接受的数据存储变量*/uint16_t usart6_get_data;uint32_t Gb_TimingDelay;void Delay(uint32_t nTime);void GPIO_Config(void);void USART_Config(void);void USART6_Puts(char * str);void NVIC_Config(void);void Delay(uint32_t nCount);void main() /*在主函数main之前通过调用启动代码运行了SystemInit函数,而这个函数位于system_stm32f4xx.c”。 程序运行起始于启动文件的第175行(LDR R0, =SystemInit)。sys时钟为HSE频率/PLL_M*PLL_N/PLL_P, 定义HSE为25M,则sys时钟频率为168M */ SysTick_Config(SystemCoreClock / 1000); /设置systemtick 一毫秒中断 /GPIO_Config(); USART_Config(); NVIC_Config(); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /Turn on LED4 and LED5 STM_EVAL_LEDOn(LED3); while (1) STM_EVAL_LEDOff(LED3); /setbits使能IO,当前下指输出 (此时为灭) Delay(100); STM_EVAL_LEDToggle(LED4); STM_EVAL_LEDToggle(LED5); STM_EVAL_LEDToggle(LED6); /*以下为查询方式 USART6_Puts(Hello Wrold!n); GPIO_ResetBits(GPIOG,GPIO_Pin_6); /Resetbits屏蔽IO,当前下指不输出(此时为亮) Delay(0xFFFFFF); while (USART_GetFlagStatus(USART6,USART_FLAG_RXNE) = RESET) /usart6_get_data = USART_ReceiveData(USART6); USART6_Puts(Get Data From USART6:); USART_SendData(USART6,USART_ReceiveData(USART6); while (USART_GetFlagStatus(USART6, USART_FLAG_TXE) = RESET) /USART6_Puts(&usart6_get_data); USART6_Puts(rn); */ /*Function: void Delay(uint32_t nCount) Description: 延时函数 Input: 延时的时间 Output:无 Return:无 */ void Delay(uint32_t nTime) Gb_TimingDelay = nTime; while(Gb_TimingDelay != 0);void SysTick_Handler(void) if (Gb_TimingDelay != 0x00) Gb_TimingDelay-; /*Function: void GPIO_Config(void) Description: GPIO配置函数 Input: 无 Output:无 Return:无 */ void GPIO_Config(void) /*定义了一个GPIO_InitStructure的结构体,方便一下使用 */ GPIO_InitTypeDef GPIO_InitStructure; /* 初始化GPIOG时钟*/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG , ENABLE);/使能GPIOG时钟(时钟结构参见“stm32图解.pdf”) /*仅设置结构体中的部分成员:这种情况下,用户应当首先调用函数PPP_SturcInit(.) 来初始化变量PPP_InitStructure,然后再修改其中需要修改的成员。这样可以保证其他 成员的值(多为缺省值)被正确填入。 */ GPIO_StructInit(&GPIO_InitStructure); /* 初始化GPIOG的Pin_6为推挽输出*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; /指定第六引脚 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; /模式为输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /频率为快速 GPIO_Init(GPIOG, &GPIO_InitStructure); /调用IO初始化函数/*Function: void USART_Config(void) Description: USART配置函数 Input: 无 Output:无 Return:无 */ void USART_Config(void) GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); /开启USART6时钟 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /开启GPIOC时钟 GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);/这相当于M3的开启复用时钟?只配置复用的引脚, GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);/ /* Connect USART pins to AF7 */ /*配置GPIOC*/ GPIO_StructInit(&GPIO_InitStructure); /缺省值填入 /*配置GPIOC_Pin6为TX输出*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; /设置为复用,必须为AF,OUT不行 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC,&GPIO_InitStructure); /*配置GPIOC_Pin7为RX输入*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; /这也必须为复用,与M3不同! GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC,&GPIO_InitStructure); /*IO引脚复用功能设置,与之前版本不同*/ /*配置USART6*/ USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate =115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART6, &USART_InitStructure); USART_ClockStructInit(&USART_ClockInitStruct); /之前没有填入缺省值,是不行的 USART_ClockInit(USART6, &USART_ClockInitStruct); USART_ITConfig(USART6, USART_IT_RXNE, ENABLE); /使能 USART6中断 USART_Cmd(USART6, ENABLE); /使能 USART6 void NVIC_Config() NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /嵌套优先级分组为 1 NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn; /嵌套通道为USART6_IRQn NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /抢占优先级为 0 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /响应优先级为 0 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /通道中断使能 NVIC_Init(&NVIC_InitStructure);/*Function: void USART6_Puts(char * str) Description: USART6发送数据 Input: 待发送数据指针 Output:无 Return:无 */void USART6_Puts(char * str) while (*str) USART_SendData(USART6, *str+); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART6, USART_FLAG_TXE) = RESET); /详见英文参考的521页,当TXE被置起时,一帧数据传输完成 /*名称:USART6中断服务程序 *作用:USART6收到数据后产生中断,并将收到的内容发回给上位机 */void USART6_IRQHandler(void) if (USART_GetITStatus(USART6, USART_IT_RXNE) != RESET) /判断为接收中断 USART_SendData(USART6, USART_ReceiveData(USART6); /发送收到的数据 STM_EVAL_LEDOn(LED3); /点亮LED,起到中断指示作用 #include stm32f4_discovery.h#include stm32f4xx_conf.h#include stm32f4xx_rcc.h#include #include stm32f4xx_spi.h#include ff.h#include diskio.h#include SPI_MSD0_Driver.h#include stm32f4xx_dcmi.h#include stm32f4xx_i2c.h#include dcmi_ov9655.h#include camera_api.h#define Hang 120#define Lie 160/-FATFS fs; FRESULT res; DIR dirs;FIL file;FILINFO finfo;UINT br;unsigned char txtBuf200;char spfline30;/-/ Private typedef - / Private define - / Private macro - / Private variables - RCC_ClocksTypeDef RCC_Clocks;OV9655_IDTypeDef OV9655_Camera_ID;uint8_t cameraBuf40;extern Camera_TypeDef Camera;extern ImageFormat_TypeDef ImageFormat;extern uint8_t ValueMax;extern const uint8_t *ImageForematArray;/unsigned long int theMap20000=0;unsigned char theMapHang*Lie*2=0;volatile unsigned char biaozhi=0;volatile unsigned char biaozhi2=0;volatile unsigned char DmaTransOver=0;/-/定义USART6接受的数据存储变量 uint16_t usart6_get_data;uint32_t Gb_TimingDelay;/-/Function: /Description: /Input: /Output:无 /Return:无 /-/-/Function: 系统通过uart用printf函数时,需要重载的函数/Description: /Input: /Output:无 /Return:无 /-int fputc(int ch, FILE *f) /Place your implementation of fputc here /Loop until the end of transmission while (USART_GetFlagStatus(USART2, USART_FLAG_TC) = RESET); / write a character to the USART USART_SendData(USART2, (uint8_t) ch); return ch;/-/Function: void Delay(uint32_t nCount) /Description: 延时函数 /Input: 延时的时间 /Output:无 /Return:无 /-void Delay(uint32_t nTime) Gb_TimingDelay = nTime; while(Gb_TimingDelay != 0);void SysTick_Handler(void) if (Gb_TimingDelay != 0x00) Gb_TimingDelay-; /-/Function: void GPIO_Config(void) /Description: GPIO配置函数 /Input: /Output:无 /Return:无 /-void GPIO_Config(void) /定义了一个GPIO_InitStructure的结构体,方便一下使用 GPIO_InitTypeDef GPIO_InitStructure; / 初始化GPIOG时钟 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG , ENABLE);/使能GPIOG时钟(时钟结构参见“stm32图解.pdf”) /仅设置结构体中的部分成员:这种情况下,用户应当首先调用函数PPP_SturcInit(.) /来初始化变量PPP_InitStructure,然后再修改其中需要修改的成员。这样可以保证其他 /成员的值(多为缺省值)被正确填入。 GPIO_StructInit(&GPIO_InitStructure); /初始化GPIOG的Pin_6为推挽输出 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; /指定第六引脚 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; /模式为输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /频率为快速 GPIO_Init(GPIOG, &GPIO_InitStructure); /调用IO初始化函数/-/Function: void USART_Config(void) /Description: USART配置函数 /Input: /Output:无 /Return:无 /-void USART_Config(void) /需要初始化的三个结构体 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStruct; /-各种时钟配置 /-使能模块时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /开启USART6时钟 /-使能GPIO引脚时钟 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /-配置串口模块的功能 /-选择模块利用引脚 GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);/这相当于M3的开启复用时钟?只配置复用的引脚, GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2); /-配置GPIOC引脚 /-缺省值填入 GPIO_StructInit(&GPIO_InitStructure); /-配置GPIOC_Pin6为TX输出 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; /设置为复用,必须为AF,OUT不行 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD,&GPIO_InitStructure); /-配置GPIOC_Pin7为RX输入 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; /这也必须为复用,与M3不同! GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD,&GPIO_InitStructure); /- /IO引脚复用功能设置,与之前版本不同 /-配置USART6 /-缺省值填入 USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate =115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART2, &USART_InitStructure); /-缺省值填入 USART_ClockStructInit(&USART_ClockInitStruct); USART_ClockInit(USART2, &USART_ClockInitStruct); /配置中断,使能相应模块 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); /使能 USART6中断 USART_Cmd(USART2, ENABLE); /使能 USART6 /-/Function: 各种中断配置函数/Description: /Input: /Output:无 /Return:无 /-void NVIC_Config() NVIC_InitTypeDef NVIC_InitStructure; /串口的 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /嵌套优先级分组为 1 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; /嵌套通道为USART6_IRQn NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /抢占优先级为 0 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /响应优先级为 0 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /通道中断使能 NVIC_Init(&NVIC_InitStructure); /DCMI的 NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /DMA_DCMI的 NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn; NVIC_InitStructure.NVIC_IRQ
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版农业科技推广项目农药产品销售合作协议
- 2025年网络安全风险评估与安全协议完善合同
- 2025年智慧城市建设承包经营合同范本
- 2025版外墙装修工程索赔处理合同
- 2025年度石料贸易代理服务合同规范
- 2025版双方自愿离婚协议书法律效力评估规范
- 2025年度琼台师范学院产学研合作协议
- 2025年劳动合同制员工职业健康安全合同
- 2025年度体育赛事赞助保证合同-体育赛事风险防控保障
- 2025年度办公大楼绿化养护与景观设计服务合同
- 液压系统基础知识培训课件
- 数学新课标培训汇报
- 糖尿病入院宣教护理
- 小学音乐开学第一课教学课件
- 万象城商业年终总结
- 黄色中国风家乡介绍山西
- 劳动关系协调师竞赛技能竞赛考试题及答案
- 扬州树人学校2024-2025七年级上学期9月月考数学试卷及答案
- 《第2课 多样的数据》参考课件1
- 熔炼过程自动化智能化控制
- 十年(2015-2024)高考真题数学分项汇编(全国)专题02 复数(教师卷)
评论
0/150
提交评论