UART send-recive

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
fifa
Posts: 4
Joined: Thu Oct 15, 2015 7:49 pm

UART send-recive

Post by fifa »

hi to all i'm a student, i want use uart for university project, now i see some exemple in chibios but i don't understand well.
i have this question:
in project STM32F4XX-UART
for send and recive data from uart you use
uartStartReceive(&UARTD2, 16, buffer);
uartStartSend(&UARTD2, 16, message);



in project STM32L1XX-UART
you don't use this function but i read this:
/*
* This callback is invoked when a character is received but the application
* was not ready to receive it, the character is passed as parameter.
*/
static void rxchar(UARTDriver *uartp, uint16_t c) {

(void)uartp;
(void)c;
/* Flashing the LED each time a character is received.*/
palSetPad(GPIOB, GPIOB_LED4);
chSysLockFromISR();
chVTResetI(&vt2);
chVTDoSetI(&vt2, MS2ST(200), ledoff, NULL);
chSysUnlockFromISR();
}

i see that you use this function in STM32F4XX-UART

my question is this
if i want sand and receive data i will use funcition uartStartReceive/uartStartSend or i will modify the function
static void rxchar(UARTDriver *uartp, uint16_t c)


bye
f.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: UART send-recive

Post by Giovanni »

Hi,

The callback is called when a byte arrives but the driver is not yet ready to accept it because uartStartReceive() has not yet invoked.

The UART driver is not buffered so the driver has to do something with incoming data, thus the callback.

If you need a buffered driver (and easier to use) look at the Serial driver, it is the buffered alternative to the UART driver.

Giovanni
User avatar
fifa
Posts: 4
Joined: Thu Oct 15, 2015 7:49 pm

Re: UART send-recive

Post by fifa »

Hi Giovanni,
in my project I can not use the serial driver, because my friends they use it in another project.
this is a project for univerity exam.
Now IF I understand correctly with the uartStartReceive() start the receive but i will write a buffer for store the answer.

bye
F.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: UART send-recive

Post by Giovanni »

Hi,

uartStartReceive() pass to the driver the buffer where to write data, the driver itself has no internal buffer. If a uartStartReceive() has not be called the driver cannot store incoming data and calls the callback instead.

Note that the UART driver is best used when data is organized in fixed length packets, the Serial driver is best for not-organized data, lines of text for example.

Giovanni
User avatar
fifa
Posts: 4
Joined: Thu Oct 15, 2015 7:49 pm

Re: UART send-recive

Post by fifa »

in your example, project STM32F4XX-UART the line

Code: Select all

static uint8_t buffer[16];
...
uartStartReceive(&UARTD1, 16, buffer);


you define the buffer and store the answer in it, this is all for recive the trasmission,
if i want print the trasmissionon UART2, use uartStopReceive(&UARTD1); and later i'll only print this buffer on (UARTD2)
did I get it right?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: UART send-recive

Post by Giovanni »

Hi,

Look at the driver documentation, there are state machine diagrams there, you need to understand that fully: http://chibios.sourceforge.net/docs3/ha ... a_r_t.html

The driver behavior is described by the state machine. If you need to call uartStopReceive() or other functions depends on what you are trying to do and the current driver state.

Note that the UART driver is not exactly the easiest to use, some details cannot be skipped.

Giovanni
Post Reply