|
|
View previous topic :: View next topic |
Author |
Message |
jackeberson
Joined: 25 Mar 2006 Posts: 1
|
porting code from a 18F252 to a 18F2525 controller |
Posted: Sun Mar 26, 2006 3:13 am |
|
|
Hi,
I want to use a 18F2525 because it has more RAM and EEPROM on board than the 18F252 controller.
I am using I2C as a slave and have string tables in FLASH.
I am using the CCS c-compiler 3.214 windows version and the TinyBoot bootloader.
I have 2 serious problems making it not work:
- my "strcpy" routines don't work anymore (sometimes yes, sometimes no). I have worked around this problem....(not a nice solution)
- reading the slave with the I2C_Write() routine seems to hang the I2C-bus. (Writing to the slave works perfect!). I played around with the I2C compiler settings but had no success.
I was wandering:
1) are there known bugs in the compiler related to these problems
2) are there known bugs in the PIC18F2525 (I2C bus related)
3) does anyone have similar problems....
The I2C pis have been connected to a P82B715 bus buffer.
The application works without problems on a 18F252 controller....
Hope to find the answers here....
Thanks in advance.
Jack. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 26, 2006 4:56 pm |
|
|
Quote: |
- my "strcpy" routines don't work anymore
|
If you can post a small test program (like 10 lines, max) that shows
the problem, it's possible we could help. The test program should
be a complete, compilable, testable program with #include, #fuses,
and any applicable #use statements. |
|
|
jack eberson Guest
|
porting from 18F252 to 18F2525 |
Posted: Mon Mar 27, 2006 1:11 am |
|
|
Hi,
This example file which comes with the CCS compiler works fine on the 18F252 with does not work on the 18F2525 (or 18F2620)...
///////////////////////////////////////////////////////////////////////////
//// EX_SLAVE.C ////
//// ////
//// This program uses the PIC in I2C slave mode to emulate the ////
//// 24LC01 EEPROM. You can write to addresses 00h to 0Fh with it. ////
//// ////
//// This program is to be used in conjunction with the ex_extee.c ////
//// sample. Use the "#include <2402.C>" or "#include <2401.c>". ////
//// Only 16 bytes of address space are implemented, however. ////
//// ////
//// If using a compiler version before 2.639 add "*0x14 = 0x3E;" to ////
//// the begining of main(), and add "NOFORCE_SW" as the last ////
//// parameter in the #use i2c directive. ////
//// ////
//// This example will work with the PCM and PCH compilers. The ////
//// following conditional compilation lines are used to include a ////
//// valid device for each compiler. Change the device, clock and ////
//// RS232 pins for your hardware if needed. ////
/////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
/////////////////////////////////////////////////////////////////////////
#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 <18F452.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
#endif
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xa0)
typedef enum {NOTHING, CONTROL_READ,
ADDRESS_READ, READ_COMMAND_READ} I2C_STATE;
I2C_STATE fState;
BYTE address, buffer[0x10];
#INT_SSP
void ssp_interupt ()
{
BYTE incoming;
if (i2c_poll() == FALSE) {
if (fState == ADDRESS_READ) { //i2c_poll() returns false on the
i2c_write (buffer[address]);//interupt receiving the second
fState = NOTHING; //command byte for random read operation
}
}
else {
incoming = i2c_read();
if (fState == NOTHING){
fState = CONTROL_READ;
}
else if (fState == CONTROL_READ) {
address = incoming;
fState = ADDRESS_READ;
}
else if (fState == ADDRESS_READ) {
buffer[address] = incoming;
fState = NOTHING;
}
}
}
void main ()
{
int i;
fState = NOTHING;
address = 0x00;
for (i=0;i<0x10;i++)
buffer[i] = 0x00;
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while (TRUE) {}
}
what works: I can write data to the slave; no problem
what fails: reading data from the slave; uC hangs.
I did:
- change the include file to 18F252, recompile and upoad to uC: still not working
- I uploaded the HEX file from the working 18F252 uC: still not working.
Hope someone has any idea what goes wrong......
Thanks in advance for helping me out.....
Jack. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|