中级会员
 
- 积分
- 331
- 金钱
- 331
- 注册时间
- 2015-11-19
- 在线时间
- 38 小时
|
1金钱
大家帮忙检查一下我的STM32F302串口实验,好几天了,编译没有错误,但是就是不发送数据,求大神解答。[mw_shl_code=applescript,true]#include"stm32f30x.h"
void My_USART1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStrue;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_7);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_7);
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStrue.GPIO_OType=GPIO_OType_PP;
GPIO_InitStrue.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStrue);
USART_InitStructure.USART_BaudRate=115200;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;
USART_Init(USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);//ê1Äü′®¿ú1
}
void port_init(void)
{
GPIO_InitTypeDef tGPIO;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE);
/*----------------------------------------------------------------------------------*/
tGPIO.GPIO_Pin = GPIO_Pin_2;
tGPIO.GPIO_Mode = GPIO_Mode_OUT;
tGPIO.GPIO_OType = GPIO_OType_PP;
tGPIO.GPIO_PuPd = GPIO_PuPd_UP;
tGPIO.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &tGPIO);
GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_RESET);
/*----------------------------------------------------------------------------------*/
}
int main(void)
{
port_init();
My_USART1_Init();
while (1)
{
USART_SendData(USART1,0x11);
GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_RESET);
// delay_ms(500);
// GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_RESET);
// delay_ms(500);
}
}
[/mw_shl_code]
|
|