Click here to Skip to main content
15,885,660 members

Comments by Herambashree (Top 8 by date)

Herambashree 6-Nov-13 9:09am View    
thax
Herambashree 6-Nov-13 7:52am View    
This is my code here

for slave controller
/////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////
//AUTHOR:ANOOP //
//COMPANY:UNIPAR //
//LOCATION:BANGALORE //
//DSPIC 30F2010 //
//PROJECT:SINEWAVE INVERTER USING DSPIC //
//////////////////////////////////////////////////////////////////////////////////

#define SCL _RF3 // I2C bus
#define SDA _RF2 /*
#define SCL_IN _TRISF3 //
#define SDA_IN _TRISF2 //*/
//#define SCL _TRISF3 //
//#define SDA _TRISF2 //
////Mains sub time duration is 344 Micro sec 2.91 KHz////

#include <p30f2010.h>
#include "init.h"
//#include "DataEEPROM.h"
#include "p30fxxxx.h"
#include <stdio.h>
#include <stdlib.h>

_FOSC(CSW_FSCM_OFF & XT_PLL16);
//_FGS(CODE_PROT_ON);

unsigned char f=0,bit1=0,read_value=0,read=0,count=0,i,data=0;
unsigned int addrs,var,var2=0;
unsigned char a[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char b[16] = {1,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0};
struct
{
unsigned addrs :1;
}adr;

void read_write();
void read_data();
void communication();
unsigned char I2CRead();

int main(void)
{


PORTEbits.RE0=0;
_TRISE0 = 0;
PORTFbits.RF2=1;
PORTFbits.RF3=1;
_TRISF2 = 1;
_TRISF3 = 1;


///////// void _write_eedata_word(int Mydata2,int Mydata1 );///////
addrs=0X0F;
adr.addrs=0;
var=0;
{
I2CCON =0XA1C0;
I2CSTAT =0X0699;
I2CBRG =0X007;
I2CADD =0X08;
I2CRCV =0X0000;
I2CTRN =0X00FF;


}
while(1){



//while(!SCL);while(SCL);
if((SDA==0) && (SCL ==0)){

while(count<10) {
if(SCL)
count++;
//while(!SCL);
}
data=I2CRead();
if(data >3)_RE0 =1;
}

/*{
for(i=0;i<16;i++){
while(!SCL);
a[i] = SDA;
}
for(i=0;i<16;i++){
if(a[i]==b[i])
count++;
}
if(count>=11){
//_RE0 =1;count=0;
}
}
if(I2CRCV ==0XA2)_RE0 =1;*/
/*_TRISF2 = 1;
_TRISF3 = 1;
if((SDA==0) && (SCL ==0)){
communication();


_TRISF2 = 1;
_TRISF3 = 1;
}*/

}
return 0;
}



unsigned char I2CRead(){
unsigned char i, Data=0;
for(i=0;i<8;i++){
SCL = 0;
SCL = 1;
if(SDA)
Data |=1;
if(i<7)
Data<<=1;
}
SCL = 0;
SDA = 1;
return Data;
}


/////////////////////////////////////////////////////
for master controller
////////////////////////



//#include <htc.h>
#define SCL _RF3 // I2C bus
#define SDA _RF2 //

#include <p30f2010.h>


#include "p30fxxxx.h"
#include <stdio.h>
#include <stdlib.h>
unsigned long data1;
_FOSC(CSW_FSCM_OFF & XT_PLL16);
//_FGS(CODE_PROT_ON);
int a;

void I2CInit(){
SDA = 1;
SCL = 1;
}

void I2CStart(){
SCL = 1;
SDA = 0;
SCL = 0;
}

void I2CRestart(){
SDA = 1;
SCL = 1;
SDA = 0;
}

void I2CStop(){
SDA = 0;
SCL = 1;
SDA = 1;
}

void I2CAck(){
SDA = 0;
SCL = 1;
SCL = 0;
}

void I2CNak(){
SDA = 1;
SCL = 1;
SCL = 0;
}

unsigned char I2CSend(unsigned char Data){
unsigned char i, ack_bit;
for(i=0;i<8;i++){
SCL = 0;
if ((Data & 0x80) == 0)
SDA = 0;
else
SDA = 1;
SCL = 1;
Data<<=1;
}
SCL = 0;
ack_bit = SDA;
SCL = 1;
SCL = 0;
return !ack_bit;
}

unsigned char I2CRead(){
unsigned char i, Data=0;
for(i=0;i<8;i++){
SCL = 0;
SCL = 1;
if(SDA)
Data |=1;
if(i<7)
Data<<=1;
}
SCL = 0;
SDA = 1;
return Data;
}

int main(void)
{
PORTEbits.RE0=0;
_TRISE0 = 0;

{
I2CCON =0XB15F;
I2CSTAT =0X46BD;
I2CBRG =0X007;
I2CADD =0XA3;
I2CRCV =0X0000;
I2CTRN =0X00FF;


}
I2CInit();

while(1){
I2CStart();
I2CSend(0xFE);
I2CSend(0xA2
I2CStop();



}
return 0;
}




////////////////////////////////////////////////
I am not getting output here. Is there any mistake here? I am checking the voltage in the RE0 pin of slave controller.

thanks
Herambashree 6-Nov-13 6:14am View    
Thaks Jochen Arndt

I shall try and reply you.
Herambashree 6-Nov-13 5:27am View    
Dear Jochen Arndt,
Thaks for reply to my question
I am using dsPIC 30F2010 as a slave device.would you please give me detail about reserve address and the how do I know slave address (any example). Is there any sub address pins for it?
May I have to do any register bit configuration for I2CCON AND I2CSTAT and others. If you have idea about it please give detail please.

Thax
Heram
Herambashree 28-Oct-13 4:36am View    
Thax