/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / CircleOS 4.1 - simple working USART example?

Username:     
Password:     
             

Forum
  • Index
  •  » circleOS
  •  » CircleOS 4.1 - simple working USART example?

# 1   2010-12-20 02:40:27 CircleOS 4.1 - simple working USART example?

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

CircleOS 4.1 - simple working USART example?

Hi All,
I am trying to get a simple example working using USART2 on the extension connector inside CircleOS 4.1 (EvoPrimer). I have searched through this forum and looked at the "HANDHELD-DATACOLLECTION-TERMINAL" project in the Projects section and also at the examples that come with the ST library, but I am having not much success. Characters get mangled up or the app freezes.
I think my baudrate is correct since looking at the USART2 peripheral in Ride7 shows 9600 bauds.
It might just have to do with the NVIC configuration or which interrupts to use or I read somewhere here that the TIM2 timer might interfere with USART2. I tried a lot of different proposed solutions and it doesn't work right. when I send character to the Primer, some characters show up right, but then there are also some garbage characters ...
Do I need to use the RX interrupt when in CircleOS ( I assume yes).
Do I need to use the TX interrupt when in CircleOS (not sure about that one)
So I was wondering if someone has some simple example that sends "Hello World" out over USART and receives a string from USART2.
Thanks for any help,
Mike

Offline

 

# 2   2010-12-20 15:42:09 CircleOS 4.1 - simple working USART example?

xuwa0800
Member
From: Sweden
Registered: 2010-05-20
Posts: 27

Re: CircleOS 4.1 - simple working USART example?

Hej,

to start with usart, you don't have to use interrupt which may casue extra problems for you. you can just test the send and receive funtions of the usart.  to do this, the simple way is to connect your RX and TX together(i mean the same usart's RX and TX), then you just send some data, and if the usart works correctly, you can see the received value in data register in the debug mode.

for the baut rate, in this test, maybe it is not so critical. but you shouldn't just believe in the data shown in usart peripheral, because of the library(i use the old lib, i'm not sure how about it now, to get 9600, i set the value to 6400, instead of 9600, because of the crystal used in Primer2 is 12MHz instead of 8MHz, you should check your kit)

following are the codes which i hope can help you:

    USART_InitTypeDef USART2_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

        /* Configure USART2 Tx (PA.2) as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

        /* Configure USART2 Rx (PA.3) as input floating */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
     
        /* enable UART peripheral by activating clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);     
   
        /* USART2 configuration ------------------------------------------------------*/
    USART2_InitStructure.USART_BaudRate = 6400;         //BaudRate = 9600 baud
    USART2_InitStructure.USART_WordLength = USART_WordLength_8b;  //Word Length = 8 Bits
    USART2_InitStructure.USART_StopBits = USART_StopBits_1;  //Two Stop Bit
    USART2_InitStructure.USART_Parity = USART_Parity_No ;   //No parity
    USART2_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;  //Hardware flow control disabled (RTS and CTS signals)
    USART2_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;  //Receive and transmit enabled
   
    USART_Init(USART2,&USART2_InitStructure);
    // USART2->BRR = 0x753;
    USART_Cmd(USART2, ENABLE); 


   //ini done, start to send data
   USART_SendData(USART2,0x11);

Last edited by xuwa0800 (2010-12-20 15:44:22)


/Wang

Offline

 

# 3   2010-12-21 06:57:38 CircleOS 4.1 - simple working USART example?

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: CircleOS 4.1 - simple working USART example?

Just a remark about baudrate : the code above is true if you use the ST library as "precompiled library" (option of the linker in your Ride  project); if you put all ST library files into your project (that is preferable), configure the baudrate to 9600 and the Ride debug views will be correct.

Offline

 

# 4   2010-12-22 10:43:56 CircleOS 4.1 - simple working USART example?

xuwa0800
Member
From: Sweden
Registered: 2010-05-20
Posts: 27

Re: CircleOS 4.1 - simple working USART example?

hej mikepo,

could you please tell me when you get usart 'working', i have a strange problem with usart in OS4.1, the kit used is primer 2, i'm not sure if same thing will happen to your kit

link: http://www.stm32circle.com/forum/viewtopic.php?id=1294

Last edited by xuwa0800 (2010-12-22 10:45:36)


/Wang

Offline

 

# 5   2010-12-22 17:17:43 CircleOS 4.1 - simple working USART example?

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: CircleOS 4.1 - simple working USART example?

I am still working on this ... doing a lot of reading.
I will let you know as soon as I have a working example...

Offline

 

# 6   2010-12-23 05:09:19 CircleOS 4.1 - simple working USART example?

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: CircleOS 4.1 - simple working USART example?

Hello Yves:

yrt :

Just a remark about baudrate : the code above is true if you use the ST library as "precompiled library" (option of the linker in your Ride  project); if you put all ST library files into your project (that is preferable), configure the baudrate to 9600 and the Ride debug views will be correct.

I have seen this mentioned in a few other posts as well, but I cannot seem to find that option in the Project properties. I am looking under "LD Linker" -> Libraries and all I see is "UART0 putchar" and "printf capabilities".
I am using Ride7 7.30.10.0159, Patch 0169 and RKit-ARM 1.29.10.0334.
Am I looking in the wrong place?
I have included the stm32f10x_usart.c into my project and also it's dependencies I think.
But I still need to set the baudrate to "6400" to get a value of "9600" displayed in the peripherals in Ride7.
How do I know it's not using the precompiled libs?
do I need to include ALL ST Library files?
Thanks,
Mike

Last edited by mikepo (2010-12-23 05:10:47)

Offline

 

# 7   2010-12-23 06:52:26 CircleOS 4.1 - simple working USART example?

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: CircleOS 4.1 - simple working USART example?

Hi Mike,

After a lot of problems and a lot of support in forums, with the precompiled ST library system (compatibility between versions...), we decided to remove this option in the last version of the KitARM. So you have only to include the necessary ST files into your project, depending on the peripherals you use.
Concerning the baudrate display, did you set the "RLink configuration/Advanced options/Crystal frequency" parameter to 12 MHz, because a lot of display is calculated with this value ?

Yves

Offline

 

# 8   2010-12-28 02:20:56 CircleOS 4.1 - simple working USART example?

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: CircleOS 4.1 - simple working USART example?

A quick update here: I got a sample project set up, using interrupts for Rx and Tx and a circular transmit and receive buffer. It works quite nicely (with one caveat, see below) as a test project for serial communication.
The caveat is that I encountered the same issue as in this thread http://www.stm32circle.com/forum/viewtopic.php?id=1294. When shutting down the EvoPrimer and starting back up the Tx function does not work anymore, until you put the device back into Debug mode.
The project is made for the EvoPrimer, but it should work on the Primer2 as well with just changing a few lines at "DRAW_DisplayStringWithMode" (y position might be different for the Primer2).
Project can be downloaded here: http://lts.cr/CbH

Last edited by mikepo (2010-12-28 02:23:52)

Offline

 

# 9   2010-12-28 05:29:32 CircleOS 4.1 - simple working USART example?

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: CircleOS 4.1 - simple working USART example?

I got the project working now, solved the issue with the Tx not working after shutdown.
Basically the issue is that TIM2 needs to be reset for the USART Tx to work, with the following line:

Code:

TIM_DeInit(TIM2);

Latest version is here if anyone is interested: http://lts.cr/CeZ

Offline

 

# 10   2011-01-03 09:59:34 CircleOS 4.1 - simple working USART example?

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: CircleOS 4.1 - simple working USART example?

Hi mikepo,

It would be interesting for everybody that you post your USART project on this website.
Thanks,
Yves

Offline

 

# 11   2011-01-03 15:05:10 CircleOS 4.1 - simple working USART example?

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: CircleOS 4.1 - simple working USART example?

Hi Yves,
I added the project here:
http://www.stm32circle.com/projects/project.php?id=133
It is still a little bit rough around the edges, so if anyone has any improvements, please let me know.

Offline

 

  • Index
  •  » circleOS
  •  » CircleOS 4.1 - simple working USART example?

Board footer