How to Communicate with UART Sensor on USART6
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 :)
