LPC1768 UART works with cp2102 USB to TTL module, but doesn't work with HC05

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

LPC1768 UART works with cp2102 USB to TTL module, but doesn't work with HC05

Jump to solution
2,165 Views
Alex_2221
Contributor IV

Hello everyone, I'm trying to read temperature and store and send back the data I send. I can do that without any problem using cp2102 USB to TTL module, however when I replace cp2102 module with HC05 bluetooh module when I enter the data instead of the data (two digit number) I enter, I recieve a very long and irrelevant number like 65121. I attached my code. By the way my ARM is LPC1768

Thanks in advance,

Alex

Labels (1)
0 Kudos
1 Solution
2,087 Views
Alex_2221
Contributor IV

@xiangjun_rong 

Hi again. I finally solved my problem. Actually I had to #define N 4. When I had cp2102 I thought N 2 would be enough, since  the digital numbers have only 2 digits, but when I replaced cp2102 with HC05 the data couldn't be saved properly. That was strange that N 2 wasn't enough for HC05. Plus, Interestingly, again I had to convert the data into int from ASCII. The data again appeared to be ASCII I don't know why. So, I again subtracted '0' from the data to convert it. I can't thank you enough. Had not been for your code, help, and pieces advice, I wouldn't have debugged my code and solved my problem. I wish a wonderful new year.

BR, 

Alex

View solution in original post

0 Kudos
4 Replies
2,149 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Hearing You have not solved your problem, I am sorry.

Regarding the code:

void UART_IntReceive(void)
{
data[Index]=UART_ReceiveByte(LPC_UART3);
Index++;

if (Index>=N)
Index=0;
//UART_SendByte(LPC_UART3,data);

}

As you know that all interrupt sources of usart module share the same interrupt vector, I suppose that you have to check the interrupt source before you read the receiver data.

void UART_IntReceive(void)
{

if(LPC_UART3->LSR) & 0x01)

{
data[Index]=UART_ReceiveByte(LPC_UART3);

}
Index++;

if (Index>=N)
Index=0;
//UART_SendByte(LPC_UART3,data);

}

If the line LPC_UART3->LSR) & 0x01 has compiling error, pls modify it based on your architecture to access peripheral register.

xiangjun_rong_0-1640578570525.png

Hope it can help you

BR

XiangJun Rong

2,142 Views
Alex_2221
Contributor IV

@xiangjun_rong Hi, thank you very much for your time and reply. Yeah, I thought I solved my problem last time then I realized that I didn't. I tried what you recommended, but it didn't help. I checked my debugger again and realized that whatever I type always data[0] is 13 and data[1] is 10, and because I tried to change the data from ASCII to int I subtracted '0'( when I had cp2102 I had to do this because for some reasons the numbers where in ASCII). That's why I get that large number like 61548. So, if I don't subtract '0' I have 13 and 10 and definitely 13*10+10 will be 140. They don't change when I type something else. I uploaded the screenshot of the debugger. Someone else said that it might be because of the baudrate, but I doubt that because I have no problem sending data. I only have problem in receiving data. Plus, I understood that the program works fine when I step over in debug mode exactly like cp2102, however when I run the program I can clearly see that only 13 and 10 get saved regardless of what I type, but when I step over in debug mode and the program works slowly it can successfully save my data. btw I tried to change the baudrate, but it didn't help either.

0 Kudos
2,101 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

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);
}

 

2,088 Views
Alex_2221
Contributor IV

@xiangjun_rong 

Hi again. I finally solved my problem. Actually I had to #define N 4. When I had cp2102 I thought N 2 would be enough, since  the digital numbers have only 2 digits, but when I replaced cp2102 with HC05 the data couldn't be saved properly. That was strange that N 2 wasn't enough for HC05. Plus, Interestingly, again I had to convert the data into int from ASCII. The data again appeared to be ASCII I don't know why. So, I again subtracted '0' from the data to convert it. I can't thank you enough. Had not been for your code, help, and pieces advice, I wouldn't have debugged my code and solved my problem. I wish a wonderful new year.

BR, 

Alex

0 Kudos