Page 1 of 1

UART send-recive

Posted: Fri Oct 16, 2015 7:01 am
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.

Re: UART send-recive

Posted: Fri Oct 16, 2015 8:40 am
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

Re: UART send-recive

Posted: Fri Oct 16, 2015 8:58 am
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.

Re: UART send-recive

Posted: Fri Oct 16, 2015 9:05 am
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

Re: UART send-recive

Posted: Fri Oct 16, 2015 9:51 am
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?

Re: UART send-recive

Posted: Fri Oct 16, 2015 10:08 am
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