LPC1768 UART recieve problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1768 UART recieve problem

852 Views
Alex_2221
Contributor IV

Hello everyone, I'm trying to read two temperatures using LM35 and send them to a phone or computer using HC05 in order to control them. I want to send setpoints to the MCU. I tried to send different numbers ( 2 digit numbers) to the MCU and echo them, however I managed to recieve only the first digit of the numbers I was trying to send. I thought maybe I have problems in sending back the numbers  and I tried to use the recieved temperature in my code as a setpoint, but it didn't work.

 Here is my code. I also added the C file.

Thanks in advance, Alex

Code: 

#include <stdio.h>

#include "lpc17xx_gpio.h"
#include "lpc17xx_pinsel.h"
#include "lpc17XX_uart.h"
#include "lpc17XX_adc.h"

#include "Hardware.h"
#include "Delay_RIT.h"

int main()
{
uint8_t buffstr [20];
uint8_t Temprec [1];
uint8_t temprec;

GPIO_SetDir(2,(1<<2),1);

HW_Init();

while(1)
{
uint16_t temp1 = HW_ADC_Read1();
uint16_t temp2 = HW_ADC_Read2();


uint8_t len= sprintf( (char*)buffstr," %u\n %u\n ",temp1,temp2);
UART_Send(LPC_UART3,buffstr,len,NONE_BLOCKING);

UART_Receive(LPC_UART3,Temprec,1,NONE_BLOCKING);

temprec= Temprec[0];

 

Delay_RIT_ms(1000);

if(temp1>=(temprec+1))
GPIO_ClearValue(2,(1<<2)) ;

else if ( temp1<=temprec)

GPIO_SetValue(2,(1<<2));
}


}

 

Labels (1)
0 Kudos
5 Replies

835 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

How about using the code:

uint8_t counter;

while(1)
{
uint16_t temp1 = HW_ADC_Read1();
uint16_t temp2 = HW_ADC_Read2();


uint8_t len= sprintf( (char*)buffstr," %u\n %u\n ",temp1,temp2);

           counter=len-1;

while(1)

{
UART_Send(LPC_UART3,buffstr[counter],1,BLOCKING);

UART_Receive(LPC_UART3,Temprec,1,BLOCKING);

if(counter==0) break;

       counter--;

 

}

 

temprec= Temprec[0];

 

Delay_RIT_ms(1000);

if(temp1>=(temprec+1))
GPIO_ClearValue(2,(1<<2)) ;

else if ( temp1<=temprec)

GPIO_SetValue(2,(1<<2));
}

pls have a try

BR

XiangJun Rong

0 Kudos

821 Views
Alex_2221
Contributor IV

I tested your code. I was able to receive the number that I send via HC05 successfully, but I don't recieve the temperatures of the sensors on my phone continously anymore. 

0 Kudos

826 Views
Alex_2221
Contributor IV

Thank you very much. I'll try it and will let you know if it works for me. 

0 Kudos

845 Views
Alex_2221
Contributor IV

I use this code for checking if the MCU can echo the number, but whenever I use UART_RECIEV (  blocking) I can correctly echo back the number, but it only works once and I can't recieve anything else from the MCU like the temperatures of the two sensors and if I use  UART_RECIEV (  none-blocking) I can only echo back the first digit of the number, but can recieve the temperature and change the number that I am sending as a setpoint:

UART_Receive(LPC_UART3,Temprec,2,NONE_BLOCKING);

UART_Send(LPC_UART3,Temprec,2,BLOCKING);

0 Kudos

843 Views
Alex_2221
Contributor IV

@xiangjun_rong  What do you think about this?

0 Kudos