pic16f886 + i2c+ raspberry pi

Here you can find latest news on mikroElektronika products.
Post Reply
Author
Message
superino
Posts: 3
Joined: 29 Jun 2016 03:49

pic16f886 + i2c+ raspberry pi

#1 Post by superino » 29 Jun 2016 06:09

Hello im new on the forum and i have a big problem..
im going to do a matrix of led RGB 5x5, that i can control with the raspberry pi 2 the problem is that i need more outputs thats why i want to connect with a pic 16f886 through the protocol i2c.
but i dont find any guide how can i do this program in mikro c if somebody can help me i would appreciate
:( thanks

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: pic16f886 + i2c+ raspberry pi

#2 Post by lana.arsic » 29 Jun 2016 14:31

Hi superino,

Welcome to the MikroE forum.

I suggest you to use our 4x4 RGB click:

http://www.mikroe.com/click/4x4-rgb/

and one of our clicker boards:

http://www.mikroe.com/clicker/

Best regards,
Lana

superino
Posts: 3
Joined: 29 Jun 2016 03:49

Re: pic16f886 + i2c+ raspberry pi

#3 Post by superino » 11 Jul 2016 21:56

hii lana.arsic i already desing my matriz of leds im just having problem with the code to write in mikro c to make the pic as slave i just need he recive 2 bytes of information.
i try to conect the pic with
vdd 5v
vss ground
scl scl raspi
sda sda raspi
and dont detect the pic i dont know if i have problems with the code..

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: pic16f886 + i2c+ raspberry pi

#4 Post by lana.arsic » 12 Jul 2016 14:24

Hi superino,

Unfortunately, mikroC provides library which supports only the master I²C mode,
but maybe you can find these threads useful:

http://forum.mikroe.com/viewtopic.php?f=97&t=8106

http://forum.mikroe.com/viewtopic.php?t=3223

Or, maybe you can consider to use UART instead.

Best regards,
Lana

checker
Posts: 77
Joined: 22 May 2011 10:58

Re: pic16f886 + i2c+ raspberry pi

#5 Post by checker » 13 Jul 2016 06:44

lana.arsic wrote:Or, maybe you can consider to use UART instead.
I agree with this answer, you will use the same amount of pins and UART in my opinion is easier to implement for one or two way control.

other options would be using shift registers or port expander to save on programming and maybe speed increase. The world is your canvas, plenty of options so don't get fixated on only one.

superino
Posts: 3
Joined: 29 Jun 2016 03:49

Re: pic16f886 + i2c+ raspberry pi

#6 Post by superino » 03 Aug 2016 20:04

This is the code im doing but my raspberry still dont detect the pic.. i try to use internal oscilator INTOSC or INTOSCIO using 8Mhz please if sombody know any anwserrrr

Code: Select all

void Init(){
     ADCON1 = 0;                          // All ports set to digital
     TRISA= 0X00;
     TRISB= 0X00;
     TRISC= 0b00011000;                   // puerto C a salida
     TRISC3_bit = 1;                      // Configurar I2C SCL pin
     TRISC4_bit = 1;                      // Configurar I2C SDA pin
     SSPADD= 0X69;
     SSPCON = 0x36;                       // Direccion esclavo
     PIE1.SSPIF = 1;                      // enable SSP interrupts
     INTCON = 0xC0;                       // enable INTCON.GIE
     OSCCON.IRCF0=1;
     OSCCON.IRCF1=1;
     OSCCON.IRCF2=1;

     
}
void interrupt(){  
if (band == 0 ){                             //
  if (PIR1.SSPIF == 1){                   // I2C Interrupcion
    PIR1.SSPIF = 0;                      // reinicia la bandera
    }
    if (SSPSTAT.BF == 0){               // all done,
      color = SSPBUF;
      band=1;                         // bandera en uno
      return;
    } 
    }
    //recieve data from master
    else{
    if (SSPSTAT.D_A == 1){             // Data
      byte = SSPBUF;                  // get data
      return;
    }
      }
   }

checker
Posts: 77
Joined: 22 May 2011 10:58

Re: pic16f886 + i2c+ raspberry pi

#7 Post by checker » 03 Aug 2016 21:54

Code: Select all

     TRISC3_bit = 1;                      // Configurar I2C SCL pin
     TRISC4_bit = 1;                      // Configurar I2C SDA pin
redundant because TRISC= 0b00011000 already sets them as inputs

Code: Select all

     PIE1.SSPIF = 1;                      // enable SSP interrupts
should be:

Code: Select all

     PIE1.SSPIE = 1;                      // enable SSP interrupts
because in the first you are setting the SSP interrupt flag to 1, in the revision you will be setting SSP interrupt enabled.

Code: Select all

    if (SSPSTAT.D_A == 1){             // Data
      byte = SSPBUF;                  // get data
      return;
Not sure where you are going with that statement, I have never seen byte used as a variable.

other than those minor points, I am not sure where the problem lies, maybe you can zip your code and post here or if it is sensitive maybe open help request and give them the specifics

Post Reply

Return to “Product Announcements”