cancel
Showing results for 
Search instead for 
Did you mean: 

UART example code for STM32F0

hospodar
Associate III
Posted on November 20, 2012 at 23:34

Hello,

I looking for some example code for communication between my ST-DISCOVERY F0 board and PC (UART). Can someone help me with it? I´m novice.

Thank you
60 REPLIES 60
Posted on May 07, 2015 at 20:03

Well it means you've got it specified twice, right?

Put the typedef and prototype definitions in the .H file

Include the .H file once in each .C file

Don't define the typedef in the .C file, just the body code for the functions you have prototyped.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hospodar
Associate III
Posted on May 07, 2015 at 22:42

Now, I have three .c files (main.c, fifo.c, stdio_through_usart.c). In all of them is included fifo.h.

fifo.h contains:

#ifndef FIFO_H
#define FIFO_H
#define RXSIZE 1024
#define TXSIZE 512
uint8_t RxBuffer[RXSIZE];
uint8_t TxBuffer[TXSIZE];
typedef
struct
{
char
* buf;
int
head;
int
tail;
int
size;
} fifo_t;
fifo_t RxFifo[1];
fifo_t TxFifo[1];
void
fifo_init(fifo_t * f, 
char
* buf, 
int
size);
int
fifo_read(fifo_t * f, 
void
* buf, 
int
nbytes);
int
fifo_write(fifo_t * f, 
const
void
* buf, 
int
nbytes);
#endif /* FIFO_H */

But now there is new errors. Is this double inclusion? I have defined these arrays just once. Error: L6200E: Symbol RxBuffer multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol RxBuffer multiply defined (by fifo.o and main.o). Error: L6200E: Symbol TxBuffer multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol TxBuffer multiply defined (by fifo.o and main.o). Error: L6200E: Symbol RxFifo multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol RxFifo multiply defined (by fifo.o and main.o). Error: L6200E: Symbol TxFifo multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol TxFifo multiply defined (by fifo.o and main.o).
Posted on May 08, 2015 at 01:16

Define the actual variables, once, in your .C file, and the refer to them in your .H file with the extern prefix.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 08, 2015 at 01:18

http://stackoverflow.com/questions/1433204/how-do-i-use-extern-to-share-variables-between-source-files-in-c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hospodar
Associate III
Posted on May 13, 2015 at 18:43

to be migrated, sourceId: 13890:74F499D6-C293-4561-BFB5-4F1489999957

Posted on May 13, 2015 at 20:02

It's a FIFO, you've presumably already pulled other byte(s) from the buffer, and the tail has moved forward to account for that. It doesn't shift/copy the buffer content, it keeps track of where the ''next'' byte should come from.

Variable advances, data doesn't move.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 13, 2015 at 20:09

to be migrated, sourceId: 13895:74F499D6-C293-4561-BFB5-4F1489999957

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

Dear All,

How I can retarget scanf function to software buffer in order to send data in interrupt handler?

Posted on September 16, 2015 at 17:33

Keil allows you to provide a replacement for int fgetc(FILE *f)

int fgetc(FILE *f)
{
uint16_t ch;
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART1);
return((int)ch);
}

Alternatively, make a buffer, and use sscanf() ?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alla_venugopal
Associate
Posted on November 26, 2015 at 13:48

Hi clive1,

I am new to STM32F0 contoller. I need to communicate 2 STM32F0 controllers using RS485 protocol.Could you please share the code.

Thanks