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

PIC18 Bootloader -- RS232 Problems

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



Joined: 02 Mar 2004
Posts: 4

View user's profile Send private message

PIC18 Bootloader -- RS232 Problems
PostPosted: Wed Mar 03, 2004 4:45 pm     Reply with quote

Hello,
I am using the Tiny PIC bootloader from (http://www.ac.ugal.ro/staff/ckiku/software/picbootloader.htm) on a PIC18F458 @40MHz and it works beautifully. However, if the C code that is bootloaded to the PIC tries to use the RS232 port, the output is not displayed in a terminal program. I've tried numerous baud rates and have had no success. If I load the C code directly to the PIC without the bootloader (PicStart) the output is displayed to the terminal program.

Code:
#include <18F458.h>
#fuses HS,NOWDT,NOPROTECT,PUT, NOLVP
#use delay(clock=40000000)
#use rs232(baud=19200,parity=N,bits=8,xmit=PIN_D6,rcv=PIN_D7,stream=PC)

#int_global
void dummy() {}

void main() {

    fprintf (PC,"Bootloader OK");
   while (1){  \\Blink LED on D0
        output_high(PIN_D0);
        delay_us(35000);
        output_low(PIN_D0);
        delay_us(35000);
   }
}


Any suggestions on why the bootloader is disrupting the communication? I have tried changing the #USE RS232 to pins D7 and D6 and that works fine even with the bootloader but that requries a hardware change between bootload and code launch for terminal output.

Regards,
Patrick
Guest








PostPosted: Wed Mar 03, 2004 10:21 pm     Reply with quote

Try putting the "errors" switch in your #use rs232 statement.

Hope that helps.
Guest








Re: PIC18 Bootloader -- RS232 Problems
PostPosted: Thu Mar 04, 2004 2:59 am     Reply with quote

paclark wrote:
However, if the C code that is bootloaded to the PIC tries to use the RS232 port, the output is not displayed in a terminal program.

Any suggestions on why the bootloader is disrupting the communication?
Patrick


patrick,

this is a common problem when using bootloaders. it is a result of the bootloader code configuring various serial port registers prior to your program running AND/OR an error condition already present when your program goes to configure the serial port. the second condition can *sometimes* be resolved as noted above. but that is the trivial case...

this problem took a lot of time for me to figure out when it first happened to me.

ok, how to solve? one way, and i believe the best way, is to get out the datasheet and look up all of the serial port related registers. then, at the beginning of your program, reset these registers to their power-up values prior to doing anything else. yes, i know this is a pain the butt. but the bootloader is leaving the PIC (specifically the USART) in a mode which isn't getting configured properly by the CCS initialization. so you need to help it along by reinitializing those registers.

recently i actually had this problem in reverse -- i wanted to jump back into the bootloader code from my program, thus forcing a code update on the device. i had a lot of fun with that, let me tell you. ultimately it was the same problem as above -- the bootloader wants the hardware in a known state (as close to power up as possible), and my program code had to make provisions to put it back in that state. in any case, you should be able to quickly adopt the code below to fix your situation. not all of the registers i show need to be reset for your situation, so you could experiment and cull some out. for example, to re-enter my bootloader, i had to reinitialize all of the interrupt and timing registers. in your case you probably don't need to touch these, but the baud rate generator etc registers you will have to fix up.

jds


Code:

// used to reset to power-up defaults for bootloader reentry.
// 18Fxxx special purpose register power up values:

// location // power-up value

#byte PCL =    0xFF9
#byte FSR0H =  0xFEA // 0x00
#byte FSR0L =  0xFE9 // 0x00

#byte INTCON = 0xFF2 // 0x00
#byte INTCON2= 0xFF1 // 0xF5
#byte INTCON3= 0xFF0 // 0xC0
#byte FSR0H =  0xFEA // 0x00

#byte STATUS = 0xFD8 // 0x00

#byte TMR0H =  0xFD7 // 0x00
#byte TMR0L =  0xFD6 // 0x00
#byte T0CON =  0xFD5 // 0xFF

#byte TMR1H =  0xFCF // 0x00
#byte TMR1L =  0xFCE // 0x00
#byte T1CON =  0xFCD // 0x00

#byte TMR2 =   0xFCC // 0x00
#byte PR2 =    0xFCB // 0xff
#byte T2CON =  0xFCA // 0x00

#byte SSPADD = 0xFC8 // 0x00
#byte SSPSTAT= 0xFC7 // 0x00

#byte SSPCON1= 0xFC6 // 0x00
#byte SSPCON2= 0xFC5 // 0x00

#byte TMR3H =  0xFB3 // 0x00
#byte TMR3L =  0xFB2 // 0x00
#byte T3CON =  0xFB1 // 0x00

#byte SPBRG =  0xFAF // 0x00
#byte RCREG =  0xFAE // 0x00
#byte TXREG =  0xFAD // 0x00
#byte TXSTA =  0xFAC // 0x02
#byte RCSTA =  0xFAB // 0x00

#byte PIR2 =   0xFA1 // 0x00
#byte PIR1 =   0xF9E // 0x00
#byte PIE1 =   0xF9D // 0x00

#byte TRISC =  0xF94 // 0xff
#byte TRISB =  0xF93 // 0xff
#byte TRISA =  0xF92 // 0x3f

#byte PORTC =  0xF82 // 0x00
#byte PORTB =  0xF81 // 0x00
#byte PORTA =  0xF80 // 0x00


void jump_to_bootloader() {
   disable_interrupts(GLOBAL);
   internal_eeprom(INCREMENT16, EEPROM_FLASH_ATT, DONT_CARE);
   display_message(MSG_FWUPDATE,MOD_NONE,TIMEOUT_NONE);
   delay_ms(250);    // >200ms for downloader sync
   FSR0H =  0x00;    //  clean up special purpose registers
   PIR1 =   0x00;
   PIR2 =   0x00;
   TMR2 =   0x00;
   T2CON =  0x00;
   PIE1 =   0x00;
   PR2 =    0xff;
   STATUS = 0x00;
   TMR0H =  0x00;
   TMR0L =  0x00;
   T0CON =  0xFF;
   INTCON = 0x00;
   INTCON2= 0xff;
   INTCON3= 0xc0;
   T1CON =  0x00;
   TMR1L =  0x00;
   TMR1H =  0x00;
   SPBRG =  0x00;
   TXSTA =  0x02;
   RCSTA =  0x00;
   TXREG =  0x00;
   RCREG =  0x00;
   reset_cpu();      // then jump to reset vector
   }

paclark



Joined: 02 Mar 2004
Posts: 4

View user's profile Send private message

PostPosted: Thu Mar 04, 2004 12:53 pm     Reply with quote

Beautiful. Thank you jds for your help. Might I ask which bootloader you use?

Patrick
jds-pic2
Guest







PostPosted: Fri Mar 05, 2004 12:32 pm     Reply with quote

paclark wrote:
Beautiful. Thank you jds for your help. Might I ask which bootloader you use?

Patrick


patrick,

see the bootloader info at
http://www.microchipc.com/

specifically
http://www.microchipc.com/PIC16bootload/index.htm
and
http://www.microchipc.com/PIC18bootload/

also see
http://www.ehl.cz/pic/pic_e.htm
and note that somewhere there is a PIC18 version of this application as well.

jds
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