Sunteți pe pagina 1din 6

mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . .

1 trong 6

Login

https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

Register

FAQ

Search

It is currently 22 Apr 2015 09:46

View unanswered posts | View active topics


Board index Compilers mikroC Compilers Older versions of mikroC Compilers mikroC for PIC mikroC General

All times are UTC + 1 hour

I2C on a PIC18F4620 not working at all . . .


Page 1 of 1 [ 13 posts ]
Print view

Previous topic | Next topic

Author
reab

Message
Post subject: I2C on a PIC18F4620 not working at all . . .

Posted: 21 Mar 2006 10:52

I thought a new thread might be in order for this issue:


Joined: 28 Aug 2005 20:43
Posts: 263
Location: West Sussex,
United Kingdom

I've upgraded my application from 16F877a - 18F452 to a PIC18F4620. I've managed to find work arounds for many issues
but this latest one defies me. I2C refuses to work and as I store many of my LCD message strings in a 512kbit device
(which up to now has worked perfectly) it causes me a few issues.
The data sheet for PIC18F4620 states that I should separately initialise the port pins but I'm struggling with this.
So far this is a snippet of how I set it up - I use ME's I2C library in my routines which up to now have worked well:
Code: Select all

PORTA

0;

TRISA

0;

PORTB

0;

TRISB

0;

PORTC

0;

TRISC

0;

PORTD

0;

TRISD

0;

TRISE

0;

PORTE

0;

ADCON1 =

// configure for I2C ?? not sure how

0x0F;

PORTA.F5 = 1;

PORTC.F3 = 1;
PORTC.F4 = 1;
SSPCON1.SSPEN = 1;

// enable I2C bit for serial communication

Have I used the correct syntax and is it the correct order and which of the I2C pins (RC3/RC4) are input or output?
Any pointers would be helpfull - original thread was: http://www.mikroe.com/forum/viewtopic.php?t=4400
Roger B
_________________
Be kind and like your words - you never know, you may have to eat them one day!

Top

reab

Joined: 28 Aug 2005 20:43

Post subject: Oops . . .

Posted: 23 Mar 2006 10:28

Just a little bit of update information. After working at this I've now changed and used the soft I2C library routines
instead on this device and all seems to work ok again. Only question is why as the data sheet seems to state that apart
from possible register settings it should be compatible with the earlier devices.

4/22/2015 3:41 PM

mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . .

2 trong 6

Posts: 263
Location: West Sussex,
United Kingdom

https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

Ah well . . . it would be nice to understand whats happening though . .


Roger B
_________________
Be kind and like your words - you never know, you may have to eat them one day!

Top

pizon

Post subject: Re: Oops . . .

Posted: 23 Mar 2006 13:14

We will try it out and let you know.


mikroElektronika team
Joined: 11 Oct 2004 08:53
Posts: 823

_________________
pizon

Top

boattow

Joined: 08 Mar 2007 03:00


Posts: 60

Post subject: I2C on PIC18F4620 not working

Posted: 06 Feb 2008 04:41

Hi,
I found this post and others where it seems that people are not getting I2C to work on the PIC18F4620. There was never
any resolution posted here.
I have a project using MEBasic. I was using the PIC18F4550. It talks to the character LCD, A2D (displays battery
voltage), talks to user hardware, reads buttons, and of course talks to several devices over I2C such as the Philips real
time clock. I started running out of program memory so I got a PIC18F4620 which looks to be virtually the same chip as
the 4550 except the lack of USB but twice the memory. I put it in after programming it and it seems to work as it
displays the opening LCD message and the battery voltage but seems to stop working when it gets to the I2C comm with
the RTC. Is there a change I need to make in software or configuration bits when changing controllers? I set the flash
program software to the new processor, changed it from 48Mhz to 40Mhz as well as the crystal but not working, just as
others have stated in other posts here. Anyone have any ideas?
Thanks,
FJ

Top

Bob Lawrence

Post subject: 4620 - silicon errata

Posted: 06 Feb 2008 05:08

/4620 PDF Here:


Joined: 18 Aug 2004 11:55
Posts: 300
Location: Lwr Sackville, Nova
Scotia, Canada

http://ww1.microchip.com/downloads/en/D ... 80224c.pdf

Top

bobbydavro

Post subject:

Posted: 06 Feb 2008 10:41

Just wondering could you implement a I2C eeprom on your old chip?
Joined: 13 Nov 2007 14:50
Posts: 64
Location: UK
Top

srdjan

mikroElektronika team

Post subject:

Posted: 06 Feb 2008 13:21

Hi,
Refer to this post
http://www.mikroe.com/forum/viewtopic.php?t=12648&highlight=i2c

Joined: 28 Dec 2005 12:47


Posts: 1552

4/22/2015 3:41 PM

mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . .

3 trong 6

https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

Location: Serbia
Top

boattow

Joined: 08 Mar 2007 03:00


Posts: 60

Post subject: Yes

Posted: 06 Feb 2008 13:32

Bobbydavro:
Using the 18F4550 I had this communicating with a 24lc256 EEPROM, PCF8583 RTC, and 2 slave PICs in I2C slave mode.
The code for the EEPROM is just the MEBasic example only 2 bytes used to address it.
FJ
Last edited by boattow on 06 Feb 2008 13:42, edited 1 time in total.

Top

srdjan

Post subject: Re: Yes

Posted: 06 Feb 2008 13:37

boattow wrote:
mikroElektronika team

Using the 18F4550 I had this communicating with a 24lc256 EEPROM, PCF8583 RTC, and 2 slave PICs in I2C slave
mode. The code for the EEPROM is just the MEBasic example only 2 bytes used to address it. I think the erata that
Bob posted will be the answer. I just won't be able to try it until this evening.
FJ
Joined: 28 Dec 2005 12:47
Posts: 1552
Location: Serbia

Yes, the post I have referred you to has the exact portion of the errata, Bob was talking about, which is describing the
silicon bug causing the pic18f4620 i2c module not to work and the appropriate workaround.

Top

boattow

Joined: 08 Mar 2007 03:00


Posts: 60

Post subject: Thanks!

Posted: 06 Feb 2008 13:48

SRDJAN and Bob,


I'm sure this is the problem I'm having. Thanks for taking the time to help me. I will try fixing it this evening and report
back here.
FJ

Top

boattow

Post subject: Thanks again

Posted: 07 Feb 2008 02:59

Thanks to Bob and SRDJAN, it works now. I greatly appreciate your help.
FJ
Joined: 08 Mar 2007 03:00
Posts: 60
Top

Bob Lawrence

Post subject: Don't forget to post your corrections

Posted: 07 Feb 2008 03:16

boattow,
Joined: 18 Aug 2004 11:55
Posts: 300
Location: Lwr Sackville, Nova
Scotia, Canada

I'm glad you got it working.

If you post what you changed it may help someone else.

Bob

Top

dronology

Joined: 29 Dec 2007 23:48


Posts: 106
Location: istanbul

Post subject:

Posted: 07 Feb 2008 09:20

18f4620's Pin map seems so similar to 16F877. But 18f4620 contains more complicated structure. For ex. 877's RB port
doesn't contain any Analog input but 4620 contains and so on. So you have to set your initial values (if you want to use
RB as digital i/o you need to disable ADCON and etc.) at the beginning of your code.
I wrote codes (some functions) for serial eeproms 1 week ago based on SoftI2C's. In these functions I'll give more than
you need (not only serial eprom functions but also ploting them on your GLCD function).

4/22/2015 3:41 PM

mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . .

4 trong 6

https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

Code: Select all

//**** VARIABLE DECLARATIONS********


unsigned char take[35];

//**** DEFINITION OF FUNCTIONS********


void read_char(int high_addr, int low_addr, char *ch);

//Reads char from serial eeprom (from exact

location of mem).
void write_char(int high_addr, int low_addr, unsigned char *ch);

//Writes char to serial eeprom (to

exact location of mem).


void write_text_to_lcd(int highadr, int start_adr, int end_adr, int coordx, int coordy);

//Reads text

of given mem address and space and writes that text to GLCD (T6963)
void write_text_to_memo(int high_addr, int low_addr, char *text);

//Writes text to serial eeprom (to

exact location of mem).


void Zero_Fill(char *value);

//**** DECLARATION OF FUNCTIONS********


//Reads char from serial eeprom (from exact location of mem).
//24C256 and 24C512 Serial EEPROM char reader function
void read_char(int high_addr, int low_addr, unsigned char *ch){
Soft_I2C_Start();
Soft_I2C_Write(0xA0);

// device address

Soft_I2C_Write(0x00+high_addr); // send byte (data address H)


Soft_I2C_Write(0x00+low_addr); // send byte (data address L)
Soft_I2C_Stop();
Soft_I2C_Start();
Soft_I2C_Write(0xA1);
*ch = Soft_I2C_Read(0);
Soft_I2C_Stop();
}//~ end of function

//Writes char to serial eeprom (to exact location of mem).


void write_char(int high_addr, int low_addr, unsigned char *ch){
Soft_I2C_Start();
Soft_I2C_Write(0xA0);

// Issue start signal


// device address

Soft_I2C_Write(0x00+high_addr); // send byte (data address H)


Soft_I2C_Write(0x00+low_addr); // send byte (data address L)
Soft_I2C_Write(*ch);
Soft_I2C_Stop();
}//~ end of function

//24C256 and 24C512 Serial EEPROM: reads text from EEPROM and writes it to LCD
void write_text_to_lcd(int high_adr, int start_adr, int end_adr, int coordx, int coordy){
int i_;
for (i_=start_adr; i_<end_adr; ++i_){
read_char(high_adr, i_, &take[i_-start_adr]);
if(take[i_-start_adr]=='^'){
take[i_-start_adr]=' ';
Zero_Fill(take);

4/22/2015 3:41 PM

mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . .

5 trong 6

https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

break;
}
}
T6963C_write_text(take, coordx, coordy,1);
//clears take array
for (i_=0; i_<35; ++i_){
take[i_]=0;
}
}//~ end of function

//24C256 and 24C512 Serial EEPROM: write text to EEPROM function


void write_text_to_memo(int high_addr, int low_addr, char *text){
int i_, len;
len = strlen(text);
Soft_I2C_Start();

// Issue start signal

Soft_I2C_Write(0xA0);

// device address

Soft_I2C_Write(0x00+high_addr); // send byte (data address H)


Soft_I2C_Write(0x00+low_addr); // send byte (data address L)
for(i_=0; i_ < len; ++i_){
Soft_I2C_Write(text[i_]);
}
Soft_I2C_Stop();
}//~ end of function

//fills zeros to empty elements of text array


//this is not function that I wrote but it works well. you can find the source of this func. in this
forum.
void Zero_Fill(char *value) {
if (value[1] == 0) {

// fill text repesentation


//

with leading zero

value[1] = value[0];
value[0] = 48;
value[2] = 0;
}
}//~ end of function

In my programs the array of take[35] defined globally. It is being used as a ALU. After each operation if you keep it
empty you ca your main program You need to
and this part of write_text_to_lcd function:

Code: Select all

if(take[i_-start_adr]=='^'){
take[i_-start_adr]=' ';
Zero_Fill(take);
break;
}

I splited the string datas of in the serial eeprom by using "^" symbol. When the program read cycle comes to this line it
will see this symbol and when reading from eprom it will cut its reading. This is a some kind of end of line. But you
don't need to act like this. Only address info will be enough for you as it is described in write_text_to_memo function,
on the other meaning only and only start address and size of text is enough for putting your string to exact location and

4/22/2015 3:41 PM

mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . .

6 trong 6

https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

getting end of it. In these technics write_text_to_lcd and write_text_to_memo functions differ from each other. But
both of them work.

Kind Regards,
D.ELMASLI
_________________
R. Giskard Reventlov & R. Daneel Olivaw
http://www.circuitechs.com
http://www.dronology.com

Top

Display posts from previous: All posts

Sort by Post time

Ascending

Go

Page 1 of 1 [ 13 posts ]

Board index Compilers mikroC Compilers Older versions of mikroC Compilers mikroC for PIC mikroC General

All times are UTC + 1 hour

Who is online
Users browsing this forum: No registered users and 4 guests
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 post attachments in this forum
Search for:

Go

Jump to:

mikroC General

Go

Powered by phpBB Forum Software phpBB Group

4/22/2015 3:41 PM

S-ar putea să vă placă și