Page 1 of 1
pic16f886 + i2c+ raspberry pi
Posted: 29 Jun 2016 06:09
by superino
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
Re: pic16f886 + i2c+ raspberry pi
Posted: 29 Jun 2016 14:31
by lana.arsic
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
Re: pic16f886 + i2c+ raspberry pi
Posted: 11 Jul 2016 21:56
by superino
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..
Re: pic16f886 + i2c+ raspberry pi
Posted: 12 Jul 2016 14:24
by lana.arsic
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
Re: pic16f886 + i2c+ raspberry pi
Posted: 13 Jul 2016 06:44
by checker
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.
Re: pic16f886 + i2c+ raspberry pi
Posted: 03 Aug 2016 20:04
by superino
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;
}
}
}
Re: pic16f886 + i2c+ raspberry pi
Posted: 03 Aug 2016 21:54
by checker
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