|
|
View previous topic :: View next topic |
Author |
Message |
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
Odd bootloader behaviour |
Posted: Tue Aug 16, 2016 3:44 am |
|
|
Good day,
I have 2x 18F4620 on the same board, I use the same boot loader for both.
First CPU is happy like a charm. Second is not. I use standard CCS boot loader.
When I turn on enable_interrupts (GLOBAL); then CPU2 stops working.
Code:
Code: |
void systemsetup(VOID)
{
setup_wdt (WDT_ON); //set watch dog timer
//output_FLOAT (I2CSCL);
//output_FLOAT (I2CSDA);
disable_interrupts (GLOBAL); //clear interrupts
set_timer0 (0); //clear timers
set_rtcc (0); //clear timers
setup_timer_0 (RTCC_INTERNAL|RTCC_8_BIT|T0_DIV_1); //set timer 0 parameters
setup_adc_ports (AN0_TO_AN5|VSS_VDD); //set AD ports
setup_adc (ADC_CLOCK_INTERNAL|ADC_CLOCK_DIV_64); //|ADC_TAD_MUL_2); //ADC_CLOCK_INTERNAL|
setup_comparator (NC_NC_NC_NC); //turn off comparators
//enable_interrupts (GLOBAL); //clear interrupts
//enable_interrupts (INT_ssp); //enable serial i2c
//enable_interrupts (INT_rda); //enable serial port
//enable_interrupts (INT_RTCC); //enable TIMERs
//i2c_init(TRUE);
}
|
Code: |
// CONFIG TABLES ==================
#include <18F4620.h> //libs from compiler
#device ADC=10 //analogue to digital converter init specs
#include <ctype.h> //libs from compiler
#include <stddef.h> //libs from compiler
#include <string.h> //libs from compiler
// ================================
// DEFINE =========================
//#define BUSSPEED 115200
//#define RX_PIN PIN_C7 // serial data receive pin
//#define TX_PIN PIN_C6 // serial data transmit pin
//#define TX_ON PIN_C5 // serial TX on
#define STATUS PIN_B2 // status led
//#define I2CSCL PIN_C3
//#define I2CSDA PIN_C4
// ================================
// FUSES ==========================
#FUSES H4
#FUSES MCLR
#FUSES BROWNOUT
#FUSES NODEBUG
#FUSES PROTECT // code protect
#FUSES CPB // boot block code protect
#FUSES CPD // data eeprom code protect
#FUSES NOEBTRB // boot block table code protect
#FUSES NOEBTR // table code protect
//#FUSES NOWDT,NOPROTECT,NOLVP
#FUSES WDT4096
#FUSES WDT
#FUSES PUT
#FUSES NOXINST
#use delay (clock=40M)
// ================================
// SYSTEM =========================
//#use rs232(baud=BUSSPEED,xmit=TX_PIN,rcv=RX_PIN,parity=n,bits=8,stop=1,ENABLE=TX_ON,ERRORS,TIMEOUT=15)
//#use i2c(slave, stream=main, sda=I2CSDA, scl=I2CSCL, address=0xA0, FORCE_HW, SMBUS)
#include "systemsetup.c"
//#include "variables.c"
// ================================
//#use fixed_io(D_outputs=GOUT1,GOUT2,GOUT3,GOUT4,GOUT5,GOUT6,GOUT7,GOUT8)
//#use fixed_io(A_outputs=BUZZ)
//#use fixed_io(B_outputs=STATUS)
//#use fixed_io(C_outputs=TX_PIN,TX_ON)
//#use fixed_io(E_outputs=POWER,BATTERY)
// MAIN PROGRAM ===================
//#int_rda
//void comm (void)
//{
//}
#include <\BTLD\bootloader.h>
//#zero_ram
void main()
{
// main program
systemsetup();
write_eeprom (0x00,0x00);
WHILE (true)
{
//loop program
restart_wdt () ;
//printf("\nOK\r\n");
output_low (STATUS);
delay_ms(500);
output_high (STATUS);
delay_ms(500);
output_low (STATUS);
delay_ms(500);
output_high (STATUS);
delay_ms(500);
}
}
// ================================
|
So when global are off my bootloader loads app in correctly and runs blinking LED
When I turn on globals then it never leaves the bootloader and after reset is unresponsive.
Ideas? Can it be somehow related to the circuit?
Thnx _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Tue Aug 16, 2016 3:56 am |
|
|
to be specific it fails after enable_interrupts (INT_RTCC); is on.
This works:
Code: |
setup_wdt (WDT_ON); //set watch dog timer
output_FLOAT (I2CSCL);
output_FLOAT (I2CSDA);
disable_interrupts (GLOBAL); //clear interrupts
//set_timer0 (0); //clear timers
//set_rtcc (0); //clear timers
setup_timer_0 (RTCC_INTERNAL|RTCC_8_BIT|T0_DIV_1); //set timer 0 parameters
setup_timer_1 (T1_INTERNAL|T1_DIV_BY_1);
set_timer1 (0); //clear timers
set_timer0 (0); //clear timers
setup_adc_ports (AN0_TO_AN5|VSS_VDD); //set AD ports
setup_adc (ADC_CLOCK_INTERNAL|ADC_CLOCK_DIV_64); //|ADC_TAD_MUL_2); //ADC_CLOCK_INTERNAL|
setup_comparator (NC_NC_NC_NC); //turn off comparators
enable_interrupts (GLOBAL); //clear interrupts
enable_interrupts (INT_ssp); //enable serial i2c
enable_interrupts (INT_rda); //enable serial port
//enable_interrupts (INT_RTCC); //enable TIMERs
//enable_interrupts (INT_TIMER1); //enable TIMERs
i2c_init(TRUE);
|
This will not work:
Code: |
setup_wdt (WDT_ON); //set watch dog timer
output_FLOAT (I2CSCL);
output_FLOAT (I2CSDA);
disable_interrupts (GLOBAL); //clear interrupts
//set_timer0 (0); //clear timers
//set_rtcc (0); //clear timers
setup_timer_0 (RTCC_INTERNAL|RTCC_8_BIT|T0_DIV_1); //set timer 0 parameters
setup_timer_1 (T1_INTERNAL|T1_DIV_BY_1);
set_timer1 (0); //clear timers
set_timer0 (0); //clear timers
setup_adc_ports (AN0_TO_AN5|VSS_VDD); //set AD ports
setup_adc (ADC_CLOCK_INTERNAL|ADC_CLOCK_DIV_64); //|ADC_TAD_MUL_2); //ADC_CLOCK_INTERNAL|
setup_comparator (NC_NC_NC_NC); //turn off comparators
enable_interrupts (GLOBAL); //clear interrupts
enable_interrupts (INT_ssp); //enable serial i2c
enable_interrupts (INT_rda); //enable serial port
enable_interrupts (INT_RTCC); //enable TIMERs
enable_interrupts (INT_TIMER1); //enable TIMERs
i2c_init(TRUE);
|
However the same program will run well when there is no bootloader in use... ideas? _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Aug 16, 2016 5:08 am |
|
|
ideas..
1) the WDT is enabled, perhaps it's 'timing out', cauisng the failure??
2) every enabled ISR MUST have a handler(code),best to confirm..
3) You should create a program that will TELL you what the 'fialure' is,similar to POST in the PC BIOS.
4) this...
setup_adc (ADC_CLOCK_INTERNAL|ADC_CLOCK_DIV_64); //|ADC_TAD_MUL_2); //ADC_CLOCK_INTERNAL|
...
99% of the time is wrong 'internal' is generally used for PICs that do adc while asleep.I don't use that PIC maybe it's 'different' than the rest??
Jay |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Tue Aug 16, 2016 8:16 am |
|
|
Adding to what temtronic said, you commented out your RDA isr and then enable it anyways. That will cause the chip to continually reset. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Tue Aug 16, 2016 10:44 am |
|
|
Unless I am missing something I don't see handlers for SSP, Timer1 or RTCC at all....
Not to mention the order of his program (Fuses, use delay, use rs232 etc) is wrong _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Wed Aug 17, 2016 12:52 am |
|
|
Of course it is wrong, this is cut program out of larger section just so I can debug what is going on. So please do not be picky about the bits and pieces but focus on the message. I will try to add RTCC section and other relative IRQs and see if it will kick on.
The problem is that the main fully functional program works on the CPU2 if bootloader is not used. If I add bootloader in then the same program does not start up at all. If I load program out of CPU1 which is functional with bootloader then it goes from first kick. So there is something definitely in the RTCC section of CPU2 program which the bootloader does not like. I will try to debug and once I find it I will post. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Wed Aug 17, 2016 1:20 am |
|
|
Quote: |
So please do not be picky about the bits and pieces but focus on the message.
|
Problem is that when dealing with code, it is the 'bits and pieces' that matter.
The general line here, is that when posting code to show a problem, it should be "a small runnable program, that can be directly compiled, and shows the problem".
If we 'guess' and try to put code together, then we may well be hiding the very problem you want us to solve......
|
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Wed Aug 17, 2016 1:27 am |
|
|
Agree, and not.. but I have got it working.
It is CCSC compilator - had to do clean, rebuild the code and it goes. For some odd reason it did the trick but I had to reboot PC. Yesterday 3 hours of fight no luck, today boot up, start CCS, rebuild and without any modifications spot on... very odd... _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Wed Aug 17, 2016 5:43 am |
|
|
My apologies... Since I am not a mind reader to know what is missing, in the future I will avoid looking at or commenting on your code.
Whatever code you showed us, <or> what is missing, this section is still in the wrong order regardless.
Fuses need to come right after the processor definition, then your #device line, then your #use lines, then your #includes and variables.
Code: | // CONFIG TABLES ==================
#include <18F4620.h> //libs from compiler
#device ADC=10 //analogue to digital converter init specs
#include <ctype.h> //libs from compiler
#include <stddef.h> //libs from compiler
#include <string.h> //libs from compiler
// ================================
// DEFINE =========================
//#define BUSSPEED 115200
//#define RX_PIN PIN_C7 // serial data receive pin
//#define TX_PIN PIN_C6 // serial data transmit pin
//#define TX_ON PIN_C5 // serial TX on
#define STATUS PIN_B2 // status led
//#define I2CSCL PIN_C3
//#define I2CSDA PIN_C4
// ================================
// FUSES ==========================
#FUSES H4
#FUSES MCLR
#FUSES BROWNOUT
#FUSES NODEBUG
#FUSES PROTECT // code protect
#FUSES CPB // boot block code protect
#FUSES CPD // data eeprom code protect
#FUSES NOEBTRB // boot block table code protect
#FUSES NOEBTR // table code protect
//#FUSES NOWDT,NOPROTECT,NOLVP
#FUSES WDT4096
#FUSES WDT
#FUSES PUT
#FUSES NOXINST
#use delay (clock=40M)
// ================================
// SYSTEM =========================
//#use rs232(baud=BUSSPEED,xmit=TX_PIN,rcv=RX_PIN,parity=n,bits=8,stop=1,ENABLE=TX_ON,ERRORS,TIMEOUT=15)
//#use i2c(slave, stream=main, sda=I2CSDA, scl=I2CSCL, address=0xA0, FORCE_HW, SMBUS)
#include "systemsetup.c"
//#include "variables.c" |
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Thu Aug 18, 2016 12:49 am |
|
|
Thnx, It is not my intention to upset everybody but please understand that it is hard to past program containing large pieces built out of many lines. ...many lines...
Thank you for directions on the order of the program. It is very good tip. I wish the compiler would throw indication on incorrect order of the statements.
I was more after experience in the compilation process which could affect the compilation when bootloader is added. Obviously the order of the statements may having something to do with it. So I will correct it and we see how it goes. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
|
|
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
|