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 mssp help with master to slave comm

Status
Not open for further replies.

PicChristmas

New Member
I have the master setup to transmit data to the slave using the 18f2420. My question is what is the process to get the received data out of the SSPBUF in the slave unit? Do i have to test for more that the SPIF to know when the data has been recieved.



Code:
i2Write: 

		SSPCON2.0	=1 			'initiate START condition 
		gosub i2Wait 		'wait for current operation to finish 
		
		SSPBUF	=	i2cAddr 	'send out slave address zero / all unit call
		gosub i2Wait 		'wait for current operation to finish 
		
		SSPBUF= rxChar 			'write memory data 
		gosub i2Wait 		'wait for current operation to finish 
		
		SSPCON2.2=1 			'initiate STOP condition 
		gosub i2Wait 		'wait for current operation to finish 

		return
 
Oh yeah it's more complicated than that. You need to read some status bits- S, DA, RW, & BF- to determine the state of the response. But these do nicely frame your packet in the stream of bytes which in some ways makes it easier than the serial port.

There is a notable absence of a well documented solution which includes handling of link errors. It's a bit tricky.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top