Jump to content
Sign in to follow this  
fischp

I2c Example Error

Recommended Posts

Gentlemen,

 

The i2c example program in the C/BoostC directory fails to compile for me. I'm using SB 5.9.7 with all of the latest patches. I've tried several different PICs including the 16f767 and some higher end 18fs.

 

When I complile the program I get:

 

BoostC Optimizing C Compiler Version 2.2.5 Beta (for PIC18 architecture)

http://www.picant.com/c2c/c.html

Copyright© 2004-2005 Pavel Baranov

Copyright© 2004-2005 David Hobday

 

 

line 70: Illegal redefinition of symbol: PORTC

line 71: Illegal redefinition of symbol: TRISC

 

2 errors detected

Error: preprocessing error

failure

Exit code was 1.

Removing target: I2C_Test.obj

Failed to locate output file 'I2C_Test.obj'

Done

 

Failed

 

Help!

 

Thanks!

 

P.S. Here's the source code:

 

////////////////////////////////////////////////////////////////////////////

// I2C Communications Test Program

//

// Exercises the i2c driver code in <i2c_driver.h> by demonstrating

// reading and writing to an External EEPROM

////////////////////////////////////////////////////////////////////////////

// Author(s): Andrew Smallridge

// Date 15 November 2004

//

// Copyright © 2004-2005 Andrew Smallridge

// Copyright © 2004-2005 Pavel Baranov

// Copyright © 2004-2005 David Hobday

////////////////////////////////////////////////////////////////////////////

#pragma CLOCK_FREQ 40000000

 

#include <system.h>

#include <i2c_driver.h>

 

////////////////////////////////////////////////////////////////////////////

// i2c master hardware / software mode definition

//

// For i2c hardware support comment out the #define use_ic2_SW line

////////////////////////////////////////////////////////////////////////////

//#define use_i2c_SW

//

#if defined use_i2c_SW

////////////////////////////////////////////////////////////////////////////

// i2c software implementation template arguments

////////////////////////////////////////////////////////////////////////////

#define i2c_ARGS 3, PORTC, TRISC, 4, PORTC, TRISC, e_SSPCON1, e_SSPCON2, \

e_SSPSTAT, e_SSPBUF, e_SSPIF_BIT, e_SSPIF_PIR, \

e_BCLIF_BIT, e_BCLIF_PIR, 7, e_SSPADD, (i2c_reset_wdt | i2c_SMP)

 

// RAM used by the software i2c driver to emulate the equivalent i2c hardware registers

unsigned short swi2c_SSPCON1@0x40; // define location for the emulated SSPCON1

unsigned short swi2c_SSPCON2@0x41; // define location for the emulated SSPCON2

unsigned short swi2c_SSPSTAT@0x42; // define location for the emulated SSPSTAT

unsigned short swi2c_SSPBUF@0x43; // define location for the emulated SSPBUF

unsigned short swi2c_SSPIF_PIR@0x44;// define location for the emulated SSPIF_PIR

unsigned short swi2c_BCLIF_PIR@0x45;// define location for the emulated BCLIF_PIR

unsigned short swi2c_SSPADD@0x46; // define location for the emulated SSPADD

 

// variables cannot be passed as template arguments. The following constants map to

// the PIC registers and software emalated i2c RAM locations. These constants are

// then used by the templated functions. When changing the address of an emulated

// register the corresponding constant mapping must also be changed.

#define PORTC 0x0f82

#define TRISC 0x0f94

#define e_SSPCON1 0x40

#define e_SSPCON2 0x41

#define e_SSPSTAT 0x42

#define e_SSPADD 0x43

#define e_SSPBUF 0x44

#define e_SSPIF_PIR 0x45

#define e_BCLIF_PIR 0x46

#define e_SSPIF_BIT 3

#define e_BCLIF_BIT 3

 

#else

////////////////////////////////////////////////////////////////////////////

// i2c hardwareware implementation template arguments

////////////////////////////////////////////////////////////////////////////

#define i2c_ARGS 3, PORTC, TRISC, 4, PORTC, TRISC, e_SSPCON1, e_SSPCON2, \

e_SSPSTAT, e_SSPBUF, e_SSPIF_BIT, e_SSPIF_PIR, \

e_BCLIF_BIT, e_BCLIF_PIR, 7, e_SSPADD, (i2c_reset_wdt | i2c_SMP |i2c_HW)

 

// variables cannot be passed as template arguments. The following constants map to

// the PIC registers and PIC's i2c register locations. These constants are

// then used by the templated functions.

#define PORTC 0x0f82

#define TRISC 0x0f94

#define e_SSPCON1 0xfc6

#define e_SSPCON2 0xfc5

#define e_SSPSTAT 0xfc7

#define e_SSPADD 0xfc8

#define e_SSPBUF 0xfc9

#define e_SSPIF_PIR 0xf9e

#define e_BCLIF_PIR 0xfa1

#define e_SSPIF_BIT 3

#define e_BCLIF_BIT 3

 

#endif

 

 

////////////////////////////////////////////////////////////////////////////

// TEST CODE - I2C Device constants

////////////////////////////////////////////////////////////////////////////

 

// define External EEPROM I2C slave (Hardware) addresses

#define xee_slave 0xA0 // Base address of 24C512 EEPROM

 

 

 

////////////////////////////////////////////////////////////////////////////

// Read from the External EEPROM

////////////////////////////////////////////////////////////////////////////

// s is a pointer to the destination buffer to data read from the EEPROM

// HW_address is the hardware address of the i2c device

// ic2_addr is the target internal address within the External EEPROM

// count is the number of bytes to be read starting at i2c_addr

void read_XEE(char *s, char HW_address, unsigned short i2c_addr, unsigned short count)

{

short i;

 

i2c_start();

i2c_write(HW_address); // send XEE i2c address

i2c_write(i2c_addr >> 8); // send XEE internal HIGH address

i2c_write((char) i2c_addr & 0x00ff); // send XEE internal LOW address

i2c_restart(); // send i2c_restart

 

// sending XEE read command via i2c_write

i2c_write(HW_address | 0x01); // send device address + RD to I2C device

 

// XEE read loop

for (i=0;i<count-1;i++)

*s++ = i2c_read(0);

*s++ = i2c_read(1);

*s = 0;

 

i2c_stop();

}

 

////////////////////////////////////////////////////////////////////////////

// Write to the External EEPROM

////////////////////////////////////////////////////////////////////////////

// s is a pointer to the string to be written to the EEPROM

// HW_address is the hardware address of the i2c device

// ic2_addr is the target internal address within the External EEPROM

// count is the number of bytes to be written starting at i2c_addr

void write_XEE(char *s, char HW_address, unsigned short i2c_addr, unsigned short count)

{

short i;

 

i2c_start();

i2c_write(HW_address); // send XEE i2c address

i2c_write(i2c_addr >> 8); // send XEE internal HIGH address

i2c_write((char) i2c_addr & 0x00ff); // send XEE internal LOW address

 

// XEE write loop

for (i=0;i<count;i++)

i2c_write(*s++);

i2c_stop();

}

 

////////////////////////////////////////////////////////////////////////////

// Return the length of a string

////////////////////////////////////////////////////////////////////////////

char strlen(char *s)

{

char i;

 

for (i = 0; *s != 0; i++)

s++;

return(i);

}

 

 

void main()

{

char buffer[32];

char *mesg = "i2c Test String";

char *s1;

char i;

 

unsigned short i2c_addr; // used for internal addressing for the target I2C device

 

#define I2C_divisor 0x7E

// set the divisor for the I2C clock

// for software I2C emulation this can be any value (such as 1)

i2c_init(I2C_divisor);

 

// demonstrating a write to address 0x0210 in External EEPROM

i2c_addr = 0x0210;

write_XEE(mesg, xee_slave, i2c_addr, strlen(mesg)+1);

 

// The External EEPROM requires a delay to finish

// programming the flash before it can be accessed again

delay_ms(10);

 

// demonstrating a read 16 bytes from address 0x0214 in External EEPROM

i2c_addr = 0x0214;

s1 = buffer; // point s1 to the work buffer

read_XEE(s1, xee_slave, i2c_addr, 16);

 

while (1);

}

Share this post


Link to post
Share on other sites
Gentlemen,

 

The i2c example program in the C/BoostC directory fails to compile for me.  I'm using SB 5.9.7 with all of the latest patches.  I've tried several different PICs including the 16f767 and some higher end 18fs.

 

When I complile the program I get:

 

BoostC Optimizing C Compiler Version 2.2.5 Beta (for PIC18 architecture)

http://www.picant.com/c2c/c.html

Copyright© 2004-2005 Pavel Baranov

Copyright© 2004-2005 David Hobday

 

 

line 70: Illegal redefinition of symbol: PORTC

line 71: Illegal redefinition of symbol: TRISC

 

2 errors detected

 

Comment out the two lines

#define PORTC 0x0f82

#define TRISC 0x0f94

 

Regards, Andrew

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...