你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。
chrome
firefox
safari
ie8及以上
ST
意法半导体官网
STM32
中文官网
ST
全球论坛
登录/注册
首页
技术问答
话题
资源
创客秀
视频
标签
积分商城
每日签到
UART4,UART5【悬赏问答】
[复制链接]
luke242
提问时间:2012-10-31 14:49 /
谁有串口4,5的程序,我的串口不好使,麻烦大侠给解答一下
赞
0
收藏
0
评论
5
分享
发布时间:2012-10-31 14:49
举报
请先
登录
后回复
5个回答
luke242
回答时间:2012-10-31 14:50:32
a0a.1 0b0c
回复:UART4,UART5
我的初始化代码:
#ifdef UART4_USE //与上位机通信
//使能时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
//中断优先级
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//配置接收管脚PC11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//配置发送管脚PC10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//波特率、字长、停止位、奇偶校验位、硬件流控制、异步串口为默认(被屏蔽字设置)
USART_InitStructure.USART_BaudRate = UART4_RATE;
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(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
赞
0
评论
回复
支持
反对
xiaodc88
回答时间:2012-11-5 14:31:16
a0a.1 0b0c
回复:UART4,UART5【悬赏问答】
楼上的便是,不重复发了,说清楚你的为什么不好使?串口这玩意还比较简单哈
赞
0
评论
回复
支持
反对
zhang7309
回答时间:2012-11-5 18:10:33
a0a.1 0b0c
RE:UART4,UART5【悬赏问答】
恩,建议楼主把原因说的明白点,以便大家能尽快帮你解决
赞
0
评论
回复
支持
反对
zykzyk-93033
回答时间:2012-11-8 20:52:58
a0a.1 0b0c
RE:UART4,UART5【悬赏问答】
这个你参考下:
/*----------------------------------------------------------------------------
STM32 USART setup.
initializes the USARTx register
*----------------------------------------------------------------------------*/
__inline static void stm32_UsartSetup (void) {
if (__USART_USED & 0x01) { // USART1 used
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR &= ~(1 APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for GPIOA
GPIOA->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART1_REMAP; // set USART1 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // enable clock for GPIOB
GPIOB->CRL &= ~(0xFFUL CRL |= (0x0BUL CRL |= (0x04UL APB2ENR |= RCC_APB2ENR_USART1EN; // enable clock for USART1
USART1->BRR = __USART_BRR(__PCLK2, __USART1_BAUDRATE); // set baudrate
USART1->CR1 = __USART1_DATABITS; // set Data bits
USART1->CR2 = __USART1_STOPBITS; // set Stop bits
USART1->CR1 |= __USART1_PARITY; // set Parity
USART1->CR3 = __USART1_FLOWCTRL; // Set Flow Control
USART1->CR1 |= (USART_CR1_RE | USART_CR1_TE); // RX, TX enable
if (__USART_INTERRUPTS & 0x01) { // interrupts used
USART1->CR1 |= __USART1_CR1;
USART1->CR2 |= __USART1_CR2;
USART1->CR3 |= __USART1_CR3;
NVIC->ISER[1] |= (1 CR1 |= USART_CR1_UE; // USART enable
} // end USART1 used
if (__USART_USED & 0x02) { // USART2 used
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR &= ~(1 APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for GPIOA
GPIOA->CRL &= ~(0xFFUL CRL |= (0x0BUL CRL |= (0x04UL CRL &= ~(0xFFUL CRL |= (0x04UL CRL |= (0x0BUL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART2_REMAP; // set USART2 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN; // enable clock for GPIOD
GPIOD->CRL &= ~(0xFFUL CRL |= (0x0BUL CRL |= (0x04UL CRL &= ~(0xFFUL CRL |= (0x04UL CRL |= (0x0BUL APB1ENR |= RCC_APB1ENR_USART2EN; // enable clock for USART2
USART2->BRR = __USART_BRR(__PCLK1, __USART2_BAUDRATE); // set baudrate
USART2->CR1 = __USART2_DATABITS; // set Data bits
USART2->CR2 = __USART2_STOPBITS; // set Stop bits
USART2->CR1 |= __USART2_PARITY; // set Parity
USART2->CR3 = __USART2_FLOWCTRL; // Set Flow Control
USART2->CR1 |= (USART_CR1_RE | USART_CR1_TE); // RX, TX enable
if (__USART_INTERRUPTS & 0x02) { // interrupts used
USART2->CR1 |= __USART2_CR1;
USART2->CR2 |= __USART2_CR2;
USART2->CR3 |= __USART2_CR3;
NVIC->ISER[1] |= (1 CR1 |= USART_CR1_UE; // USART enable
} // end USART2 used
if (__USART_USED & 0x04) { // USART3 used
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR &= ~(3 APB2ENR |= RCC_APB2ENR_IOPBEN; // enable clock for GPIOB
GPIOB->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL CRH &= ~(0xFFUL CRH |= (0x04UL CRH |= (0x0BUL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART3_REMAP; // set USART3 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; // enable clock for GPIOC
GPIOC->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL APB2ENR |= RCC_APB2ENR_IOPBEN; // enable clock for GPIOB
GPIOB->CRH &= ~(0xFFUL CRH |= (0x04UL CRH |= (0x0BUL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART3_REMAP; // set USART3 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN; // enable clock for GPIOD
GPIOD->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL CRH &= ~(0xFFUL CRH |= (0x04UL CRH |= (0x0BUL APB1ENR |= RCC_APB1ENR_USART3EN; // enable clock for USART3
USART3->BRR = __USART_BRR(__PCLK1, __USART3_BAUDRATE); // set baudrate
USART3->CR1 = __USART3_DATABITS; // set Data bits
USART3->CR2 = __USART3_STOPBITS; // set Stop bits
USART3->CR1 |= __USART3_PARITY; // set Parity
USART3->CR3 = __USART3_FLOWCTRL; // Set Flow Control
USART3->CR1 |= (USART_CR1_RE | USART_CR1_TE); // RX, TX enable
if (__USART_INTERRUPTS & 0x04) { // interrupts used
USART3->CR1 |= __USART3_CR1;
USART3->CR2 |= __USART3_CR2;
USART3->CR3 |= __USART3_CR3;
NVIC->ISER[1] |= (1 CR1 |= USART_CR1_UE; // USART enable
} // end USART3 used
} // end of stm32_UsartSetup
赞
0
评论
回复
支持
反对
xieyuanfu
回答时间:2012-11-11 23:42:40
a0a.1 0b0c
RE:UART4,UART5【悬赏问答】
你下载有 3.5的固件库吧?
在
STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\USART
这个目录里 就有 串口 4 5 的例子
串口4有DMA支持,
串口5就没有了,只能查询、中断。
例程里面是串口1、2、3的,根据其定义,修改一些关键参数即可。
例如:
#define USART1_DR_Base (uint32_t)(&USART1->DR)
#define USART1_SR_Base (uint32_t)(&USART1->SR)
#define UART5_DR_Base (uint32_t)(&UART5->DR) //(uint32_t)(&USART5->DR)
#define UART5_SR_Base (uint32_t)(&UART5->SR) //(uint32_t)(&USART5->SR)
//串口5 查询发送
void Uart5_SendArray(u16 Leng)
{
u8 i;
for(i=0;i {
/* Send one byte */
USART_SendData(UART5, TxBuffer5
);
/* Loop until UART5 DR register is empty */
while(USART_GetFlagStatus(UART5, USART_FLAG_TXE) == RESET)
{
}
}
}
不过 你想要学到东西 还是要把你的问题具体说出来 大家才好帮你解决的啊
赞
0
评论
回复
支持
反对
所属标签
相似问题
关于
意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号
手机版
快速回复
返回顶部
返回列表
回复:UART4,UART5
#ifdef UART4_USE //与上位机通信
//使能时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
//中断优先级
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//配置接收管脚PC11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//配置发送管脚PC10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//波特率、字长、停止位、奇偶校验位、硬件流控制、异步串口为默认(被屏蔽字设置)
USART_InitStructure.USART_BaudRate = UART4_RATE;
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(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
回复:UART4,UART5【悬赏问答】
RE:UART4,UART5【悬赏问答】
RE:UART4,UART5【悬赏问答】
/*----------------------------------------------------------------------------
STM32 USART setup.
initializes the USARTx register
*----------------------------------------------------------------------------*/
__inline static void stm32_UsartSetup (void) {
if (__USART_USED & 0x01) { // USART1 used
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR &= ~(1 APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for GPIOA
GPIOA->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART1_REMAP; // set USART1 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // enable clock for GPIOB
GPIOB->CRL &= ~(0xFFUL CRL |= (0x0BUL CRL |= (0x04UL APB2ENR |= RCC_APB2ENR_USART1EN; // enable clock for USART1
USART1->BRR = __USART_BRR(__PCLK2, __USART1_BAUDRATE); // set baudrate
USART1->CR1 = __USART1_DATABITS; // set Data bits
USART1->CR2 = __USART1_STOPBITS; // set Stop bits
USART1->CR1 |= __USART1_PARITY; // set Parity
USART1->CR3 = __USART1_FLOWCTRL; // Set Flow Control
USART1->CR1 |= (USART_CR1_RE | USART_CR1_TE); // RX, TX enable
if (__USART_INTERRUPTS & 0x01) { // interrupts used
USART1->CR1 |= __USART1_CR1;
USART1->CR2 |= __USART1_CR2;
USART1->CR3 |= __USART1_CR3;
NVIC->ISER[1] |= (1 CR1 |= USART_CR1_UE; // USART enable
} // end USART1 used
if (__USART_USED & 0x02) { // USART2 used
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR &= ~(1 APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for GPIOA
GPIOA->CRL &= ~(0xFFUL CRL |= (0x0BUL CRL |= (0x04UL CRL &= ~(0xFFUL CRL |= (0x04UL CRL |= (0x0BUL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART2_REMAP; // set USART2 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN; // enable clock for GPIOD
GPIOD->CRL &= ~(0xFFUL CRL |= (0x0BUL CRL |= (0x04UL CRL &= ~(0xFFUL CRL |= (0x04UL CRL |= (0x0BUL APB1ENR |= RCC_APB1ENR_USART2EN; // enable clock for USART2
USART2->BRR = __USART_BRR(__PCLK1, __USART2_BAUDRATE); // set baudrate
USART2->CR1 = __USART2_DATABITS; // set Data bits
USART2->CR2 = __USART2_STOPBITS; // set Stop bits
USART2->CR1 |= __USART2_PARITY; // set Parity
USART2->CR3 = __USART2_FLOWCTRL; // Set Flow Control
USART2->CR1 |= (USART_CR1_RE | USART_CR1_TE); // RX, TX enable
if (__USART_INTERRUPTS & 0x02) { // interrupts used
USART2->CR1 |= __USART2_CR1;
USART2->CR2 |= __USART2_CR2;
USART2->CR3 |= __USART2_CR3;
NVIC->ISER[1] |= (1 CR1 |= USART_CR1_UE; // USART enable
} // end USART2 used
if (__USART_USED & 0x04) { // USART3 used
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR &= ~(3 APB2ENR |= RCC_APB2ENR_IOPBEN; // enable clock for GPIOB
GPIOB->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL CRH &= ~(0xFFUL CRH |= (0x04UL CRH |= (0x0BUL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART3_REMAP; // set USART3 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; // enable clock for GPIOC
GPIOC->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL APB2ENR |= RCC_APB2ENR_IOPBEN; // enable clock for GPIOB
GPIOB->CRH &= ~(0xFFUL CRH |= (0x04UL CRH |= (0x0BUL APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for Alternate Function
AFIO->MAPR |= __USART3_REMAP; // set USART3 remap
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN; // enable clock for GPIOD
GPIOD->CRH &= ~(0xFFUL CRH |= (0x0BUL CRH |= (0x04UL CRH &= ~(0xFFUL CRH |= (0x04UL CRH |= (0x0BUL APB1ENR |= RCC_APB1ENR_USART3EN; // enable clock for USART3
USART3->BRR = __USART_BRR(__PCLK1, __USART3_BAUDRATE); // set baudrate
USART3->CR1 = __USART3_DATABITS; // set Data bits
USART3->CR2 = __USART3_STOPBITS; // set Stop bits
USART3->CR1 |= __USART3_PARITY; // set Parity
USART3->CR3 = __USART3_FLOWCTRL; // Set Flow Control
USART3->CR1 |= (USART_CR1_RE | USART_CR1_TE); // RX, TX enable
if (__USART_INTERRUPTS & 0x04) { // interrupts used
USART3->CR1 |= __USART3_CR1;
USART3->CR2 |= __USART3_CR2;
USART3->CR3 |= __USART3_CR3;
NVIC->ISER[1] |= (1 CR1 |= USART_CR1_UE; // USART enable
} // end USART3 used
} // end of stm32_UsartSetup
RE:UART4,UART5【悬赏问答】
在
STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\USART
这个目录里 就有 串口 4 5 的例子
串口4有DMA支持,
串口5就没有了,只能查询、中断。
例程里面是串口1、2、3的,根据其定义,修改一些关键参数即可。
例如:
#define USART1_DR_Base (uint32_t)(&USART1->DR)
#define USART1_SR_Base (uint32_t)(&USART1->SR)
#define UART5_DR_Base (uint32_t)(&UART5->DR) //(uint32_t)(&USART5->DR)
#define UART5_SR_Base (uint32_t)(&UART5->SR) //(uint32_t)(&USART5->SR)
//串口5 查询发送
void Uart5_SendArray(u16 Leng)
{
u8 i;
for(i=0;i {
/* Send one byte */
USART_SendData(UART5, TxBuffer5);
/* Loop until UART5 DR register is empty */
while(USART_GetFlagStatus(UART5, USART_FLAG_TXE) == RESET)
{
}
}
}
不过 你想要学到东西 还是要把你的问题具体说出来 大家才好帮你解决的啊