#include "sys.h"
#include "usart.h"
//////////////////////////////////////////////////////////////////////////////////
//±????ò???©?§?°?????????×÷???í???????????????ü????????
//Mini STM32??·?°?
//?®??1??????
//?????×?@ALIENTEK
//????????:www.openedv.com
//????????:2010/5/27
//°?±???V1.3
//°??¨?ù??????°?±?????
//Copyright(C) ?????×? 2009-2019
//All rights reserved
//********************************************************************************
//V1.3???????÷
//?§???????????????????®???¨?????è??.
//????????printf???§??
//???????®???????ü??????.
//??????printf??????×?·????§??bug
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//?????????ú??,?§??printf????,?????è??????use MicroLIB
#if 1
#pragma import(__use_no_semihosting)
//±ê×????è?????§??????
struct __FILE
{
int handle;
/* Whatever you require here. If the only file you are using is */
/* standard output using printf() for debugging, no file handling */
/* is required. */
};
/* FILE is typedef?? d in stdio.h. */
FILE __stdout;
//?¨??_sys_exit()??±???????°??÷?ú????
_sys_exit(int x)
{
x = x;
}
//???¨??fputc????
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0);//??··???,?±??·????ê±?
USART1->DR = (u8) ch;
return ch;
}
#endif
//end
//////////////////////////////////////////////////////////////////
#ifdef EN_USART1_RX //??????????????
//?®??1????·??????ò
//×???,????USARTx->SR??±??????????????í?ó
//????×???
//bit7???????ê??±ê??
//bit6????????0x0d
//bit5~0?????????????§×???????
void USART1_IRQHandler(void)
{
u8 res;
if(USART1->SR&(1<<5))//??????????
{
res=USART1->DR;
USART1->DR=res;
}
}
#endif
//??????IO ?®??1
//pclk2 CLK2?±??????(Mhz)
//bound:?¨????
//CHECK OK
//091209
void uart_init(u32 pclk2,u32 bound)
{
float temp;
u16 mantissa;
u16 fraction;
temp=(float)(pclk2*1000000)/(bound*16);//????USARTDIV
mantissa=temp; //??????????·?
fraction=(temp-mantissa)*16; //??????????·?
mantissa<<=4;
mantissa+=fraction;
RCC->APB2ENR|=1<<2; //????PORTA???±??
RCC->APB2ENR|=1<<14; //?????®???±??
GPIOA->CRH&=0XFFFFF00F;
GPIOA->CRH|=0X000008B0;//IO×????è??
RCC->APB2RSTR|=1<<14; //?????®??1
RCC->APB2RSTR&=~(1<<14);//????????
//?¨?????è??
USART1->BRR=mantissa; // ?¨?????è??
USART1->CR1|=0X200C; //1??????,?????é??.
//????????????
USART1->CR1|=1<<8; //PE????????
USART1->CR1|=1<<5; //??????????·???????????
MY_NVIC_Init(3,3,USART1_IRQChannel,2);//×é2??×?????????
}
这个程序只是在原子哥程序基础上改成这样子而已,但是为什么就是接收不了数据很奇怪,照理说不会有错啊,麻烦各位高手帮我看看,小弟在这里给大家拜个早年,祝福大家工作顺利,学业进步,家庭美满,
void USART1_IRQHandler(void)
{
u8 res;
if(USART1->SR&(1<<5))//??????????
{
res=USART1->DR;
USART1->DR=res;
}
}就改了这里
|