<?xml version="1.0" encoding="utf-8" ?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
				<channel rdf:about="http://www.8051projects.net/">
				<title>8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes : Forum / topic</title>
				<link>http://www.8051projects.net/</link>
				<description>Learn to make simple microcontroller projects, pic, 8051, avr and arm projects. download 8051 projects, tutorials, libraries, sample codes. join the microcontroller discussion forum and ask doubts regarding electronics. the best source for 8051 over internet.</description>
				<dc:language>en-gb</dc:language>
				<dc:date>2008-12-01T22:54:29-08:00</dc:date>
				<dc:creator>contact@nospam.com</dc:creator>
				<admin:generatorAgent rdf:resource="http://e107.org" />
				<admin:errorReportsTo rdf:resource="mailto:contact@nospam.com" />
				<sy:updatePeriod>hourly</sy:updatePeriod>
				<sy:updateFrequency>1</sy:updateFrequency>
				<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
				<items>
				<rdf:Seq>
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t7020.html" />
				</rdf:Seq>
				</items>
				</channel>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator></dc:creator>
						<dc:subject></dc:subject>
						<description>I am reading the ADC of the master controller and sending the data to the slave through SPI.Master is sending the data accurately, but slave is receiving in this fashionMaster send = 179Slave read = 179  210  218  51  46  124  168  254  232  201  179  ..........This means that I  receive the correct data  after 8 or 9 bytes as you can see the pattern shown above. Another thing is that I am sending this data on hyper terminal.My code for master and slave is given below.Master Code:CODE:<br />#include &lt;16F877A.h>//<br />#fuses NOWDT,NOPROTECT,XT,NOLVP,PUT<br />#use delay(clock=4000000)<br />#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)<br />float val=0;<br />int8 data=0;<br /><br /><br /><br /><br /><br />#int_TIMER0<br /><br />void pick_sample&#40;void&#41;<br />&#123;<br />set_timer0&#40;150&#41;;<br />set_adc_channel&#40;0&#41;;<br />delay_us&#40;10&#41;;<br />val = read_adc&#40;&#41;;<br />data = &#40;int8&#41;val;<br /><br />&#125;<br /><br /><br />void main&#40;&#41;<br />&#123;<br /><br />setup_timer_0&#40;RTCC_INTERNAL|RTCC_DIV_16&#41;;&nbsp; &nbsp; &nbsp; &nbsp;<br />set_timer0&#40;150&#41;;<br /><br />enable_interrupts&#40;int_rtcc&#41;;<br />enable_interrupts&#40;global&#41;;<br /><br />setup_adc_ports&#40;all_analog&#41;;<br />setup_adc&#40;adc_clock_internal&#41;;<br /><br />setup_spi&#40; SPI_MASTER | SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16 &#41;;<br /><br />while&#40;1&#41;<br />&#123;<br /><br />spi_write&#40;data&#41;;<br />printf&#40;"\n\rdata = %u dataf = %f",data,val&#41;;<br /><br />&#125;<br />&#125;<br />&nbsp;Slave code:CODE:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />//SLAVE program<br /><br />#include &lt;16F877A.h>//<br />#fuses NOWDT,NOPROTECT,XT,NOLVP,PUT<br />#use delay(clock=4000000)<br />#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)<br /><br />int8 data=0;<br /><br /><br />void main&#40;&#41;<br />&#123;<br /><br />setup_spi&#40;SPI_SLAVE|SPI_H_TO_L|SPI_SS_DISABLED&#41;;<br /><br /><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; output_high&#40;PIN_C4&#41;;<br />&nbsp; &nbsp; output_high &#40;PIN_C5&#41;;<br />while&#40;1&#41;<br />&nbsp; &nbsp; &nbsp; &nbsp; &#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; if&#40;SPI_DATA_IS_IN&#40;&#41;&#41;<br />&#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data = spi_read&#40;&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output_b&#40;data&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output_toggle&#40;PIN_D4&#41;;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf&#40;"\n\r data = %u",data&#41;;<br />&#125;<br />&#125;<br />&#125;Please help me in this regard.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>Re: SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>i do not understand this..you are sending one byte and on receiver side you are getting bytes like 8 or 9 bytes...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>Re: SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator>Hanzala</dc:creator>
						<dc:subject></dc:subject>
						<description>I am sending from master 179 continuously, while slave is receiving the correct byte after 8 or 9th byte.That is correct data received after every 8th or 9th byte.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>Re: SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>can you explain me in the slave code what are you doing here? and why?CODE:output_b&#40;data&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />output_toggle&#40;PIN_D4&#41;;<br />&nbsp;</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>Re: SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator>Hanzala</dc:creator>
						<dc:subject></dc:subject>
						<description>By toggling D4 I am just want to make sure that slave is receiving the data and I am sending this data on port B. I have attached LED's on Port B and I just want to see the data on portB as well.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>Re: SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>try doing this way...in slave controller setup SPI as..CODE:setup_spi&#40;SPI_SLAVE|SPI_L_TO_H|SPI_SS_DISABLED&#41;;i mean.. L->H data transition.. please do it the right way..The thing is.. master put data on o/p pin on H->L transition and slave read on L->H transition, this ensures that data is transfered properly..Thats the reason you are getting correct data after exact 8 bits.. Everything will be fine if you just understand the reason..Make the changes and try again..</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>Re: SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator>Hanzala</dc:creator>
						<dc:subject></dc:subject>
						<description>It is still not working properly. May be it is a synchronization problem. Does any one has a program which he has tried himself?Can any one tell me that "if I donot use SPI_READ() function, but read the data from SSPBUF register", than how can I read SSPBUF in C??????</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t7020.html">
						<title>Re: SPI interfacing problem between two 16F877A</title>
						<link>http://www.8051projects.net/forum-t7020.html</link>
						<dc:date>2008-12-01T22:54:29-08:00</dc:date>
						<dc:creator>Rocha</dc:creator>
						<dc:subject></dc:subject>
						<description>hello,  Maybe the 'master' is running (and sending data) faster  than the slave (because it has few instructions). Therefore, the data in the slave PIC gets corrupted. If I were you I would put a delay in the master and test it again. BTW: Why did you put in the slave code the     output_high(PIN_C4);    output_high (PIN_C5);  pin_c4 is ther SDI and and C5 is the SDO</description>
						</item>
				</rdf:RDF>