Simply UART communication for STM32F0 Discovery using mbed. Received char is sent back to the computer.

Dependencies:   mbed

main.cpp

Committer:
krepemar
Date:
2015-03-13
Revision:
0:0fb9dd105439
Child:
1:2cae2115481a

File content as of revision 0:0fb9dd105439:

#include "mbed.h"

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

//SERIAL_TX=PA_2/PA_9 Discovery
//SERIAL_RX=PA_3/PA_10 Discovery
Serial pc(PA_2, PA_3);

DigitalOut myled(PC_8);
char buffer[255];
int prijato=0;

void serialRx()
{
    while(pc.readable()) {
        char c=pc.getc();
        buffer[prijato++]=c;
    }
}

int main()
{
    int i = 1;
    pc.printf("Program started !\n");
    pc.attach(&serialRx,Serial::RxIrq);
    while(1) {
        while(prijato) {
            pc.printf("Prisel znak: %c (%d).\n", buffer[prijato-1],(int)buffer[prijato-1]);
            prijato--;
        }
        wait(1);
        pc.printf("This program runs since %d seconds.\n", i++);
        myled = !myled;
    }
}