cancel
Showing results for 
Search instead for 
Did you mean: 

Help Reading Data off UART sensor - Amphenol SM-UART-04L is a laser dust sensor

AMoha.13
Associate II

Hi All,

I need some help and guidance as to how I can read data off UART sensor?

I have tried to following many instructions from my professor and from online but have been so far unsuccessful at obtaining any data.

Currently doing testing through CubeIDE and have the STM32F411RE plugged into my pc through USB and am able to transmit and receive data using TERA TERM but cannot get any readings to show from the sensor.

I am wondering if I'm at all reading correctly? Can I read data from the sensor while plugged into my PC, similar to I2C?

If not how should I read data from the sensor? Please see my current code below.

Oh and we have to use LL Logic not HAL!

uint8_t USART2_GetChar()
{
	uint8_t data;
 
	data = RxBuffer[RxTailIndex];				// read the character indexed by RxTailIndex (ie the oldest valid character in the buffer)
		RxTailIndex++;							//increment the tail index (now points to the next oldest char
		if(RxTailIndex>= 1000)					// wrap the tail index around to zero if it reaches the max value of the array
			RxTailIndex = 0;
 
 
 
	return data;
}
 
 
// Function to determine if a character is available.
// Returns non zero if there are characters in the buffer
// Returns zero if no characters are in the buffer
 
uint8_t USART2_CharAvail()
{
 
return(RxHeadIndex-RxTailIndex);   // compare head and tail index, if they are different it means there are characters present. If difference is 0
									// there are no characters in the buffer
}
 
void USART2_IRQHandler()
{
	if(LL_USART_IsActiveFlag_RXNE(USART2) && LL_USART_IsEnabledIT_RXNE(USART2))	// Check to see if it is the character received interrupt that has fired
	{
		Data = LL_USART_ReceiveData8(USART2);  // Reading from the USART Data Rx register clears the RXNE flag
 
		RxBuffer[RxHeadIndex] = Data;			// Store the received character in the RxBuffer at the location inexed by RxHeadIndex
					RxHeadIndex++;						// Increment RxHeadIndex
					if(RxHeadIndex >= 1000)				// If RxHeadIndex is at the max value of the array wrap around to 0. This may overwrite oldest chars
						RxHeadIndex = 0;			    // if they have not been cleared. Moral of the story , read from the buffer before it overwrites.
 
	}
}
 
  while (1)
  {
	  AirQuality();
  }
 
void AirQuality()
{
  uint8_t data;
  if(USART2_CharAvail())						// Test to see if a character has been recieved
  {
	  data = USART2_GetChar();					// if yes do something interesting with it
 
 
  }
}

2 REPLIES 2

The data is looks like it's not going to be in ASCII (human readable), it is in binary, packetized, in a format described in the manual.

Basically a stream of data you'll need to synchronize too, and parse.

You might also need to send commands to start it.

https://www.tti.com/content/dam/ttiinc/manufacturers/amphenol/AdvancedSensors/PDF/AAS-Telair-Particulate-Sensor-Application-Note.pdf

Not sure how qualified the professors is, or in what, but his job is to teach you the means of solving problems, probably not to solve them for you. To be honest the task looks doable for a secondary school MCU programming project.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AMoha.13
Associate II

Thanks for that. I am aware that I need to send the command but how would I do this in code?

The professor has shown us but only showed us how to blink an LED through the means of UART and use Tera Term to send and receive characters. DId not actually demo communicating with an actual device other them a terminal :(