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

PIC to PC data send problem, via Bluetooth module
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
iceman999



Joined: 13 Dec 2012
Posts: 15

View user's profile Send private message

PostPosted: Thu Dec 13, 2012 3:59 pm     Reply with quote

Compiler is 4.083, i just copied your posted code, so nothing is changed, only setup_spi is now in main.c.

This is main.c after adding setup_spi and LED flashing...
Code:
#include "C:\Users\Jan\Documents\Nova mapa\main.h"


// rezerviran prostor za bootloader
#define _bootload
#ifdef _bootload
#define LOADER_END 0x7FF
#define LOADER_SIZE 0x6FF
#build(reset=LOADER_END+1, interrupt=LOADER_END+9)
#org 0, LOADER_END {}
#endif

void led(){
output_high(PIN_C0);
delay_ms(500);
output_low(PIN_C0);
delay_ms(500);
}


void main()
{
   
    setup_spi(FALSE); 
   
while(1){

printf("1");
led();
}

}


And main.h again:
Code:
#include <18F2550.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                           //needed for 20MHz
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                     //Internal External Switch Over mode enabled
#FUSES NOFCMEN                  //No fail safe
#FUSES NOPBADEN                //You are turning off the ADC
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                       //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL5                        //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1                  //System Clock by 1
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 2:11 am     Reply with quote

OK.
I have a 'nasty feeling' you may be hitting a compiler problem. I don't have 4.083. I only kept compilers that worked for me. I kept 4.070, and a couple of the slight later 4.08x releases, suggesting I was hitting problems in the mid 4.08 area.
Have taken the code, simplified without the bootloader, and with several unnecessary fuses removed (for instance, what is the point of setting a brownout reset voltage, when you are turning brownout off....). Compiler with 4.089, and it runs fine:
Code:

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

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                           //needed for 20MHz
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES PUT                      //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOIESO                     //Internal External Switch Over mode enabled
#FUSES NOFCMEN                  //No fail safe
#FUSES NOPBADEN                //You are turning off the ADC
#FUSES MCLR                       //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL5                        //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1                  //System Clock by 1
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
void led(){
   output_high(PIN_C0);
   delay_ms(500);
   output_low(PIN_C0);
   delay_ms(500);
}


void main(){
   setup_spi(FALSE);
   
   while(1){

   printf("1");
   led();
   }
}

'1' coming out the UART every second, and the baud rate is correct and working.

I have added PUT (you _should_ always use this when using a crystal).

Best Wishes
iceman999



Joined: 13 Dec 2012
Posts: 15

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 9:34 am     Reply with quote

I tried compilers 4.105 and 4.093, but then nothing works. I can't get it start...
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 9:43 am     Reply with quote

You have got a pullup resistor on MCLR?.

Best Wishes
iceman999



Joined: 13 Dec 2012
Posts: 15

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 3:51 am     Reply with quote

Yes i have.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 4:42 am     Reply with quote

As a comment, are you actually loading this with a bootloader?.
What fuses are used in the bootloader?.

Best Wishes
iceman999



Joined: 13 Dec 2012
Posts: 15

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 8:48 am     Reply with quote

I'm using bootloader just to run my usb programmer, and the only code for it is this:

bootloader
Code:

#define _bootload
#ifdef _bootload
#define LOADER_END 0x7FF
#define LOADER_SIZE 0x6FF
#build(reset=LOADER_END+1, interrupt=LOADER_END+9)
#org 0, LOADER_END {}
#endif
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 1:51 pm     Reply with quote

No, you are missing the point.
The bootloader has it's own fuses, and many cannot load ones from the program. Problem is that if you change fuses in the main code, this then stops the bootloader working, so the bootloader 'protects itself', and prevents the code from changing the fuses.
I'd guess your bootloader has the fuse selected as HS_PLL, which then means the CPU _will_ probably be running at 48MHz, whatever your fuses say. This is also why the code worked with the wrong fuses.

You need to post the fuses used in the bootloader.

Best Wishes
ezflyr



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

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 5:08 pm     Reply with quote

Hi,

Are you actually using a bootloader to load code into your PIC? A 'USB
programmer' does not inherently require a bootloader to program a PIC. For
example, the CCS U-40 and U-64 programmers are both USB programmers
that use ICSP to program the PIC. Specifically, what programmer are you
actually using? Post a link!

If you are *really* using a bootloader, how did you progam your PIC
initially? Bootloaders are fairly advanced, and should not really be used
during program development, especially if you are a beginner. Scrap the
bootloader, and program the PIC using the ICSP port.

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Dec 16, 2012 1:53 am     Reply with quote

Unless he has got a bootloader present, the code is never going to run, since it is setup to be jumped to by a bootloader. As you say, a proper 'USB programmer', does not need/want a bootloader.

Best Wishes
iceman999



Joined: 13 Dec 2012
Posts: 15

View user's profile Send private message

PostPosted: Sun Dec 16, 2012 1:03 pm     Reply with quote

I got this programmer at the university, it is very simple, but you can't program PIC without code for bootloader. If i try to delete bootloader code, i can't program this PIC anymore. I have to take it to a friend, who has proper programmer, he loads bootloader code onto my PIC and then i can use it again with my USB programmer. Hope you understand...

Where could i find fuses for bootloader?

If this doesn't work, should i use internal crystal and try to run program with it?


Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Dec 16, 2012 1:35 pm     Reply with quote

Right. You do _not Have a USB programmer, you have a USB bootloader. Your friend who loaded the bootloader code, should have the sources, and this will have the fuses. Your fuses need to be the _same_ as these, and your clock selection also needs to be the same. If you have just the bootloader hex file, then load this into MPLAB, and it will display the fuses. Post these and we can work out the clock rate.
There is _not_ an 'internal crystal'. There is an internal oscillator, and this can't be used for USB. You cannot select this if you are using a USB bootloader....

Best Wishes
iceman999



Joined: 13 Dec 2012
Posts: 15

View user's profile Send private message

PostPosted: Sun Dec 16, 2012 2:04 pm     Reply with quote

Thank you. I will get HEX file and i will post it.
ezflyr



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

View user's profile Send private message

PostPosted: Sun Dec 16, 2012 2:54 pm     Reply with quote

Hi iceman999,

You should really try to make your life easier and obtain a different
programmer that uses the 'ICSP' (In Circuit Serial Programming) capability
of the PIC. Bootloaders are great for field upgrades of your firmware, but
frankly they are lousy for developing code!! How much time have you
wasted on this issue, and how much is your time worth? Trust me, you
won't regret having a decent programmer if you intend to do any amount of
PIC development at all!

John
iceman999



Joined: 13 Dec 2012
Posts: 15

View user's profile Send private message

PostPosted: Fri Jan 04, 2013 4:43 pm     Reply with quote

Hello guys.

Weirdest thing happened. When i did't know what to do anymore, i just tried to change some parameters, such as

Code:
#use delay(clock=20000000)


to

Code:
#use delay(clock=48000000)


and WTF?, this works! First my LED started flashing at the right frequency and than i tried to send data, which worked as well... I'm happy as hell!

Thanks for all replys!

Regards
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, 3  Next
Page 2 of 3

 
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