Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I2C Master Slave Read data from slave

Status
Not open for further replies.

SneaKSz

Member
Hello all

I'm experiencing problems with receiving data from my slave. The slave knows its addressed and sets its data into SSPBUF. The data also clocks out, but when I read the SSPBUF in the master, it's not the value I send over I2C.

This is the picture of the master receiving data ( address = 0x08, the +1 for reading, data = 0xAA).

**broken link removed**

https://img191.imageshack.us/i/masterreadslave0xaa.png/

This is the routine :
Code:
					SendStart(); // send S
					Delay10TCY();// 	
					SendByte2(0x08+1); // Address READ
					Delay10TCYx(10);// 	
					SSPCON2bits.RCEN=1;
					Delay10TCYx(10);// 	
					SSPFlag();
					Delay10TCY();
			//		test=ReadI2C();
					while(SSPSTATbits.BF == 0);
					Delay10TCY();
					Nack();
					Delay10TCY();
					SendStop();
					Delay10TCY();
					Delay10TCY();
					SSPCON2bits.RCEN=0;
				//	Delay10KTCYx(1);// 
					Delay10TCY();
					errorV= SSPBUF;// put the SSPBUF in a char

Code:
void SendStart(){
SSPCON2bits.SEN=1;
SSPFlag();
}

void SendStop(){
SSPCON2bits.PEN=1; // P activeren
SSPFlag();
}
void Nack(){
SSPCON2bits.ACKEN=1;
SSPCON2bits.ACKDT=1;	
}
void SSPFlag() {
while(PIR1bits.SSPIF==0); // wait until sent
PIR1bits.SSPIF=0; // set low
}
The problem is that I can't send a NACK and a STOP bit. Someone sees the wrong sequence in my code?
 
Last edited:
Fixed : The problem was there is a busbuffer and opto coupler between the master & slave. A resistor was chosen badly and the LOW level was 4.5V, by choosing a correct resistor, the low level went to 0.5V and the master received a NACK.

Thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top