Hi, Alex,
I have checked your code, I do not understand your code clearly. This is my suggestion.
1)pls narrow down your problem, whether you have problem when you receive character or you have issue when you deal with the received characters.
I suggest you receive a string for example 100 character and check if the characters are correct or not, if there is missing characters. If you receive characters well, it is your job to deal with the received characters.
Pls #define N 100, then check the data array if the received characters are correct or not.
2)For the while loop, you should update the flag so that you handle the data only once.
if(flag)
{
data4=(data[0]-'0')*10+(data[1]-'0');
flag=false;
}
Secondly, it appears that your received data is digital number rather than ascii code, I do not know why you subtracts "0".
Have a nice festival.
BR
Xiangjun Rong
while(1)
{
uint16_t data4;
if(flag)
{
data4=(data[0]-'0')*10+(data[1]-'0');
}
if(data[0]!=0&&Index==1)
{
data4=data[0]-'0';
Index=0;
data[0]=0;
data[1]=0;
}
if(data[0]==NULL&&data[1]==NULL)
data4=0;
// float temp1=HW_ADC_Read(1)/10.0F;
float temp2=20.0F;
uint8_t len=sprintf((char*)buffStr,"%f\n %u\n",temp2,data4);
UART_Send(LPC_UART3,buffStr,len,BLOCKING);
if(temp2>data4)
GPIO_SetValue(2,(1<<5));
else if ( temp2<=data4)
GPIO_ClearValue(2,(1<<5)) ;
Delay_RIT_ms(1000);
}