<?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-01T23:04:37-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-t10000.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10000.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10000.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10000.html" />
				</rdf:Seq>
				</items>
				</channel>
						<item rdf:about="http://www.8051projects.net/forum-t10000.html">
						<title>Problem With Atmega32 SPI communication</title>
						<link>http://www.8051projects.net/forum-t10000.html</link>
						<dc:date>2008-12-01T23:04:37-08:00</dc:date>
						<dc:creator></dc:creator>
						<dc:subject></dc:subject>
						<description>Hello All,Greetings!I am trying to do communication between two Atmega32 using SPI. I am using 16 Mhz Crystal. I initialized Master as://~~~~~~~~~~~~~~~~SPI master initialisation in polling mode~~~~~~~~~~~~~~~~void initSpiMaster (void){// set PB4(/SS), PB5(MOSI), PB7(SCK) as output sbi(DDRB, 7);	// set SCK as outputsbi(PORTB, 7);	// set SCK hicbi(DDRB, 6);	// set MISO as inputsbi(DDRB, 5);	// set MOSI as outputsbi(DDRB, 4);	// SS must be output for Master mode                      // to work      	    // enable SPI in Master Mode with SCK = CK/4    SPCR    = (1&lt;&lt;SPE)|(1&lt;&lt;MSTR);      SPSR=0x00;                	// clear SPIF bit in }and Slave asvoid spiInit(){cbi(DDRB, 6);	// set MISO as inputcbi(DDRB, 5);	// set MOSI as output// enable SPI in slave Mode with SCK = CK/4SPCR=0xC0;SPSR=0x00;}I checked the Clock at master i found that 15-16 Mhz not changing with changes the prescaler also. I am getting few junk byte at slave side some side. * Please suggest me am i doing initialization in write way or not* why Clock frequency is not changes according to prescaler. RegardsMukesh</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10000.html">
						<title>Re: Problem With Atmega32 SPI communication</title>
						<link>http://www.8051projects.net/forum-t10000.html</link>
						<dc:date>2008-12-01T23:04:37-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>I really don't see any problem with your code as such.Well there is one more guy in forum who tried the same thing between two PIC controllers. He was also getting junk bytes. We couldnt find any solution of why its happening like that.are you using interrupts in Slave controller?Try to play with clock polarity maybe you can get right data being sent. Keep master as rising and slave as falling and try again.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10000.html">
						<title>Re: Problem With Atmega32 SPI communication</title>
						<link>http://www.8051projects.net/forum-t10000.html</link>
						<dc:date>2008-12-01T23:04:37-08:00</dc:date>
						<dc:creator>Amin Sharif</dc:creator>
						<dc:subject></dc:subject>
						<description>Hello.Try this one out. I was having the same problem but have been solved.CODE:#include "spi_lib.h"<br /><br />//*****************************<br />//<br />// &nbsp;SPI module initialization &nbsp;atmega32<br />//<br />//*****************************<br /><br />#define DD_MOSI&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 5<br />#define DD_MISO &nbsp; &nbsp; 6<br />#define DD_SCK &nbsp; &nbsp; &nbsp;7<br />#define DDR_SPI &nbsp; &nbsp; DDRB<br /><br /><br />void SPI_MasterInit&#40;void&#41;<br />&#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; // Set MOSI and SCK output, all others input<br />&nbsp; &nbsp; &nbsp; &nbsp; DDR_SPI = &#40;1&lt;&lt;DD_MOSI&#41;|&#40;1&lt;&lt;DD_SCK&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; // Enable SPI, Master, set clock rate fck/16<br />&nbsp; &nbsp; &nbsp; &nbsp; SPCR = &#40;1&lt;&lt;SPE&#41;|&#40;1&lt;&lt;MSTR&#41;|&#40;0&lt;&lt;SPR1&#41;|&#40;0&lt;&lt;SPR0&#41;|&#40;0&lt;&lt;CPOL&#41;|&#40;1&lt;&lt;CPHA&#41;;<br />&#125;<br /><br />void SPI_sendString&#40;unsigned char * s&#41;<br />&#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; int i = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; while &#40;i &lt; 100&#41; // don't get stuck if it is a bad string<br />&nbsp; &nbsp; &nbsp; &nbsp; &#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if&#40; s&#91;i&#93; == '\0' &#41; break; // quit on string terminator<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SPI_sendChar&#40; s &#91;i++&#93; &#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &#125;<br />&#125;<br /><br />void SPI_sendChar&#40;char spiData&#41;<br />&#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; /* Start transmission */<br />&nbsp; &nbsp; &nbsp; &nbsp; SPDR = spiData;<br />&nbsp; &nbsp; &nbsp; &nbsp; /* Wait for transmission complete */<br />&nbsp; &nbsp; &nbsp; &nbsp; while&#40;!&#40;SPSR &amp; &#40;1&lt;&lt;SPIF&#41;&#41;&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; _delay_ms&#40;1&#41;;<br /><br />&#125;<br /><br />void SPI_SlaveInit&#40;void&#41;<br />&#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; /* Set MISO output, all others input */<br />&nbsp; &nbsp; &nbsp; &nbsp; DDR_SPI = &#40;1&lt;&lt;DD_MISO&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; /* Enable SPI */<br />&nbsp; &nbsp; &nbsp; &nbsp; SPCR = &#40;1&lt;&lt;SPE&#41;|&#40;0&lt;&lt;SPR1&#41;|&#40;0&lt;&lt;SPR0&#41;|&#40;0&lt;&lt;CPOL&#41;|&#40;1&lt;&lt;CPHA&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; SPDR = 0xFE;<br />&#125;<br /><br /><br />//**********************<br />//<br />// File Name&nbsp; &nbsp; : 'spi_lib.h'<br />//<br />//**********************<br />#ifndef spi_LIB<br />#define spi_LIB<br /><br />#include &lt;avr/io.h>#include &lt;avr/interrupt.h>#include &lt;avr/sleep.h>#include &lt;avr/delay.h>void SPI_MasterInit(void);<br />void SPI_sendString&#40;unsigned char * s&#41;;<br />void SPI_sendChar&#40;char spiData&#41;;<br />void SPI_SlaveInit&#40;void&#41;;<br /><br />#endif<br />&nbsp;good luck</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10000.html">
						<title>Re: Problem With Atmega32 SPI communication</title>
						<link>http://www.8051projects.net/forum-t10000.html</link>
						<dc:date>2008-12-01T23:04:37-08:00</dc:date>
						<dc:creator>Amin Sharif</dc:creator>
						<dc:subject></dc:subject>
						<description>Write in master controller main program.	SPI_MasterInit();	SPI_sendChar('A');	SPI_sendChar('B');	SPI_sendChar('&#092;r');	SPI_sendString("SPI Master Initialized&#092;r");Write in slave controller main program, You can use your own usart commandsIt receives the character and increment and sends back to master.	SPI_SlaveInit();	while(1)		//loop demos	{	while(!(SPSR &amp; (1&lt;&lt;SPIF)));		if (SPDR != 0xfe)		{			Tempdata = SPDR;			USART_sendChar(Tempdata);			SPDR = Tempdata + 1;		}	}</description>
						</item>
				</rdf:RDF>