初级会员

- 积分
- 96
- 金钱
- 96
- 注册时间
- 2020-9-30
- 在线时间
- 22 小时
|
串口接收程序,他报错说我重复定义函数,但是视频里面说这些函数是弱定义函数,可以重新定义的:
#include "sys.h"
#include "delay.h"
#include "usart.h"
UART_HandleTypeDef usart1_handler;
//′®¿úÅäÖÃoˉêy
u8 rdate[1];
void uart1_init ()
{
usart1_handler.Instance=USART1;
usart1_handler.Init.BaudRate=115200;
usart1_handler.Init.WordLength=USART_WORDLENGTH_8B;
usart1_handler.Init.StopBits=USART_STOPBITS_1;
usart1_handler.Init.HwFlowCtl=UART_HWCONTROL_NONE;
usart1_handler.Init.Mode=UART_MODE_TX_RX; //êÕ·¢Ä£ê½
usart1_handler.Init.Parity= USART_PARITY_NONE;
HAL_UART_Init(&usart1_handler);//μ÷óÿa′®¿ú3õê¼»ˉoˉêy
}
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef GPIO_Initure;
if(huart->Instance==USART1)//èç1ûêÇ′®¿ú1£¬½øDD′®¿ú1 MSP3õê¼»ˉ,°å×óĬèÏ′®¿úò»êÇ×óÏ·½usb¿ú£¬
{
__HAL_RCC_GPIOA_CLK_ENABLE(); //ê1ÄüGPIOAê±Öó
__HAL_RCC_USART1_CLK_ENABLE(); //ê1ÄüUSART1ê±Öó
GPIO_Initure.Pin=GPIO_PIN_9; //PA9
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_Initure.Pull=GPIO_PULLUP; //éÏà-
GPIO_Initure.Speed=GPIO_SPEED_FAST; //¸ßËù
GPIO_Initure.Alternate=GPIO_AF7_USART1; //¸′óÃÎaUSART1
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //3õê¼»ˉPA9
GPIO_Initure.Pin=GPIO_PIN_10; //PA10
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //3õê¼»ˉPA10
HAL_NVIC_SetPriority(USART1_IRQn,3,3); //éèÖÃÖD¶ÏóÅÏè¼¶
HAL_NVIC_EnableIRQ(USART1_IRQn); //ê1ÄüÖD¶Ïí¨μà
}
}
void USART1_IRQHandler(void) //ÖD¶Ï·tÎñoˉêy
{
HAL_UART_IRQHandler(&usart1_handler);
HAL_UART_Receive_IT(&usart1_handler,rdate,sizeof(rdate));
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
u8 rec;
if(huart->Instance==USART1)
{
rec=*((huart->pRxBuffPtr)-1);
//rec=rdate[0];
HAL_UART_Transmit(&usart1_handler,&rec,1,1000);
}
}
int main(void)
{
Cache_Enable(); //′ò¿aL1-cache
HAL_Init(); //3õê¼»ˉHAL¿a
Stm32_Clock_Init(432,25,2,9); //éèÖÃê±Öó,216Mhz
//Stm32_Clock_Init(360,25,2,8); //éèÖÃê±Öó,216Mhz
delay_init(216);
uart1_init ();
HAL_UART_Receive_IT(&usart1_handler,rdate,sizeof(rdate)); //ê1Äü½óêÕÖD¶Ï
while (1)
{
//HAL_USART_Transmit(&usart1_handler,buff,sizeof(buff),1000);//1.¾ä±ú2.êy¾YÖ¸Õë3.òa·¢Ëí¶àéù¸ö×Ö½ú4.3¬ê±ê±¼ä
//delay_ms(300);
}
}
报错:
*** Using Compiler 'V5.06 update 3 (build 300)', folder: 'D:\ARM\ARMCC\Bin'
Build target 'Template'
compiling main.c...
linking...
..\OBJ\Template.axf: Error: L6200E: Symbol HAL_UART_MspInit multiply defined (by usart.o and main.o).
..\OBJ\Template.axf: Error: L6200E: Symbol HAL_UART_RxCpltCallback multiply defined (by usart.o and main.o).
..\OBJ\Template.axf: Error: L6200E: Symbol USART1_IRQHandler multiply defined (by usart.o and main.o).
Not enough information to list image symbols.
Not enough information to list the image map.
Finished: 2 information, 0 warning and 3 error messages.
"..\OBJ\Template.axf" - 3 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:04
求大佬解决
|
|