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

Bluetooth with 18f2550 communication
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

Bluetooth with 18f2550 communication
PostPosted: Sun Jul 07, 2013 6:28 am     Reply with quote

Hello my friends,

I want to send my code to 18f2550 by bluetooth with bootloader. Is it possible? I do not know which hex file I initially send to 18f2550. I use ccs 4.138 and securecrt to send my code.

Thanks in advance
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 8:05 am     Reply with quote

Sounds like another student project.

What Bluetooth hardware do you have connected to the pic?
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 9:27 am     Reply with quote

oxo wrote:
Sounds like another student project.


Actually this is a part of my project. I thought it is more simple way rather than usb bootloader.

oxo wrote:
What Bluetooth hardware do you have connected to the pic?


I bought this one.
http://dx.com/p/jy-mcu-arduino-bluetooth-wireless-serial-port-module-104299
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 1:36 am     Reply with quote

Looks quite simple. The BT module you have is transparent, and exactly like a UART.

I would get the bootloading working with a direct wired connection first, then introduce the BT interface.
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 2:10 am     Reply with quote

oxo wrote:
Looks quite simple. The BT module you have is transparent, and exactly like a UART.

I would get the bootloading working with a direct wired connection first, then introduce the BT interface.


I made the connection between bluetooth and 18f2550. (RX and TX connection). A direct wired connection you said is this RX - TX connection?
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 3:03 am     Reply with quote

merics wrote:
oxo wrote:
Looks quite simple. The BT module you have is transparent, and exactly like a UART.

I would get the bootloading working with a direct wired connection first, then introduce the BT interface.


I made the connection between bluetooth and 18f2550. (RX and TX connection). A direct wired connection you said is this RX - TX connection?


yes,
rx-tx
tx-rx
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 3:56 am     Reply with quote

oxo wrote:

yes,
rx-tx
tx-rx


I did exactly like that. Then I tried tiny bootloader in order to work regularly.
But it did not work. In case this works , then I want to do the same for securecrt.

On the other hand , what should I do next?
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 4:23 am     Reply with quote

merics wrote:
oxo wrote:

yes,
rx-tx
tx-rx


I did exactly like that. Then I tried tiny bootloader in order to work regularly.
But it did not work. In case this works , then I want to do the same for securecrt.

On the other hand , what should I do next?


Oh come on.. what everybody knows! Investigate why it doesn't work! Does data come out of the PC and arrive in the PIC.. etc
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 6:16 am     Reply with quote

Code:

#include <serially_led_trial.h>

char data;
void main()
{
   setup_timer_3(T3_DISABLED | T3_DIV_BY_1);

     
   while(TRUE)
   {
      //TODO: User Code
      data=getc();
      printf("\n\r ++ write a for a0\n\r");
      output_high(pin_a1);
      delay_ms(100);
      output_low(pin_a1);
      delay_ms(100);
      if (data=='a')
      {
      output_high(pin_a0);
      delay_ms(600);
      output_high(pin_a0);
      delay_ms(300);
      printf("\n\r ++ a0 toggle\n\r");
      delay_ms(100);
      }
   }

}


I tried this code but pic does not respond.

Bluetooth module's led toggle if it is idle. When I make connection between pc and bluetooth module, the led is on continuosly and the com6 is seen on pc screen but there is no response.[/code]
ezflyr



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

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 6:32 am     Reply with quote

merics,

Basic project development/troubleshooting. Start simple, and build on your early success's to achieve your final result.

At the present time you haven't even shown that your PIC is actually running! The first statement in your while loop is a 'getc()', and if no data is
received, your code will hang there, and appear to be dead....

Start by connecting an LED to an I/O pin of the PIC (with a suitable current limiting resistor), and then write a small loop that toggles this LED once
every second. Does the LED flash, and does it flash at the proper rate??

Next, connect your PIC to the PC thru a MAX232 TTL-to-RS232 converter IC. Write a small loop that continuously reads data from the PIC UART, and
echoes it back to the PC. Does that work properly?

Finally, after all of the above is working, add the bluetooth module, and repeat step 2 above.

My guess is that your PIC is not running as you intend. The 'LED flash' test will tell you this very quickly. In the meantime, post your #fuses,
and your #use delay statement......

John
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 7:02 am     Reply with quote

ezflyr wrote:
merics,

Basic project development/troubleshooting. Start simple, and build on your early success's to achieve your final result.

At the present time you haven't even shown that your PIC is actually running! The first statement in your while loop is a 'getc()', and if no data is
received, your code will hang there, and appear to be dead....

I tried a lot of thing like you said.
Quote:

Start by connecting an LED to an I/O pin of the PIC (with a suitable current limiting resistor), and then write a small loop that toggles this LED once
every second. Does the LED flash, and does it flash at the proper rate??

It works and Leds flash properly, I tried it. I found the problem that the program is stuck on first printf function
Quote:

Next, connect your PIC to the PC thru a MAX232 TTL-to-RS232 converter IC. Write a small loop that continuously reads data from the PIC UART, and
echoes it back to the PC. Does that work properly?

I have not got these equipment. I directly work on bluetooth module. If I find no way ' I will try this.
Quote:

Finally, after all of the above is working, add the bluetooth module, and repeat step 2 above.

My guess is that your PIC is not running as you intend. The 'LED flash' test will tell you this very quickly. In the meantime, post your #fuses,
and your #use delay statement......

John


Up to now my words could be out of topic. I will share my experience regularly.Here is my fuses.
Code:

#include <18F2550.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL5                     //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES HSPLL                    //High Speed Crystal/Resonator with PLL enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=48000000)

#use FIXED_IO( A_outputs=PIN_A1,PIN_A0 )
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC)
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 8:09 am     Reply with quote

Code:

#include <serially_led_trial.h>
char data;
void main()
{
   setup_timer_3(T3_DISABLED | T3_DIV_BY_1);

      output_high(pin_a1);
      delay_ms(1000);
      output_low(pin_a1);
      delay_ms(1000); 
      printf("led toggle\r\n");
   while(TRUE)
   {
   data=getc();
   if(data=='a')
   {
      output_high(pin_a0);
      delay_ms(1000);
      output_low(pin_a0);
      delay_ms(1000);
      output_high(pin_a0);
      delay_ms(1000);
      printf("another led toggle\r\n");
   }
   }


}

The code is working.

So, how can I send my code to pic 18f2550 over bluetooth and use the bluetooth connection as a bootloader?
https://copy.com/rA4bjVBD7jUvLzKV
ezflyr



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

View user's profile Send private message

PostPosted: Mon Jul 08, 2013 9:26 am     Reply with quote

merics,

A 'serial bootloader' is where you will need to focus your efforts. As 'oxo' has already mentioned, and you mis-understood, you need to get a serial
bootloader working first without the bluetooth module, and then once it's working, introduce the module.

CCS provides a serial bootloader in the 'Examples' folder that works, and has pretty good setup documentation. I'd start there.

Generally, the bootloader is activated by a button press (for example), or by the reception of a 'special' character within a certain time frame, both at
power up. You'll need to work out these details.

John
merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 3:02 am     Reply with quote

Quote:

merics,

A 'serial bootloader' is where you will need to focus your efforts. As 'oxo' has already mentioned, and you mis-understood, you need to get a serial
bootloader working first without the bluetooth module, and then once it's working, introduce the module.

CCS provides a serial bootloader in the 'Examples' folder that works, and has pretty good setup documentation. I'd start there.

Generally, the bootloader is activated by a button press (for example), or by the reception of a 'special' character within a certain time frame, both at
power up. You'll need to work out these details.

John


John,

I worked on the usb bootloader previously ( for both 18f4550 and 18f2550). Generally the bootloader program is used by pin_b5 ,so I do it for my robot. And it works regularly. I want to use bluetooth because both I want to get rid of wired connection and I want to send code to 18f2550 and send some sensors data from 18f2550 to pc through bluetooth module.

I set that you said. But when I compile it, the program of the ex_bootloader shows file not found error.

Code:

#elif defined(__PCH__)
#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP
#use delay(clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#endif


#define _bootloader


#include <bootloader.h>
#include <loader.c>


#if defined(__PCM__)
 #org LOADER_END+1,LOADER_END+10
#elif defined(__PCH__)
 #org LOADER_END+2,LOADER_END+20
#endif
void application(void) {
  while(TRUE);
}

#if defined(__PCH__)
#org 0x40,0x7F
#else
#org 0x20,0x3F
#endif
void main(void) {
   if(!input(PIN_B5))
   {
      load_program();
   }

   application();
}

#ORG default

#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}

merics



Joined: 07 Jul 2013
Posts: 11

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 5:53 am     Reply with quote

Finally I complied but it does not work. Where did I make a mistake?


The main code

Code:

#include <serial_bootloader_trial.h>
#include <bootloader.h>

char data;
void main()
{
   setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
   int i=0;

   printf("\r\nApplication program version 1.00 \r\n");
      output_high(pin_a1);
      delay_ms(1000);
      output_low(pin_a1);
      delay_ms(1000); 
      printf("led toggle\r\n");
   while(TRUE)
   {
   printf("%u ",++i);
   data=getc();
   if(data=='a')
   {
      output_high(pin_a0);
      delay_ms(1000);
      output_low(pin_a0);
      delay_ms(1000);
      output_high(pin_a0);
      delay_ms(1000);
      printf("another led toggle\r\n");
   }
   }


}



The bootloader code

Code:

#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#elif defined(__PCH__)
#include <18F2550.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL5                     //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES HSPLL                    //High Speed Crystal/Resonator with PLL enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC)
#endif


#define _bootloader


#include <bootloader.h>
#include <loader.c>


#if defined(__PCM__)
 #org LOADER_END+1,LOADER_END+10
#elif defined(__PCH__)
 #org LOADER_END+2,LOADER_END+20
#endif
void application(void) {
  while(TRUE);
}

#if defined(__PCH__)
#org 0x40,0x7F
#else
#org 0x20,0x3F
#endif
void main(void) {
   if(!input(PIN_B5))
   {
      load_program();
   }

   application();
}

#ORG default

#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}

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 1, 2  Next
Page 1 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