代码如下:那位大神指点一下啊~ #include "stm32f10x.h" #include "stdio.h" void delay(__IO u32 nCount); int main(void) { /* USART1 config 115200 8-N-1 */ USART3_Config(); printf("\r\n STM32f103 USART1 test"); //USART3_Config(); while(1) { printf("\r\n TM32f103 USART3 test \r\n"); // for (;;) { //} } } void delay(__IO u32 nCount) { for (; nCount != 0; nCount--); } void USART3_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; /* config USART3 clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 | RCC_APB2Periph_GPIOB, ENABLE); /* USART3 GPIO config */ /* Configure USART3 Tx (PB.10) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure USART3 Rx (PB.11) as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); /* USART3 mode config */ 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(USART3, &USART_InitStructure); /* ʹÄÜ´®¿Ú3½ÓÊÕÖÐ¶Ï */ USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_Cmd(USART3, ENABLE); } //ÅäÖÃUSART3½ÓÊÕÖÐ¶Ï void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3); /* Enable the USARTy Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) { uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; /* Check the parameters */ assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) { /* Compute the Corresponding IRQ Priority --------------------------------*/ tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; tmppre = (0x4 - tmppriority); tmpsub = tmpsub >> tmppriority; tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; tmppriority = tmppriority << 0x04; NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; /* Enable the Selected IRQ Channels --------------------------------------*/ NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); } else { /* Disable the Selected IRQ Channels -------------------------------------*/ NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); } } #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) { /* Check the parameters */ assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; } /// Öض¨Ïòc¿âº¯Êýprintfµ½USART3 int fputc(int ch, FILE *f) { /* ·¢ËÍÒ»¸ö×Ö½ÚÊý¾Ýµ½USART3 */ USART_SendData(USART3, (uint8_t) ch); /* µÈ´ý·¢ËÍÍê±Ï */ while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET); return (ch); } /// Öض¨Ïòc¿âº¯Êýscanfµ½USART3 int fgetc(FILE *f) { /* µÈ´ý´®¿Ú1ÊäÈëÊý¾Ý */ while (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET); return (int)USART_ReceiveData(USART3); } /*********************************************END OF FILE**********************/ |
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
评分
查看全部评分
评分
查看全部评分
#include "stm32f10x.h"
#include "stdio.h"
#include "misc.h"
#include "led.h"
void delay(__IO u32 nCount);
void GPIO_Config(void);
void USART3_Config(void);
int main(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 | RCC_APB2Periph_GPIOB,ENABLE);
GPIO_Config();
USART3_Config();
while(1)
{
printf("adsfsfsfsfs");
}
// return (1);
}
void delay(__IO u32 nCount)
{
for (; nCount != 0; nCount--);
}
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART3 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART3 Rx (PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void USART3_Config(void)
{
USART_InitTypeDef USART_InitStructure;
//* USART3 mode config */
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_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
}
int fputc(int ch, FILE *f)
{
USART_SendData(USART3, (uint8_t) ch);
while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
return (ch);
}
int fgetc(FILE *f)
{
while (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART3);
}
评分
查看全部评分
我用的是LQFP48脚封装的,不需要开吧!等会我开了试试。
重新整理了一下,在9楼,10楼有进一步的描述,麻烦帮我看一下呗。
重新整理了一下,在9楼,10楼有进一步的描述,麻烦帮我看一下呗。
抢占优先级设为最高级是否合适,高低一些试试。
评分
查看全部评分
晕了,我也是瞎说,既然能下载程序,那么单片机应该是正常工作的...