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 support@ccsinfo.com

Interfacing hc-05 bluetooth module with pic 18f2550
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 5:05 am     Reply with quote

Obviously a lot of other connections needed:

5v to all the Vdd connections on the PIC.
0v to all the Vss connections on the PIC.
Gnd to both sides of the module.
Two of the HV connections to pins C6 and C7 on the PIC.
MCLR pulled up on the PIC
Then the corresponding LV connection for C7 to the UART TXD pin on the module.
Then the LV connection for C6 to the UART RXD connection on the module.
Ideally add a current limiting resistor and LED to the LED line on the module if it doesn't already have one.

Then before anything else run the 'flash an LED' test on the PIC. What you have posted is _not_ correct for the PIC setup. You have the XT oscillator selected (4Mhz max) yet are saying you are running at 20MHz....
The oscillator will probably be failing and running off the internal RC.


Last edited by Ttelmah on Thu Dec 21, 2017 7:59 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 5:46 am     Reply with quote

this line...
setup_adc(ADC_CLOCK_INTERNAL);

is wrong !
Please check the adc section in the datasheet, table 17-1 for WHY it is wrong and what clocks are valid.

I have to assume some 'wizard' defaults this value ?? It appears on a LOT of posts..

also this...
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,PARITY=N,BITS=8)

you need to add 'ERRORS' to the (...options...), otherwise teh PIC UART will 'stall,'freeze', 'lockup', 'fail'.

Jay
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 7:00 am     Reply with quote

Code:
#include <18f2550.h>
#device ADC=10

#FUSES WDT128
#FUSES INTXT
#FUSES NOPROTECT
#FUSES NOBROWNOUT
#FUSES NOPUT
#FUSES NOCPD
#FUSES STVREN
#FUSES NODEBUG
#FUSES NOLVP
#FUSES NOWRT
#FUSES NOWRTD
#FUSES IESO
#FUSES FCMEN
#FUSES PBADEN
#FUSES NOWRTC
#FUSES NOWRTB
#FUSES NOEBTR
#FUSES NOEBTRB
#FUSES NOCPB
#FUSES MCLR
#FUSES LPT1OSC
#FUSES NOXINST
#FUSES PLL1
#FUSES CPUDIV1
#FUSES NOUSBDIV
#FUSES NOVREGEN

#use delay(clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,PARITY=N,BITS=8,errors)
void main()
{
int16 pot;
setup_adc_ports(AN0_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(10);
while (TRUE);
{
pot = read_adc();
delay_ms(20);
printf("%lu",pot);

delay_ms(1000);
}
}


Now its ok????
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 7:04 am     Reply with quote

Still has an impossible CPU clock....

This is why we repeat again and again, that the _first_ thing you must do, is the basic 'flash an LED' test, and get this running at the correct rate. Until the CPU is setup to run at the right rate all clock based functions (which includes RS232) will not work right.
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 7:29 am     Reply with quote

OK tell me which software you used to communicate between pc and bluetooth??
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 7:38 am     Reply with quote

Something like this after the fuses.
Code:

#use delay(clock=4M) //4MHz xtal

#define LED PIN_B1 //whatever pin the LED and resistor are on

void main()
{
while (TRUE);
{
output_toggle(LED);
delay_ms(500);
}
}
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 8:09 am     Reply with quote

temtronic wrote:
Something like this after the fuses.





I have tested the blink led program
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 8:15 am     Reply with quote

What speed is it meant to be giving?.

The whole point is that if you set it as Temtronic shows (500mSec on 500mSec off), the flash should be exactly 1/second. Your video looks like about 4 seconds, which would then mean the CPU is actually running at 1/4 the rate you think it is.

Since your oscillator setup is impossible for the chip, it will probably be falling back to the default RC oscillator.

Serial is not going to work until this is flashing at exactly the speed it is meant to be giving.....
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 8:17 am     Reply with quote

Ttelmah wrote:
What speed is it meant to be giving?.

The whole point is that if you set it as Temtronic shows (500mSec on 500mSec off),


Previously i have set the 100ms delay. Now i set it to 500ms.



temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 11:30 am     Reply with quote

It appears to be very, very slow...though that could be the internet.
Would have to see the fuses related to clocks. I suspect the main clock is NOT running and the failsafe clock may be running.
A 20MHz xtal would need 2, say 15-22pfd caps.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Dec 21, 2017 12:34 pm     Reply with quote

As I have pointed out twice, he is selecting the wrong oscillator.
Hint HS is for a crystal over 4MHz.
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Fri Dec 22, 2017 2:56 pm     Reply with quote

I have measured the level converter output my level converter output is (4.01-3.99)v. when i applied 5v to its high voltage site and 3.3v to its low voltage site.

The output of Rx pin of Bluetooth is (3.19-3.15)v

As Ttelmah previously told
Quote:
PIC RXD needs the signal to go up to 4v to be seen as a logic '1'. The 3.3v HC05 can't do this.


I think i have to increase the level converter high voltage reference
i mean when i give 5 v it gives 4.1v So
if i give 6v it will give 4.5v or around 5v.Then the pic might regarded as logic '1'
thefloyd



Joined: 02 Sep 2009
Posts: 46

View user's profile Send private message

Still need to fix your oscillator
PostPosted: Fri Dec 22, 2017 3:05 pm     Reply with quote

As others have already told you repeatedly, your oscillator configuration is way off. You're blinking an LED at either 500/500ms on/off or 100/100ms on/off but your animated picture shows your LED blinking at *way longer* intervals - something like 8 seconds. If you're asking for a 500ms blink and you're blinking at 8s you're way off. Even if you get your voltage levels sorted, your serial communications *will not* work with a bad oscillator configuration.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 22, 2017 5:55 pm     Reply with quote

As others have said, you need to go back ...
Get the 1Hz LED running. Delete ALL other code ! NO ADC, NO bluetooth, Nothing but

device header
fuses
main()
toggle led
forever

You NEED to do that BEFORE adding anything else. ONCE you get that running, then proceed.

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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