cancel
Showing results for 
Search instead for 
Did you mean: 

how to send two strings via usart

adeemkazi92
Associate II
Posted on September 15, 2015 at 14:43

i am currently working on the usart example of stm32f07

however this example sends only one string

i wanted to know how to send two strings at different press of buttons

#stm-32f07
16 REPLIES 16
Posted on September 15, 2015 at 15:01

Have the IRQ Handler feed the output from a FIFO buffer (aka ring buffer, google if unfamiliar), rather than deal with the string directly, and push the strings into the FIFO buffer.

You could do it without interrupts too.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
adeemkazi92
Associate II
Posted on September 15, 2015 at 18:21

could you please send me the code

i know that would be a piece of cake for u

and can u recommend me a book that i can read so that i can understand stm programming better

adeemkazi92
Associate II
Posted on September 15, 2015 at 18:23

i was actually working on making a calculator by accepting data through usart Rx and displaying the options via Tx.

Posted on September 15, 2015 at 20:57

Yes, but doing your homework doesn't advance my projects.

Geoff Brown has a good breakdown of STM32 peripherals/function

http://www.cs.indiana.edu/~geobrown/book.pdf

Joseph Yiu has a good book on the Cortex-M0

http://www.amazon.com/The-Definitive-Guide-ARM-Cortex-M0/dp/0123854776

Some things like strings, buffering, interrupts and FIFOs are more universal in application, and not specific to STM32 uses. Perhaps some Computer Science texts would be more applicable there.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
adeemkazi92
Associate II
Posted on September 16, 2015 at 08:25

can u atleast help me with the buffer please.

ive been stuck on this for the past 3 days

as i have limited knowledge on c programs
keaven
Associate II
Posted on September 16, 2015 at 16:35

Hi,

you have plenty of example of circular/ring buffer on the internet since it is a wide used technic in drivers or communication. Basically, you need a pointer for the head, tail and end of the buffer. You add bytes with the head pointer and read with the tail pointer. If a pointer go pass the end you set it back to the start. If the head go higher than the tail you have an overflow error. Here is how I am declaring mine usually.

uint8_t RxCircularBuffer[RX_CIRCULAR_BUFFER_LENGHT] = {0};
uint8_t* RxTail = &RxCircularBuffer[0];
uint8_t* RxHead = &RxCircularBuffer[0];
uint8_t* const RxStart = &RxCircularBuffer[0];
uint8_t* const RxEnd = &RxCircularBuffer[RX_CIRCULAR_BUFFER_LENGHT - 1];

I would have a look to UART with DMA used also. They are giving you more information on continuous communication. I am sure clive1 wants to help you but it is best if you find your way out with some cues. And moreover , the poor guy cannot provide codes for everyone :(
Posted on September 16, 2015 at 17:05

FIFO buffering example, bottom end of first page, [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/UART%20example%20code%20for%20STM32F0&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F]this thread.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
adeemkazi92
Associate II
Posted on September 30, 2015 at 11:54

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6iO&d=%2Fa%2F0X0000000btr%2FGo_U9R04jyNWyb3FZgJwspDYxFd_HC5zHvLcCB68RYY&asPdf=false
Posted on September 30, 2015 at 12:09

Seem to be a couple of issues here, will review more fully later.

Use if while() when if () would be appropriate Strings are 'const' not 'volatile' in this context String output could be in a subroutine, should iterate until the last NUL character has been seen rather than sizeof(), this would allow it to be generic rather than hard coded. The loops waiting for input should look for RXNE to be set high, ie there's a character waiting. The values read will be ASCII digits, you might want to read more than one, and then convert to binary, either by subtracting '0', or using atoi() or sscanf(). When writing out the answer you'll need to convert back to ASCII, which could now be additional digits, consider itoa() or sprintf() to create the string, and then calling string output subroutine. I don't understand the button usage.

void OutString(char *s)
{ 
while(*s) // Not NUL
{ 
if (USART_GetFlagStatus(USART1, USART_FLAG_TXE) != RESET) // if it's empty
USART_SendData(USART1, *s++); // Out char, and advance
}
}

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