2022-05-27 05:00 AM
Hi all,
So I'm trying to communicate with a dust sensor (SMUART04L) via USART with the use of an STM32 F411RE. So far I have been able to connect it to the board and get a response of 0x42 which according to other online sources and datasheet is so far correct but I have been unable to try and retrieve data from the sensor. All other online sources show Arduino code and not LL USART code.
This is what I have so far:
while(LL_USART_ReceiveData8(USART6)!= 0x42);
for(uint8_t i=0; i<32; i++)
{
//LL_mDelay(500);
Data[i] = LL_USART_ReceiveData8(USART6);
}
The above returns value 0x42 in the array, I assumed that reading the USART would have returned the data I need one byte at a time. But the data sheet refers to a data frame format that I have to decode and I've been trying to get the data source but have been so far unsuccessful.
I assumed, similar to i2c that the sensor would just send data one byte at a time but it seems to be only transmitting 0x42.
Other online sources do a single byte read(See below) but how would I do this in LL USART?
(Below is Arduino code)
boolean readPMSdata(Stream *s) {
if (! s->available()) {
return false;
}
// Read a byte at a time until we get to the special '0x42' start-byte
if (s->peek() != 0x42) {
s->read();
return false;
}
// Now read all 32 bytes
if (s->available() < 32) {
return false;
}
uint8_t buffer[32];
uint16_t sum = 0;
s->readBytes(buffer, 32);
// get checksum ready
for (uint8_t i=0; i<30; i++) {
sum += buffer[i];
}
Any help is appreciated :)
2022-05-27 05:37 AM
Aren't you suppose to wait on RXNE status before calling LL_USART_ReceiveData8(), it just does a blind read, and doesn't block for actual data availability.
2022-05-27 08:00 AM
Thanks for that. I did that exactly and now it works :)
2024-01-11 03:19 PM
Hi, I am wondering how you were able to connect the SM-UART-04L sensor to the STM32 F411RE board? Thanks!
2024-01-11 04:56 PM
Quite an old post..
There's only a handful of pins, surely can't be than complicated.
If you're using the NUCLEO board, determine which free pins are available for a U(S)ART
2024-01-11 05:00 PM
Thanks for the quick response on such an old post!
I am more wondering how to connect the board physically as the output of the sensor has a 2x5 configuration of smaller pins that I am not sure how to connect to the MCU. I don’t have any wires currently that is able to connect to it so I’m wondering what kind of wire/adapter I would need.
Thanks again!