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.

Master slave I2C no acknowledge

Status
Not open for further replies.

SneaKSz

Member
Hi all,

Im setting up a master slave but my slave does not acknowledge. This is the sequence:
start
write address
write data
stop

Ive searched for various solution(e.g. voltage levels , I2C register settings) but I"m unable to find why the slave does not ack. The slave interrupts when receiving data but it does not acknowlegde.

Something else is that the voltage level of SDA is low when not used. The slave default releases the SDA lines.

this is the master init code :
Code:
		ADCON1=0x00;//Configure A/D
		SDA=1; // input
		SCL=1;// input
		// MSSP registers 
		SSPCON1=0b00101000; // I²C master mode , SSPEN enable
		SSPSTAT=0b10000000; // Slew Rate control (SMP) 100kHz
		SSPADD = 199;// 15KHz

slave

Code:
	// SSPMSK-> No mask
	// 7-Bit Slave mode:
	//bit 7-1 ADD<6:0>: 7-bit address
	SSPADD=0x08; // address
	SSPSTAT=0b00000000; 
	SSPCON1= 0x36; // I2C Slave mode, 7-bit address , SSPEN enable , release clock
	//SSPCON2bits.SEN  = 0;
  // Disable Address 0x0 General Call
    SSPCON2bits.GCEN = 0;

If someone is interested this is the full code :

master

Code:
void main(void){
		Delay10KTCYx(255);// 	510ms
		init();// setup
	
//	
	while(1){	
					SendStart(); // send S
					SendByte2(0x08); // Address READ
					SendByte2(0xAA); // send data
					SendStop();
					Delay10KTCYx(1);// 	510ms

}// end while		
}// end maim

void init(){
		// set SDA port high
		SDA=0;
		LATBbits.LATB6=1;
		
		ADCON1=0x00;//Configure A/D
		SDA=1; // input
		SCL=1;// input
		// MSSP registers 
		SSPCON1=0b00101000; // I²C master mode , SSPEN enable
		SSPSTAT=0b10000000; // Slew Rate control (SMP) 100kHz
		// baud rate 100.000kHz-> 19kHz
		SSPADD = 199;// 50KHz WERT NIET 
		// 149 werkt 20KHZ 99 ook 30 KHz

// IPEN's
//
//		RCONbits.IPEN=1; // enable prio
//		IPR1bits.RCIP=0;
// serial
		Delay10TCY();// wait 14µs
		TRISBbits.TRISB7=0;//TX
		TRISBbits.TRISB5=1;///RX
		ANSELHbits.ANS11=0; // RB5 digital IO
		Delay10TCY();// wait 14µs
		TXSTA=0x20;// enable transmit 
		SPBRG=19; // 9600 bps
		RCSTA=0x90;//enable receive + serial port.
		TXSTAbits.TXEN=1;
		PIR1bits.RCIF=0;
	    TXSTAbits.SYNC;
	    RCSTAbits.SPEN;
	    RCSTAbits.CREN;
	

		PIE1bits.RCIE=1;
		PIR1bits.RCIF=0;
		INTCONbits.GIE=1;
		INTCONbits.PEIE=1;
		

}

void I2CFAIL(){
SSPCON2bits.PEN=1;
}

void ACKSTAT(){
	if ( SSPCON2bits.ACKSTAT==1){ // check ackstat
	I2CFAIL(); // STOP
	
	}
}

void Nack(){

SSPCON2bits.ACKDT=1;	
SSPCON2bits.ACKEN=1;
}
void SSPFlag() {
while(PIR1bits.SSPIF==0); // wait until sent
PIR1bits.SSPIF=0; // set low
}

void SendByte2(unsigned char data){
SSPBUF= data;
SSPFlag();
}


The full code is not important, I just want to figure out why the slave does not acknowledge.

The address in SSPADD and the address that I send from the master are the same.

If someone could help me , I would be very relieved!

Kind regards
 
Last edited:
mfcdai2clarge.pngHere are the pulses :
ImageShack® - Online Photo and Video Hosting

A: data , b : clock.

Mark the voltage level on the 9th pulse. They are not correct.

EDIT ( made a local copy of the image.)
 
Last edited by a moderator:
Hi Gayan, thanks for the reply.

I"ve added your suggestion in the code, but the slave still does not acknowledge. The master stops sending out bytes and the lines stay high.

I've also changed the Pull up resistors to 4K7,2K2, no advance.
Kind regards.
 
Found the problem,

An optocoupler betweend the master & slave permitted the master from receiving a ACK.

Kind regards
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top