cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 discovery - Recieve ''char or word '' from RX.

polasek
Associate II
Posted on July 02, 2013 at 06:08

i have a problem with recieve data to stm32. send data to UART works fine in hyperterminal on windows i see all wordl who send stm32.

But we need

to

STM32

could

also

receive data

from the computer.

I need

to

able to

recognize the signs

+, -

, Enter,

delete

and

after the adoption

of the character

performed

the function.

Defining

UART

ok

I

do not know how

to make a program

to receive the data

.

Thank you all

for your advice

#recieve-uart
7 REPLIES 7
Posted on July 02, 2013 at 06:31

Well you could receive the data into a line buffer, and then parse it, or perhaps use a state machine if you want to deal with it a character at a time.

The data presumably will be sent as 8-bit bytes, you can load them into a char, or an array of chars. The DR is 16-bit to permit the reception of 9-bit data in such modes that permit that, those can be safely ignored for HyperTerminal, or other better terminal apps.

Perhaps a review of sscanf(), strstr(), strtok() might be in order?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
polasek
Associate II
Posted on July 02, 2013 at 13:02

I thought

that would be the

: xxx

=

Received

(

Usart1)

..

but do not know

how

to

write

.

I've already

tried with

many options.

And the back

does not work

.

Help me please

.

sending

data

works for me

.

Way back

no

Thanks

i

work in

stm32f3

discovery

kit

Sorry for

my English

..

I am

from the Czech Republic

Posted on July 02, 2013 at 13:52

while(USART_GetFlagStatus(USARTx, USART_FLAG_RXNE) == RESET);

RxBuffer[RxIndex++] = USART_ReceiveData(USARTx);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
polasek
Associate II
Posted on July 04, 2013 at 06:26

Hi,

Thanks for the advice

.

it works.

Now we can

tell

when you come

STM32

any

character

.

RxIndex

can compute

and send

back to the PC

how many characters

came

.

but

still

I can not

convert

RxBuffer

the word that

I

sent

back

to the PC.

or

able to

recognize

what kind of

character.

Thank you

for your advice

.

polasek
Associate II
Posted on July 12, 2013 at 11:17

Hi please help me. How do I

detect incoming

character from

pc

and the next

step

to do

that

then

do

some

processing

cycle

according to

the

character.

For example,

if (

receivechar

==

+)

{

pk1

+ +

;

 

}

if (

receivechar

== -

) {

=

pok

pok

-

PK1;

 

}

crt2
Associate II
Posted on July 12, 2013 at 13:52

If

compilers encoding (file's encoding) and character encoding from PC is same, then your example if statements should work. However... I would rather send certain binary data...

Posted on July 12, 2013 at 19:59

This all sounds like high school level C programming issues, it's probably a generational thing, I didn't grow up with windows and dialogs.

Here's how I might create a simple calculator app on the F4, as I don't have a USART hung off my F3 board. The concepts should be pretty portable.

// STM32 Simple Calculator USART2 (Tx PA.2, Rx PA.3) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); // USART2_TX
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); // USART2_RX
}
/**************************************************************************************/
void USART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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_Cmd(USART2, ENABLE);
}
/**************************************************************************************/
char USART_GetChar(void)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); // Wait for Full
return((char)USART_ReceiveData(USART2));
}
/**************************************************************************************/
void USART_PutChar(char i)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART2, i);
}
/**************************************************************************************/
void USART_PutString(char *s)
{
while(*s)
USART_PutChar(*s++);
}
/**************************************************************************************/
void USART_PutDecimal(int i)
{
char str[16], *s;
int n;
s = str + sizeof(str); // Point to tail
*--s = 0; // NUL
if (i < 
0
) // Negative
{
n
= 
1
;
i = -i; // Negate
}
else
n
= 
0
;
do
{
*
--s
= 
'0'
+ (char)(i % 10);
i
= i / 10;
}
while(i);
if (n) // Add sign if negated
*
--s
= 
'-'
;
USART_PutString(s);
}
/**************************************************************************************/
void USART_Calc(void) // Simple Calculator from keystrokes
{
int accum, num;
char i;
accum
= 
0
;
num
= 
0
;
while(1)
{
i
= 
USART_GetChar
();
if ((i >= '0') && (i <= '9')) // Decimal?
{
num = (num * 10) + (int)(i - '0'); // Load the number
}
else if (i == '+')
{
accum += num; // add
num = 0; // clear
USART_PutDecimal(accum);
USART_PutString(''

'');
}
else if (i == '-')
{
accum -= num; // subtract
num = 0; // clear
USART_PutDecimal(accum);
USART_PutString(''

'');
}
else if (i == '.') // Print current accumulator and number
{
USART_PutString(''accum:'');
USART_PutDecimal(accum);
USART_PutString('', num:'');
USART_PutDecimal(num);
USART_PutString(''

'');
}
}
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART2_Configuration();
USART_Calc();
while(1); // Don't want to exit
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..