Hi,
I have two sensors which sends me data in 36 bytes packets, 100Hz, including header bytes and checksums. the baudrates are 115200. and another two sensors with 38400 baudrates and 52 bytes packets, 50Hz. and a uart to receive data from another microcontroller, the baudrate is 115200 and each packet has 84 bytes of data, 10Hz.
my MCU is stm32h743vit6.
what is the best way to read data from these sensors? there are other sensors on my board, I2C and ADC peripherals are used on this board too.
There are two drivers available for UART. Serial Driver and UART driver, which driver do I need to use to read data from interrupts and pass to threads to parse?
Regards,
Amir.
Read from UART
Moderators: barthess, RoccoMarco
- Giovanni
- Site Admin
- Posts: 14252
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1038 times
- Been thanked: 887 times
- Contact:
Re: Read from UART
Hi,
Use the Serial driver, you just read/write from internal queues, no need to mess with interrupts, it is all done within the driver.
Giovanni
Use the Serial driver, you just read/write from internal queues, no need to mess with interrupts, it is all done within the driver.
Giovanni
Re: Read from UART
Hi,
Thanks for the reply.
is it what you mean? is it the correct and safe way to read continues data?
Regards,
Amir.
Thanks for the reply.
Code: Select all
static THD_WORKING_AREA(waThread3, 256);
static THD_FUNCTION(Thread3, arg) {
(void)arg;
chRegSetThreadName("sensor1Receive");
while (true) {
sdReadTimeout(&SD2, sensor1Buff, 36, 10);
chThdSleepMilliseconds(10);
}
}
Code: Select all
chThdCreateStatic(waThread3, sizeof(waThread3), NORMALPRIO+1, Thread3, NULL);
is it what you mean? is it the correct and safe way to read continues data?
Regards,
Amir.
- Giovanni
- Site Admin
- Posts: 14252
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1038 times
- Been thanked: 887 times
- Contact:
Re: Read from UART
The function is right, adding intervals is not useful probably, the read function is blocking, also note it handles timeouts (look at the returned value), you need to consider that in your communication protocol.
It is often not so straightforward to get communication done right.
Giovanni
It is often not so straightforward to get communication done right.
Giovanni
Re: Read from UART
Hi,
Is there any none blocking functions to read and write using serial driver?
With blocking functions there is chance to lose data in long time running, especially when there are other sensors to read and write to with high frequency.
Regards,
Amir.
Is there any none blocking functions to read and write using serial driver?
With blocking functions there is chance to lose data in long time running, especially when there are other sensors to read and write to with high frequency.
Regards,
Amir.
- Giovanni
- Site Admin
- Posts: 14252
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1038 times
- Been thanked: 887 times
- Contact:
Who is online
Users browsing this forum: No registered users and 8 guests