• AVR Freaks

Hot!PIC18F47K42 - Master I2C @ 100KHz using OLED display

Author
WGANDOL
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2019/09/26 05:09:25
  • Location: 0
  • Status: offline
2020/07/27 11:33:51 (permalink)
3 (1)

PIC18F47K42 - Master I2C @ 100KHz using OLED display

I am working on the migration of a software routine from PIC18F46K22 to PIC18F47K42 and I am not having success with the use of I2C using an OLED display.
 
I used the MCC to configure the I2C module but I had no results.
 
I'm using the internal oscillator @ 8MHz.
 
Follow my routines:
 
void I2C2_Initialize(void)
{

       TRISBbits.TRISB1 = 0;
       TRISBbits.TRISB2 = 0;

       ANSELBbits.ANSELB1 = 0;//SCL2
       ANSELBbits.ANSELB2 = 0;//SDA2

      // Configure the pins as Open-drain
     ODCONBbits.ODCB1 = 1;
     ODCONBbits.ODCB2 = 1;

    // Set the I2C levels
    //RB1I2Cbits.TH = 0b01;
    RB1I2C = 0x01;
    SLRCONBbits.SLRB1 = 0;

    //RB2I2Cbits.TH = 0b01;
    RB2I2C = 0x01;
    SLRCONBbits.SLRB2 = 0;
        
   // Set RB1 for SCL
   I2C2SCLPPS = 0x09;
   RB1PPS = 0x23;

   // Set RB2 for SDA
   RB2PPS = 0x24;
   I2C2SDAPPS = 0x0A;
 
   
   I2C2CON0bits.EN = 0;

   I2C2BTO = 0;
   I2C2PIE = 0;
   I2C2PIR = 0;
   I2C2ERR = 0;
   I2C2STAT0 = 0;
   I2C2STAT1 = 0;

   I2C2CON0 = 0x04;

   I2C2CON1 = 0x80;
   //I2C2CON2 = 0x18;
   I2C2CON2 = 0x21;

   I2C2CLK = 0x00;

   I2C2ADR0 = 0; // ADR<7:0> *addr buf disabled
   I2C2ADR1 = 0; // ADR<7:1>
   I2C2ADR2 = 0; // ADR<7:0>
   I2C2ADR3 = 0; // ADR<7:1>
   I2C2ADB0 = 0; // ADB<7:0>
   I2C2ADB1 = 0; // ADB<7:0>
   I2C2CNT = 0; // CNT<7:0>
   I2C2RXB = 0; // RXB<7:0>
   I2C2TXB = 0; // TXB<7:0>
 
   I2C2CON0bits.EN = 1;
}
 
void Oled_Command (unsigned char cmd)
{
     /*---------------------  functional code used in PIC18F46K22  -------------------------*/
      //I2C_Start();
     // I2C_WriteByte(OLED_12C_ADDRESS);//0x78
     // I2C_WriteByte(0x00); // Co = 0, D/C = 0
     // I2C_WriteByte(cmd);
     // I2C_Stop();
    /*------------------------------------------------------------*/
 
 
      I2C2_Initialize ();

     I2C2ADB1 = OLED_12C_ADDRESS;
     I2C2TXB = 0x00;
     I2C2CNT = 2;
     I2C2CON0bits.S = 1;

     I2C2PIRbits.PCIF = 0;

     sendByte(cmd);

     wait4Stop();
}
 
 
 
 
Can you help me?
#1

2 Replies Related Threads

    typematrix
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2019/03/04 08:11:26
    • Location: Ireland
    • Status: offline
    Re: PIC18F47K42 - Master I2C @ 100KHz using OLED display 2020/08/03 11:12:12 (permalink)
    0
     
     
    Which OLED?
     
    I assume the 128 by 64 pixels SSD1306 I2C bus.
     
    Here is a working recent  example of IC2 MCC functions working for this OLED for this PIC 
    https://github.com/gavinlyonsrepo/pic_18F47K42_projects/tree/master/projects/OLED_LM35
    post edited by typematrix - 2020/08/04 10:19:48
    #2
    Jerry Messina
    Super Member
    • Total Posts : 550
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: PIC18F47K42 - Master I2C @ 100KHz using OLED display 2020/08/03 11:33:43 (permalink)
    +1 (1)
    In my opinion, if you have code working on an 18F46K22 it would be easier to throw away the MCC code
    and just write a set of routines to bit-bang the I2C sequences (start, stop, write byte, etc). There are plenty of examples and app notes showing how to do that.
     
    The I2C peripheral on the K42 is very different from the MSSP peripheral of the K22.
     
     
    #3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5