|
|
View previous topic :: View next topic |
Author |
Message |
MOONG Guest
|
help please problem with bootloader pic 16f877 |
Posted: Mon Jul 12, 2004 8:11 am |
|
|
I developed a bootloader for 16f877, I call it from other function but when addr arrive at 710 then stop and no continue.Previously at the function bootloader I receive de data from serial directly in hex format to i2c e2prom, then I start the process to load it.
#define LOADER_END 0x1FFF
#define LOADER_SIZE 0x14D
#define LOADER_ADDR LOADER_END-LOADER_SIZE
#ORG LOADER_ADDR, LOADER_END auto=0 default
void real_load_program (void)
{
byte temp,count,checksum,line_type,buffidx;
int1 done=FALSE;
int16 x,addr,buffer[8];
x=9100; //address of e2prom where de data is located.
while (!done)
{
SYSLED=!SYSLED;
i2c_start();
i2c_write(0xA0);
i2c_write((*(&x+1)));
i2c_write(x);
i2c_start();
i2c_write(0xA1);
temp=i2c_read();x++;
count=i2c_read();x++;
count/=2;
addr=make16(i2c_read(),i2c_read());
addr/=2;
x+=2;
line_type=i2c_read();x++;
for (buffidx=0;buffidx<count;buffidx++)
{
buffer[buffidx]=make16(i2c_read(),i2c_read());
x+=2;
}
checksum=i2c_read(0);x++;
i2c_stop();
if (temp == ':')
{
if (line_type == 1)
{
done = TRUE;
}
else
{
if (addr<(LOADER_SIZE) || addr>(0x21FF))
{
for (buffidx=0;buffidx<count;buffidx++)
write_program_eeprom((addr+buffidx),Buffer[buffidx]);
}
}
}
}
reset_cpu();
}
#ORG default |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Jul 12, 2004 5:30 pm |
|
|
Where is your #use i2c located? You might be over-writing the i2c functions while re-programming the chip. |
|
|
MOONG Guest
|
|
Posted: Tue Jul 13, 2004 3:56 am |
|
|
ops maybe this is the problem. Can I do This?
ORG 0xXXXX, 0xXXXX
#use i2c (....);
Thanks |
|
|
Guest
|
|
Posted: Tue Jul 13, 2004 7:09 am |
|
|
Ok, now I modify the code, and the function goes to end, but my CPU don't start, can anybody help me?
#define LOADER_END 0x1FFF-0xFF
#define LOADER_SIZE 0x18E
#define LOADER_ADDR LOADER_END-LOADER_SIZE
#ORG LOADER_ADDR, LOADER_END auto=0 default
void real_load_program (void)
{
int1 done=FALSE;
int16 x,addr,buffer[8];
byte temp,count,checksum,line_type,buffidx;
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)
x=9100;
while (!done)
{
i2c_start();
i2c_write(0xA0);
i2c_write((*(&x+1)));
i2c_write(x);
i2c_start();
i2c_write(0xA1);
temp=i2c_read();x++;
count=i2c_read();x++;
count/=2;
addr=make16(i2c_read(),i2c_read());
//addr/=2;
x+=2;
line_type=i2c_read();x++;
for (buffidx=0;buffidx<count;buffidx++)
{
buffer[buffidx]=make16(i2c_read(),i2c_read());
x+=2;
}
checksum=i2c_read(0);x++;
i2c_stop();
if (temp == ':')
{
SYSLED=!SYSLED;
if (line_type == 1)
done = TRUE;
else
{
if (addr<LOADER_ADDR)
{
for (buffidx=0;buffidx<count;buffidx++)
write_program_eeprom((addr+buffidx),Buffer[buffidx]);
}
else
goto fin;
}
}
}
fin:
reset_cpu();
}
#ORG default |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Jul 13, 2004 5:20 pm |
|
|
How did you detect that the function reaches the end? Are you using ICD?
If so, remember the ICD needs to put a small peice of code at the end of the program memory for debugging purposes. Your code doesn't allow for it:
#define LOADER_END 0x1FFF-0xFF
#define LOADER_SIZE 0x18E
#define LOADER_ADDR LOADER_END-LOADER_SIZE
If you are using ICD, this will cause your code to derail and may give the impression that the function has reached the end. So in this case you'll need to change the LOADER_SIZE constant to allow for the ICD code. A value of 0x400 is probably enough. |
|
|
|
|
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
|