新手上路
- 积分
- 49
- 金钱
- 49
- 注册时间
- 2015-8-1
- 在线时间
- 0 小时
|
5金钱
STM32板子没有USB转串口,我笔记本没有串口。但是我的51板子上有USB转串口,于是用串口线接上51 J20和STM32 J5做实验,LED指示灯不停闪烁但是secureCRT上什么都没有收到,请问哪里出了问题。
下面是我写的主程序代码。
[mw_shl_code=c,true]#include "stm32f10x.h"
void Com_Init(void);
void LED_Init(void);
void Delay(vu32);
int main()
{
Com_Init();
LED_Init();
while(1)
{
USART_SendData(USART1,0x24);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
Delay(0x3FFFFF);
GPIO_SetBits(GPIOF,GPIO_Pin_6);
Delay(0x3FFFFF);
}
}
void Com_Init(void)
{
USART_InitTypeDef USART_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);
USART_DeInit(USART1);
//USART1_TX PA9
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
//USART_RX PA10
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStruct);
//USART1 INIT
USART_InitStruct.USART_BaudRate=9600;
USART_InitStruct.USART_WordLength=USART_WordLength_8b;
USART_InitStruct.USART_StopBits=USART_StopBits_1;
USART_InitStruct.USART_Parity=USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_Init(USART1,&USART_InitStruct);
//USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
}
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_6;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOF,&GPIO_InitStruct);
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}[/mw_shl_code]
|
|
|