straight forward UART problem (UART1_Data_Ready) doesn't wor

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
hasanabouali
Posts: 47
Joined: 11 Sep 2005 11:33

straight forward UART problem (UART1_Data_Ready) doesn't wor

#1 Post by hasanabouali » 23 Apr 2014 22:49

Hello,
I'm using HC-05 bluetooth module with easyPIC7,
I can send TEXT to the mobile phone without a problem, but no receive

1- I'm using Bluetooth terminal to test
2- easyPIC7 with PIC18F45k22
3- MikroC pro 6

the code extremely simple:

///////////
char receive;

void main() {
ANSELC = 0; // Configure AN pins as digital I/O

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) {
UART1_Write_Text("1"); //Working FINE
Delay_ms(1000);
if (UART1_Data_Ready() == 1) { // Never Happen, Im sure im sending data correctly "I tested the bluetooth with Arduino and everything working fine"
UART1_Write_Text("sthg received");
receive = UART1_Read();
UART1_Write(receive);
}
}
}
///////////////////////

I don't know what im missing here, to not make UART1_Data_Ready() work,

Thank you in advance,
Hasan
//

android
Posts: 345
Joined: 12 May 2010 10:35
Location: Sinny, Straya

Re: straight forward UART problem (UART1_Data_Ready) doesn't

#2 Post by android » 23 Apr 2014 23:20

Sounds like a voltage mismatch issue. Are both the PIC and the HC05 running off 3.3V?
Regards, android
(User of MikroC Pro + mikroProg)

hasanabouali
Posts: 47
Joined: 11 Sep 2005 11:33

Re: straight forward UART problem (UART1_Data_Ready) doesn't

#3 Post by hasanabouali » 24 Apr 2014 07:06

Hi,
Thanks for replying, but i checked and its not the voltage, both running on 3.3,
Tx of the module connected to Rx RC7
Rx of the module connected to Tx RC6

There is a key pin in the hc05 module, im not connecting it to anything,
But also when i tested it with arduino, it works with arduino without it,

The module can send normally, i have a problem in receiving data from the mobile, the condition UART1_Data_Ready never happens, i dont know why

To be noted:
the module working fine with Arduino and PC via UART cable,

Any help will be appreciated,

hasanabouali
Posts: 47
Joined: 11 Sep 2005 11:33

Re: straight forward UART problem (UART1_Data_Ready) doesn't

#4 Post by hasanabouali » 26 Apr 2014 17:21

I solved the problem, now its communicating perfectly...

JaHeretyk
Posts: 18
Joined: 12 Jun 2015 14:47

Re: straight forward UART problem (UART1_Data_Ready) doesn't

#5 Post by JaHeretyk » 08 Jul 2015 11:56

hasanabouali wrote:I solved the problem, now its communicating perfectly...
Hi could you share how did you manage to fix the problem with UART1_Data_Ready() never happening?

I have same problem at the moment.

Thanks, Tomek.

Edit: Solved the problem!
- It's a silly thing, set ANSD7_bit and TRISD7_bit (in my case) to 0 after executing UART1_Init(baud_rate) command to make sure the serial input pin(s) are set to digital inputs

Code: Select all


char data;

UART1_Init(56700);
TRISD7_bit = 0;
ANSD7_bit = 0;
Delay_ms(100);

// can read stuff now
while (1)
{
  if (UART1_Data_Ready() == 1)
  {
    data = UART1_Read();
    UART1_Write(data);
  }
}


trevor
Posts: 121
Joined: 28 Jun 2010 13:21

Re: straight forward UART problem (UART1_Data_Ready) doesn't

#6 Post by trevor » 15 Jul 2015 13:37

Thanks for posting your solution Tomek. So many people just disappear or never say how they solved the problem!

esarearthur
Posts: 62
Joined: 16 Apr 2011 14:13

Re: straight forward UART problem (UART1_Data_Ready) doesn't

#7 Post by esarearthur » 16 Jul 2015 09:45

JaHeretyk wrote:
hasanabouali wrote:I solved the problem, now its communicating perfectly...
Hi could you share how did you manage to fix the problem with UART1_Data_Ready() never happening?

I have same problem at the moment.

Thanks, Tomek.

Edit: Solved the problem!
- It's a silly thing, set ANSD7_bit and TRISD7_bit (in my case) to 0 after executing UART1_Init(baud_rate) command to make sure the serial input pin(s) are set to digital inputs

Code: Select all


char data;

UART1_Init(56700);
TRISD7_bit = 0;
ANSD7_bit = 0;
Delay_ms(100);

// can read stuff now
while (1)
{
  if (UART1_Data_Ready() == 1)
  {
    data = UART1_Read();
    UART1_Write(data);
  }
}


Good to share, but from experience set RX as input

Code: Select all

TRISD7_bit = 1;
Never be afraid to try.

PICKit3 + MikroC Pro for PIC
DAQ with Ethernet -- Current project

Code: Select all

TRISA = 0x00

Post Reply

Return to “mikroC PRO for PIC General”