• 大小: 5.99MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-25
  • 语言: 其他
  • 标签: STM32  

资源简介

这个是改进了,采用SPI中断控制实现0-100的收发,单片机主从通讯,采用STM32F103系列,一个小DEMO,函数都已经实现,方便移植。

资源截图

代码片段和文件信息

#include “Uart.h“

void Uart1_Init_Config(void)
{
Sys_Init();    //系统时钟的初始化
Gpio_Init();    // 端口的初始化
Uart1_Init();   // 串口的配置及其初始化
Nvid_Init(); // 中断模式的初始化
}



void Sys_Init(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1ENABLE);
}
void Gpio_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_Init(GPIOA &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ;
GPIO_Init(GPIOA &GPIO_InitStructure);
}
void Uart1_Init(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
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_Tx | USART_Mode_Rx;
USART_Init(USART1 &USART_InitStructure);

USART_Cmd(USART1 ENABLE);
USART_ITConfig(USART1 USART_IT_RXNEENABLE);
USART_ClearFlag(USART1USART_FLAG_RXNE|USART_FLAG_TC|USART_FLAG_TXE);
}

void Nvid_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

}

int fputc(int ch FILE *f)
{
/* 发送一个字节数据到USART1 */
USART_SendData(USART1 (uint8_t) ch);
/* 等待发送完毕 */
while (USART_GetFlagStatus(USART1 USART_FLAG_TXE) == RESET);
return (ch);
}

/// 重定向c库函数scanf到USART1
int fgetc(FILE *f)
{
/* 等待串口1输入数据 */
while (USART_GetFlagStatus(USART1 USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART1);
}









 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-03-23 22:40  SP主从通讯\
     目录           0  2019-03-23 22:40  SP主从通讯\APP\
     目录           0  2019-03-23 22:40  SP主从通讯\APP\SPI\
     文件        3768  2019-03-24 21:25  SP主从通讯\APP\SPI\SPI.C
     文件         262  2018-05-04 17:09  SP主从通讯\APP\SPI\SPI.h
     目录           0  2019-03-23 22:40  SP主从通讯\APP\Usart\
     文件        2232  2018-05-04 16:41  SP主从通讯\APP\Usart\Uart.c
     文件         311  2018-05-04 16:41  SP主从通讯\APP\Usart\Uart.h
     目录           0  2018-02-15 09:35  SP主从通讯\Doc\
     目录           0  2019-03-23 22:36  SP主从通讯\Libraries\
     目录           0  2019-03-23 22:36  SP主从通讯\Libraries\CMSIS\
     文件       17273  2010-06-07 10:25  SP主从通讯\Libraries\CMSIS\core_cm3.c
     文件       85714  2011-02-09 14:59  SP主从通讯\Libraries\CMSIS\core_cm3.h
     目录           0  2019-03-23 22:36  SP主从通讯\Libraries\CMSIS\startup\
     文件       15766  2011-03-10 10:52  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_cl.s
     文件       15503  2011-03-10 10:52  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_hd.s
     文件       15692  2011-03-10 10:52  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_hd_vl.s
     文件       12376  2011-03-10 10:52  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_ld.s
     文件       13656  2011-03-10 10:52  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_ld_vl.s
     文件       12765  2011-03-10 10:52  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_md.s
     文件       14073  2011-03-10 10:51  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_md_vl.s
     文件       15955  2011-03-10 10:51  SP主从通讯\Libraries\CMSIS\startup\startup_stm32f10x_xl.s
     文件      633941  2011-03-10 10:51  SP主从通讯\Libraries\CMSIS\stm32f10x.h
     文件       36557  2011-03-10 10:51  SP主从通讯\Libraries\CMSIS\system_stm32f10x.c
     文件        2085  2011-03-10 10:51  SP主从通讯\Libraries\CMSIS\system_stm32f10x.h
     目录           0  2019-03-23 22:36  SP主从通讯\Libraries\FWLIB\
     目录           0  2019-03-23 22:36  SP主从通讯\Libraries\FWLIB\inc\
     文件        8982  2011-03-10 10:47  SP主从通讯\Libraries\FWLIB\inc\misc.h
     文件       21690  2011-03-10 10:47  SP主从通讯\Libraries\FWLIB\inc\stm32f10x_adc.h
     文件        7555  2011-03-10 10:47  SP主从通讯\Libraries\FWLIB\inc\stm32f10x_bkp.h
     文件       27559  2011-03-10 10:47  SP主从通讯\Libraries\FWLIB\inc\stm32f10x_can.h
............此处省略161个文件信息

评论

共有 条评论