//用的是STM32F107VCT 25MHz的外部晶振 //固件库是V3.5的 //想实现串口通信(USART2),却怎么也发不出去数据,求看看是哪里出错了,我新手。。。谢谢啦! #include "stm32f10x.h" void RCC_Configuration(void); void GPIO_Configuration(void); void USART_Configuration(void); int main() { vu16 i=0,k=0; u8 Reset[4]={0x56,0x00,0x26,0x00}; u8 ReceiveCmd[9]; RCC_Configuration(); GPIO_Configuration(); USART_Configuration(); <span style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; text-align: left; "> for(i=0;i |
RE:帮看看这个串口通信问题
u8 Reset[4]={0x56,0x00,0x26,0x00};
你这里发送的对吗
for(i=0;i
RE:帮看看这个串口通信问题
{
USART_InitTypeDef USART_InitStructure;
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(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
USART_Cmd(USART2, ENABLE);
}
还有 Reset应该是 Reset【i】,你是这个意思吧?打印这个数组数据吧?
希望对你有用哦。
回复:帮看看这个串口通信问题
回复:帮看看这个串口通信问题
回复第 2 楼 于2012-09-07 20:57:18发表:
哥们你这里定义的是
u8 Reset[4]={0x56,0x00,0x26,0x00};
你这里发送的对吗
for(i=0;i
回复:帮看看这个串口通信问题
你看看这个:void USART2_Config(void)
{
USART_InitTypeDef USART_InitStructure;
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(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
USART_Cmd(USART2, ENABLE);
}
还有 Reset应该是 Reset【i】,你是这个意思吧?打印这个数组数据吧?
希望对你有用哦。
还是不行哦,发完数据,根本等不到那个标志位为空。。。
回复:帮看看这个串口通信问题
回复第 2 楼 于2012-09-07 20:57:18发表:
哥们你这里定义的是
u8 Reset[4]={0x56,0x00,0x26,0x00};
你这里发送的对吗
for(i=0;i
RE:帮看看这个串口通信问题
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
请楼主确认你用的是哪个串口?如果确认是用的PD5和PD6,在GPIO配置的时候请加一句:
GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
RE:帮看看这个串口通信问题
#include "stm32f10x.h"
#include "platform_config.h"
#include "stm32f10x_usart.h"
#include "misc.h"
void USART2_Config(void);
void GPIO_Configuration(void);
void Delay(vu32 Time);
unsigned char TxBuf[10] = " \r\n";
unsigned char TxBuf1[50] = " ******************************************\r\n";
unsigned char TxBuf2[50] = " * STM32开发板!^_^ *\r\n";
unsigned char TxBuf3[50] = "\r\n Please input any word :\r\n ";
unsigned char TxBuf4[50] = " * *\r\n";
int main(void)
{
int i, RX_status = 0;
SystemInit();
GPIO_Configuration();
USART2_Config();
/* ========USART打印欢迎信息============ */
for( i = 0; TxBuf != '\0'; i++) {
USART_SendData(USART2 , TxBuf);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
for( i = 0; TxBuf1 != '\0'; i++) {
USART_SendData(USART2 , TxBuf1);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
for( i = 0; TxBuf4 != '\0'; i++) {
USART_SendData(USART2 , TxBuf4);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
for( i = 0; TxBuf2 != '\0'; i++) {
USART_SendData(USART2 , TxBuf2);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
for( i = 0; TxBuf4 != '\0'; i++) {
USART_SendData(USART2 , TxBuf4);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
for( i = 0; TxBuf1 != '\0'; i++) {
USART_SendData(USART2 , TxBuf1);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
for( i = 0; TxBuf3 != '\0'; i++) {
USART_SendData(USART2 , TxBuf3);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
while (1)
{
GPIO_SetBits(GPIOE, GPIO_Pin_1);
RX_status = USART_GetFlagStatus(USART2, USART_FLAG_RXNE);
if(RX_status == SET) {
USART_SendData(USART2 , USART_ReceiveData(USART2));
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
GPIO_ResetBits(GPIOE, GPIO_Pin_1);
Delay(0xFFFFF);
}
}
}
void USART2_Config(void)
{
USART_InitTypeDef USART_InitStructure;
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(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
USART_Cmd(USART2, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //LED4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void Delay(vu32 Time)
{
for(; Time != 0; Time--);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
回复:帮看看这个串口通信问题
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
请楼主确认你用的是哪个串口?如果确认是用的PD5和PD6,在GPIO配置的时候请加一句:
GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
确定是PD5 PD6 但是加了那句话还是不行。。
RE:帮看看这个串口通信问题