2015-03-24 06:45 AM
Hello,
I want to sent some characters to a hyperterminal program. But my program wont work..I dont receive any characters in my hyperterminal. I am using the STM32-P107 development kit. The controller on it is the STM32F107VCI really need help here. I hope someone here see what i am doing wrong. I would really appreciate it. This is my code:/* Includes ------------------------------------------------------------------*/#include ''stm32f10x.h''#include ''stm32f10x_gpio.h''#include ''stm32f10x_rcc.h''#include ''stm32f10x_usart.h''#include <stdio.h>void USART_Print_Nick(void){ int i;//**************************************RCC Configuration*************************************\ /* Enable GPIO clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOC, ENABLE); /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//**************************************GPIO Configuration*************************************\ GPIO_InitTypeDef GPIO_InitStructure; /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PA.02 USART1.TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.03 USART1.RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //LED TOGGLE.. initialized // PA.08 = output port for LED GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure);//**************************************USART Configuration*************************************\ 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 configuration */ USART_Init(USART2, &USART_InitStructure); /* Enable the USART2 */ USART_Cmd(USART2, ENABLE);//******************************************Program**********************************************\ while(1) { // 1010.1010 USART_SendData(USART2, 0xAA); //LED toggle GPIO_WriteBit(GPIOC, GPIO_Pin_8, 1); for(i=0;i<0x100000;i++); GPIO_WriteBit(GPIOC, GPIO_Pin_8, 0); for(i=0;i<0x100000;i++); }}2015-03-24 07:54 AM
The USART is not compatible with RS232 levels, needs a converter.
You need to wait for TXE to assert before stuffing characters out.while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART2, 0x55); // Send Char
while(1) // Don't want to exit
{
uint16_t Data;
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); // Wait for Char
Data = USART_ReceiveData(USART2); // Collect Char
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART2, Data); // Echo Char
}
2015-03-25 12:43 AM
It still dont work here. I really dont know what i am doing wrong. Could you look to my software one more time?
//********************************************************************************************\//*****************************************Includes*******************************************\//********************************************************************************************\ #include ''stm32f10x.h'' #include ''stm32f10x_gpio.h'' #include ''stm32f10x_rcc.h'' #include ''stm32f10x_usart.h'' #include <stdio.h>void USART_Print_Nick(void){//********************************************************************************************\//*****************************************Variabelen*****************************************\//********************************************************************************************\ int i;//********************************************************************************************\//**************************************RCC Configuration*************************************\//********************************************************************************************\ /* Enable GPIO clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOC, ENABLE); /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//********************************************************************************************\//**************************************GPIO Configuration************************************\//********************************************************************************************\ GPIO_InitTypeDef GPIO_InitStructure; /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PA.02 USART1.TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.03 USART1.RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //LED TOGGLE.. initialized // PC.08 = output port for LED GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure);// GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); //nodig?//********************************************************************************************\//**************************************USART Configuration***********************************\//********************************************************************************************\ USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 9600; 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 configuration */ USART_Init(USART2, &USART_InitStructure); /* Enable the USART2 */ USART_Cmd(USART2, ENABLE);//********************************************************************************************\//******************************************PROGRAM*******************************************\//********************************************************************************************\ while(1) // Don't want to exit { while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART2, 0x55); // Send char for(i=0;i<0x100000;i++); }}2015-03-25 01:25 AM
Add
USART_SendData(USART2, 0x55); // Send char
while (1) ;
tx only one 0x55 char
_______________________________________
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.03 USART1.RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
floating ? The Rx line is fixed externally ?
2015-03-25 02:02 AM
Thanks for answer man!
But still dont work :(Or can you show me the complete software? I added thewhile (1) ;
I just want to put every 50ms (or something) a char to my hyperterminal program to start. After that i will receive character etc. But for now just send every 50 ms a byte (in this case 0x55)The software is now like this://********************************************************************************************\//*****************************************Includes*******************************************\//********************************************************************************************\#include ''stm32f10x.h''#include ''stm32f10x_gpio.h''#include ''stm32f10x_rcc.h''#include ''stm32f10x_usart.h''#include <stdio.h>void USART_Print_Nick(void){//********************************************************************************************\//*****************************************Variabelen*****************************************\//********************************************************************************************\ int i;//********************************************************************************************\//**************************************RCC Configuration*************************************\//********************************************************************************************\ /* Enable GPIO clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //RCC_APB2Periph_AFIO /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//********************************************************************************************\//**************************************GPIO Configuration************************************\//********************************************************************************************\ GPIO_InitTypeDef GPIO_InitStructure; /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PA.02 USART2.TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.03 USART2.RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure);//********************************************************************************************\//**************************************USART Configuration***********************************\//********************************************************************************************\ 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 configuration */ USART_Init(USART2, &USART_InitStructure); /* Enable the USART2 */ USART_Cmd(USART2, ENABLE);//********************************************************************************************\//******************************************PROGRAM*******************************************\//********************************************************************************************\ while(1) // Don't want to exit { while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART2, 0x55); // Send char } while (1);}2015-03-25 02:06 AM
2015-03-25 02:20 AM
No !
powerup - config uart - send 0x55 - loop if nothing happen check cable connections Hyperterminal port and config if all ok Can you check the microcontroller tx pin signal ? Oscilloscope ? Logic analyzer ? As says clive have you used the level translator like MAX3232 (for 3.3Vdevice ) or MAX232 (for 5V device) ?//********************************************************************************************\
//*****************************************Includes*******************************************\
//********************************************************************************************\
#include ''stm32f10x.h''
#include ''stm32f10x_gpio.h''
#include ''stm32f10x_rcc.h''
#include ''stm32f10x_usart.h''
#include <
stdio.h
>
void USART_Print_Nick(void)
{
//********************************************************************************************\
//*****************************************Variabelen*****************************************\
//********************************************************************************************\
int i;
//********************************************************************************************\
//**************************************RCC Configuration*************************************\
//********************************************************************************************\
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //RCC_APB2Periph_AFIO
/* Enable UART clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
//********************************************************************************************\
//**************************************GPIO Configuration************************************\
//********************************************************************************************\
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PA.02 USART2.TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.03 USART2.RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//********************************************************************************************\
//**************************************USART Configuration***********************************\
//********************************************************************************************\
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 configuration */
USART_Init(USART2, &USART_InitStructure);
/* Enable the USART2 */
USART_Cmd(USART2, ENABLE);
USART_SendData(USART2, 0x55); // Send char
while (1);
}
2015-03-25 02:47 AM
Still nothing happens.
I got a other program from a coocox example and that works on USART 2, But now i want make my own USART program with the stm32f10x libary's but i cant get it work.So the hardware is fine. but there is something in the software what is wrong.So i hope you or someone else can see what i am doing wrong. ?Thanks again for answer!2015-03-25 03:30 AM
Do you have a debugger or scope, can you use those?
How is this function called? Is it called? Where is main(), and does it call SystemInit() first? Can you see any signal on the USART2_TX pin with a scope? Is it at the right baud rate or something else? If so what?2015-03-25 03:46 AM
Hello thanks for answer!
Yes i have a debugger and scope. I measured at the Tx pin. I didn't see any signal on the scope (but i did with the coocox libray uart example. So hardware is tested well. With that program is also received characters at my hyperterminal program).But now i want do it with the stm32f10x library's but i can't get it work. I will show you my main.c and the functionvoid USART_Print(void);int main(void){ SystemInit(); //automatically added by CoIDE USART_Print_Nick();}//********************************************************************************************\//*****************************************Includes*******************************************\//********************************************************************************************\#include ''stm32f10x.h''#include ''stm32f10x_gpio.h''#include ''stm32f10x_rcc.h''#include ''stm32f10x_usart.h''#include <stdio.h>void USART_Print_Nick(void){//********************************************************************************************\//*****************************************Variabelen*****************************************\//********************************************************************************************\ int i; int y = 0xAA;//********************************************************************************************\//**************************************RCC Configuration*************************************\//********************************************************************************************\ /* Enable GPIO clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //RCC_APB2Periph_AFIO /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//********************************************************************************************\//**************************************GPIO Configuration************************************\//********************************************************************************************\ GPIO_InitTypeDef GPIO_InitStructure; /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PA.02 USART2.TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.03 USART2.RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure);//********************************************************************************************\//**************************************USART Configuration***********************************\//********************************************************************************************\ 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 configuration */ USART_Init(USART2, &USART_InitStructure); /* Enable the USART2 */ USART_Cmd(USART2, ENABLE); while (1) { while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART2, y); // Send char }}