mikroelektronika • view topic - i2c on a pic18f4620 not working at all

6
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 Post subject: I2C on a PIC18F4620 not working at all . . . Posted: 21 Mar 2006 10:52 Post subject: Oops . . . Posted: 23 Mar 2006 10:28 Login Register FAQ Search It is currently 22 Apr 2015 09:46 I2C on a PIC18F4620 not working at all . . . Page 1 of 1 [ 13 posts ] Print view Previous topic | Next topic Author Message reab Joined: 28 Aug 2005 20:43 Posts: 263 Location: West Sussex, United Kingdom I thought a new thread might be in order for this issue: 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; // configure for I2C ?? not sure how PORTD = 0; TRISD = 0; TRISE = 0; PORTE = 0; ADCON1 = 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 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. mikroElektronika • View topic - I2C on a PIC18F4620 not working at all . . . https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678 1 trong 6 4/22/2015 3:41 PM

Upload: danhis4

Post on 09-Nov-2015

8 views

Category:

Documents


1 download

DESCRIPTION

MikroElektronika • View Topic - I2C on a PIC18F4620 Not Working at All . .

TRANSCRIPT

  • 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

    Post subject: I2C on a PIC18F4620 not working at all . . . Posted: 21 Mar 2006 10:52

    Post subject: Oops . . . Posted: 23 Mar 2006 10:28

    Login Register FAQ Search

    It is currently 22 Apr 2015 09:46

    I2C on a PIC18F4620 not working at all . . .

    Page 1 of 1 [ 13 posts ]

    Print view Previous topic | Next topic

    Author Message

    reab

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

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

    I've upgraded my application from 16F877a - 18F452 to a PIC18F4620. I've managed to find work arounds for many issuesbut 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; // configure for I2C ?? not sure how PORTD = 0; TRISD = 0; TRISE = 0; PORTE = 0; ADCON1 = 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

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

    mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . . https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

    1 trong 6 4/22/2015 3:41 PM

  • Post subject: Re: Oops . . . Posted: 23 Mar 2006 13:14

    Post subject: I2C on PIC18F4620 not working Posted: 06 Feb 2008 04:41

    Post subject: 4620 - silicon errata Posted: 06 Feb 2008 05:08

    Post subject: Posted: 06 Feb 2008 10:41

    Post subject: Posted: 06 Feb 2008 13:21

    Posts: 263Location: West Sussex,United Kingdom 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

    mikroElektronika team

    Joined: 11 Oct 2004 08:53Posts: 823

    We will try it out and let you know.

    _________________pizon

    Top

    boattow

    Joined: 08 Mar 2007 03:00Posts: 60

    Hi,I found this post and others where it seems that people are not getting I2C to work on the PIC18F4620. There was neverany resolution posted here.

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

    Top

    Bob Lawrence

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

    /4620 PDF Here:

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

    Top

    bobbydavro

    Joined: 13 Nov 2007 14:50Posts: 64Location: UK

    Just wondering could you implement a I2C eeprom on your old chip?

    Top

    srdjan

    mikroElektronika team

    Joined: 28 Dec 2005 12:47Posts: 1552

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

    mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . . https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

    2 trong 6 4/22/2015 3:41 PM

  • Post subject: Yes Posted: 06 Feb 2008 13:32

    Post subject: Re: Yes Posted: 06 Feb 2008 13:37

    Post subject: Thanks! Posted: 06 Feb 2008 13:48

    Post subject: Thanks again Posted: 07 Feb 2008 02:59

    Post subject: Don't forget to post your corrections Posted: 07 Feb 2008 03:16

    Post subject: Posted: 07 Feb 2008 09:20

    Location: Serbia

    Top

    boattow

    Joined: 08 Mar 2007 03:00Posts: 60

    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

    mikroElektronika team

    Joined: 28 Dec 2005 12:47Posts: 1552Location: Serbia

    boattow wrote:

    Using the 18F4550 I had this communicating with a 24lc256 EEPROM, PCF8583 RTC, and 2 slave PICs in I2C slavemode. The code for the EEPROM is just the MEBasic example only 2 bytes used to address it. I think the erata thatBob posted will be the answer. I just won't be able to try it until this evening.FJ

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

    Top

    boattow

    Joined: 08 Mar 2007 03:00Posts: 60

    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 reportback here.FJ

    Top

    boattow

    Joined: 08 Mar 2007 03:00Posts: 60

    Thanks to Bob and SRDJAN, it works now. I greatly appreciate your help. FJ

    Top

    Bob Lawrence

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

    boattow,

    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:48Posts: 106Location: istanbul

    18f4620's Pin map seems so similar to 16F877. But 18f4620 contains more complicated structure. For ex. 877's RB portdoesn't contain any Analog input but 4620 contains and so on. So you have to set your initial values (if you want to useRB 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 thanyou need (not only serial eprom functions but also ploting them on your GLCD function).

    mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . . https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

    3 trong 6 4/22/2015 3:41 PM

  • 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 exactlocation of mem).void write_char(int high_addr, int low_addr, unsigned char *ch); //Writes char to serial eeprom (toexact location of mem).void write_text_to_lcd(int highadr, int start_adr, int end_adr, int coordx, int coordy); //Reads textof 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 (toexact 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 functionvoid 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(); // 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) Soft_I2C_Write(*ch); Soft_I2C_Stop();}//~ end of function

    //24C256 and 24C512 Serial EEPROM: reads text from EEPROM and writes it to LCDvoid write_text_to_lcd(int high_adr, int start_adr, int end_adr, int coordx, int coordy){

    int i_; for (i_=start_adr; i_

  • break; } }

    T6963C_write_text(take, coordx, coordy,1); //clears take array for (i_=0; i_

  • Board index Compilers mikroC Compilers Older versions of mikroC Compilers mikroC for PIC mikroC General All times are UTC + 1 hour

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

    Kind Regards,

    D.ELMASLI

    _________________R. Giskard Reventlov & R. Daneel Olivaw

    http://www.circuitechs.comhttp://www.dronology.com

    Top

    Display posts from previous: All posts Sort by Post time Ascending Go

    Page 1 of 1 [ 13 posts ]

    Who is online

    Users browsing this forum: No registered users and 4 guests

    You cannot post new topics in this forumYou cannot reply to topics in this forum

    You cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

    Search for: Go Jump to: mikroC General GoPowered by phpBB Forum Software phpBB Group

    mikroElektronika View topic - I2C on a PIC18F4620 not working at all . . . https://www.mikroe.com/forum/viewtopic.php?f=13&t=4678

    6 trong 6 4/22/2015 3:41 PM