General Arduino

how to get data from A02YYUW using hardware serial in Stm32 controller

userHead sridhar.Arul 2023-08-19 20:19:24 278 Views2 Replies

this is my arduino stm32 nucleo code .but i dont get any value .if i use software serial using i/o pin i get the data.

 

#include "HardwareSerial.h"

 

HardwareSerial SerialLP(PB9,PB8); // RX, TX
HardwareSerial Seriall {PA10, PA9};

 


unsigned char data[4]={};
float distance;

// Object to represent software serial port


void setup() {
 Seriall.begin(115200);

SerialLP.begin(9600); 
}

void loop()
{
 

   do{
    for(int i=0;i<4;i++)
    {
      data[i]=SerialLP.read();
     // Seriall.println("E");
    }
 }while(SerialLP.read()==0xff);

 SerialLP.flush();

 if(data[0]==0xff)
   {
     int sum;
     sum=(data[0]+data[1]+data[2])&0x00FF;
   //  Seriall.println(sum);
     if(sum==data[3])
     {
       distance=(data[1]<<8)+data[2];
       if(distance>0)
         {
          Seriall.print("distance=");
          Seriall.print(distance/10);
          Seriall.println("cm");
         }else 
            {
              Seriall.println("Below the lower limit");
            }
     }else Seriall.println("ERROR");
    }
    delay(100);
}

2024-05-09 00:49:47

sir, is it working fine. Please, tell sir

userHeadPic yaswanth.kuna
2023-08-19 20:26:09

sorry i missed that. i used UART pin(hardware serial) for to get the data.

userHeadPic sridhar.Arul