CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18f4550 serial communication error

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ozgok



Joined: 14 Apr 2014
Posts: 5

View user's profile Send private message

18f4550 serial communication error
PostPosted: Mon Apr 14, 2014 8:59 am     Reply with quote

hi all;
i design a board with 18f4550. it communicates with pc by HC-05 bluetooth card. But it cant :( . Can anyone check my codes and help me what is wrong with it?
Code:

#include <18F4550.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#fuses HSPLL,PLL5,CPUDIV1,NOWDT,PUT,BROWNOUT,NOLVP,NOXINST
#use delay(clock=48000000,crystal=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8,STOP=1,ERRORS)
#USE FAST_IO(D)
char gelen;

#int_rda
void seri_haberlesme_kesmesi()
{
output_high(pin_d5);

while (kbhit())
   {
   gelen=getc();
   }
}     

void main()
{
   setup_psp(PSP_DISABLED);       
   setup_timer_1(T1_DISABLED);     
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);           
   setup_CCP1(CCP_OFF);         
   setup_CCP2(CCP_OFF);       
   
   enable_interrupts(int_rda);
   enable_interrupts(global);
   
   set_tris_d(0x00);
   
   output_high(pin_d5);
   delay_ms(1000);
   output_high(pin_d6);
   delay_ms(1000);
   output_high(pin_d7);
   delay_ms(1000);
   output_d(0);

   while(true)
   {
   output_low(pin_d5);
   putc(gelen);
   delay_ms(300);

   if(gelen=='A')
      {
        output_high(pin_d7);
        output_low(pin_d6);
      }

   if(gelen=='B')
      {
        output_low(pin_d7);
        output_high(pin_d6);
      }
   }
}
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Apr 14, 2014 9:07 am     Reply with quote

Hi,

What is the Vdd voltage of your PIC? what is the Vdd voltage of your bluetooth modem?

Start simple. Can you flash an LED connected to an unused I/O pin at a predictable rate, say one second On, and one second Off? Can you connect a MAX232 IC to the PIC UART and send data back and forth to your PC?

My hunch is that your #1 issue is a hardware one, ie. you are trying to interface a 3.3V peripheral to a +5V PIC. This topis has been covered many, many, many times before!

Also, post your schematic for us to look at. You have to upload it somewhere (a free file hosting service works!), and then post the link to the file here.

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Apr 14, 2014 9:10 am     Reply with quote

Start with the physical. How have you got the HC05 connected to the PIC?. Do you have the required level translator?. The PIC's serial input is a _Schmitt_ level input. Requires the signal to go up to 4v. Without a suitable level translator you won't receive anything....

Separately, there is nothing in the code to say that a character has actually arrived. The outputs will be continuously updating even when a character has not changed. You need something to say 'a character has arrived', and ro only change the outputs when this goes true.
ozgok



Joined: 14 Apr 2014
Posts: 5

View user's profile Send private message

PostPosted: Mon Apr 14, 2014 11:34 am     Reply with quote

Ezflyr and Ttelmah..You are very nice people thanks alot for all of your reply. Now i connect hc05 tx pin to pic rx pin directly and rx pin to pic tx pin via 1k resistor. There is also a 2k ground resistor after 1k. Hc05 run with 3.3v. I think that 3.3v is logic 1 for pic at tx pin. Sometimes pic response after a dozen try. Sometimes not. Is it necessary using a schmitt or max232? Ezflyr can you add the old topic about this subject if easy? If not i will search it. I am waiting both of your instructions?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Apr 14, 2014 12:01 pm     Reply with quote

That won't work reliably.

The problem is the input threshold of the PIC pin. Normal 'TTL' pins have a 2.4v threshold so can be directly driven by 3v chips, but the serial input on the PIC has a Schmitt input (designed to improve noise immunity), so requires the signal to be taken up to nearly 4v.

You need to add something like a 5v TTL buffer between the HC, and the PIC, which will then give a 5v output to drive the PIC input.

A MAX232 is for a different job. It generates/receives the even higher voltage RS232 standard. Inverts the signals as well. Your unit doesn't use this.
ozgok



Joined: 14 Apr 2014
Posts: 5

View user's profile Send private message

PostPosted: Mon Apr 14, 2014 12:12 pm     Reply with quote

Ttelmah,
I understand that i must not use max232 from your reply. So can i use 74hc14? Is it solve the problem?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Apr 14, 2014 1:32 pm     Reply with quote

Unfortunately, no.
This has Schmitt inputs as well, so has the same problem as the PIC, and is also inverting which you don't want.

The classic buffer is something like the 74HCT125. Wire the enable to ground, run the chip from 5v, and each gate merrily adapts a signal from a 3.3v chip to drive a 5v chip.
ozgok



Joined: 14 Apr 2014
Posts: 5

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 12:59 am     Reply with quote

Hi again
Ttelmah i tried what you said. and nothing change. do you have a knowledge about bluetooth signals? i measure tx pin of hc05 and see 3.32V always while no pairing. 3.32V after pairing. and 3.29V while sending data to pic. Is this a normal running condition. Is HC05 broken or failed?

Or is there another problem?

I am lost. I cant sleep. Please help me.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 6:30 am     Reply with quote

Hi,

Well, of course there is still a problem, otherwise it would work, right?

In my first reply, I asked you if you could flash an LED at a predictable rate. Verifying your #Fuse settings and your crystal is an important first step. You ignored this question. I also asked you to post a schematic. Verifying that your hardware is correct is another important first step. You ignored this question.

So, I would say that if you want further help, and you want to obtain it here, you should follow the suggestions/requests that are offered to you. Many of us have gone down this road many, many times before, so we know the common pitfalls and, most importantly, we know the *proper* troubleshooting/debugging procedures!

Good Luck!

John
ozgok



Joined: 14 Apr 2014
Posts: 5

View user's profile Send private message

SOLVED
PostPosted: Mon Apr 21, 2014 2:44 am     Reply with quote

Thanks all,
i solve the problem. the problem is at my pc side. A serial hardware problem.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group