cancel
Showing results for 
Search instead for 
Did you mean: 

Testing if USART works?

salahuddinash
Associate II
Posted on March 23, 2014 at 02:05

Hi everyone, 

I'm a newbie with stm32f4Discovery kit, and I've just finished writing a code for implementing sending and receiving a character using USART, I'm using Keil uV5

Here is my code which is an example found on the web with some modification to suite stm32f407 microcontroller 

<p>

#include <stm32f4xx.h>

void USARTSetup(void);

int SendChar(int ch);

int GetChar(void);

int main(void)

{

int input,output;

USARTSetup();

output=SendChar(1);

input=GetChar();

output += output;

input += input;

return 0;

}

void USARTSetup(void)

{

 //USART1 clock enable / port A clock enable

RCC->AHB1ENR |= ((1<<0)|(1<<4));       

     

    //configure GPIOA 

/*Each pin in portA has two corresponding bits in MODER, 00->input(default), 01->output, 10->alternate function

  *bit 18,19 = ''10'' to make PA9 as alternate function, bit 20,21 = ''00'' to make PA10 as input*/

    GPIOA->MODER |=(1<<19) ;          

 // step lightly , no pull up nor pull down resistors, 00->not pull nor push, 01->pull-up, 10->pull-down

    GPIOA->PUPDR = 0;    

//speed of PA9 50MHz, 11->50MHz

GPIOA->OSPEEDR |= ((1<<18)|(1<<19));

//configure USART1

//baud rate

USART1->BRR = 64000000L/115200L;

//enable Tx and Rx 

USART1->CR1 |= ((1<<2)|(1<<3));

//enable USART

USART1->CR1 |= (1<<13);

}

int SendChar(int ch)

{

//Check if DR is empty and the previous sent data is sent or not, with checking <RXNE> bit

while(!( USART1->SR & (1<<7)));

USART1->DR=(ch&0xFF);

return (ch);

}

int GetChar(void)

{

//Check if data is recceived or not with checking <RXNE> bit

while(!(USART1->SR & (1<<5))); 

return ((int)(USART1->DR & 0xFF));

}

</p>

I've compiled this code and it was compiled without any errors or warning.. 

now I want to find out if my code function properly or not

I've installed RealTerm and plugged in my Kit and burn the code on the microcontroller, but nothing happened or appeared on RealTerm

Notes: every time I open RealTerm application an error appears 

''Error in GetComDevicesList opening registry key:...''

and I've no idea how to configure RealTerm to work well with Keil, stm32f4Discovery kit, and Windows 7??

so I'll be gratitude if anyone help

thanks a lot 
24 REPLIES 24
salahuddinash
Associate II
Posted on March 26, 2014 at 06:10

You have to add stm32f4xx_usart.c to the project, you'll need to go up the directory tree, and into the libraries directory.

 

This is just great, finally it compiled without any errors or warnings and also burnt on the chip.. you're wonderful sir, and I'm really so grateful

Now to the last step, testing if the USART is working fine with realterm.

Now I've installed realterm, and I have my USB-to-TTL converter module.. its picture is in the attachments..

the question is.. how to use them ?

I think that I have to connect PC6 pin on the discovery board with RXI pin on the module and PC7 pin on the discovery kit with TXO pin on the module and the 5V pin on the kit with VCC pin on the module and finally GND pin on the kit with GND pin on the module, then I expect to see the output and send the input of the USART on realterm ...

Am I right ??

________________

Attachments :

USB-to-TTL_module.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0e8&d=%2Fa%2F0X0000000bbs%2FQnXFer99rzUyk2d436g2X78tJPTWe9ug4Di_sRXcFCg&asPdf=false
raissateke
Associate II
Posted on October 01, 2014 at 12:29

Hello Sir, would you please upload an example on how to use AT commands for GSM modem to enable a STM32F4 output.

looking forward

alexandre2
Associate
Posted on June 23, 2015 at 19:00

Hello Clive1, I have the same error and I am working on Windows 8. Do you have any solutions ? 

Thanks

Posted on June 23, 2015 at 20:09

This thread is over a year old, what ''error'' exactly are you getting?

For Windows 8, you're going to need to find a Signed Driver that Windows 8 can use, or go through the process of disabling the signing requirement.

https://developer.mbed.org/teams/st/wiki/ST-Link-Driver

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jeremy2
Associate
Posted on July 08, 2015 at 17:50

Hello,

Just for information, using a STM32VLDISCOVERY and trying to load my code, I had the message : ''

Error: Flash Download failed  -  C:\Keil\ARM\STLink\ST-LINKIII-KEIL.dll

'' (µVision 5.15.0)

I solved the issue by setting the right target in the ''Options for target'' => ''Device'' => ''STM32F100RB'' (''STM32F100VB'' was configured by default)

and by setting the right debugger : ''Options for target'' => ''Debug'' ==> ''Use: ST-Link Debugger'', then ''Options for target'' => ''Utilities'' => Use Target Driver for Flash Programming'' => ''ST-Link Debugger''

Then I met another issue trying to load my code : ''

Error: Flash Download failed  -  Target DLL has been cancelled

''

I just solved this issue by setting the right debug adapter port : ''Options for target'' => ''Utilities'' => ''Settings'' ==> ''Debug'' ==> ''Port: SW'' (it was ''JTAG'' by default).

Now loading and debug work properly.

Bye