<?xml version="1.0" encoding="utf-8"?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rss  version="2.0">
				<channel>
				<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>

<language>en-gb</language>
				<copyright><a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/in/" target="_blank"><img alt="Creative Commons License" width="80" height="15" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/2.5/in/80x15.png" target="_blank" /></a>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/in/" target="_blank">Creative Commons Attribution-Noncommercial 2.5 India License</a>.<a href='http://www.8051projects.net/disclaimer.htm' target='_blank' />Rickey's World Disclaimer</a></copyright>
				<managingEditor>Ajay Bhargav - contact@nospam.com</managingEditor>
				<webMaster>contact@nospam.com</webMaster>
				<pubDate>Mon, 01 Dec 2008 12:00:29 -0800</pubDate>
				<lastBuildDate>Mon, 01 Dec 2008 12:00:29 -0800</lastBuildDate>
				<docs>http://backend.userland.com/rss</docs>
				<generator>e107 (http://e107.org)</generator>
				<ttl>60</ttl>
				<textInput>
				<title>Search</title>
				<description>Search 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes</description>
				<name>query</name>
				<link>http://www.8051projects.net/search.php</link>
				</textInput>
						<item>
						<title>Problem With Atmega32 SPI communication</title>
<link>http://www.8051projects.net/forum-t10000.html</link>
<description><![CDATA[Hello All,<br />Greetings!<br />I am trying to do communication between two Atmega32 using SPI. I am using 16 Mhz Crystal. I initialized Master as:<br /><br />//~~~~~~~~~~~~~~~~SPI master initialisation in polling mode~~~~~~~~~~~~~~~~<br />void initSpiMaster (void)<br />{<br />// set PB4(/SS), PB5(MOSI), PB7(SCK) as output <br /><br />sbi(DDRB, 7);	// set SCK as output<br />sbi(PORTB, 7);	// set SCK hi<br />cbi(DDRB, 6);	// set MISO as input<br />sbi(DDRB, 5);	// set MOSI as output<br />sbi(DDRB, 4);	// SS must be output for Master mode      <br />                // to work      <br />	<br />    // enable SPI in Master Mode with SCK = CK/4<br />    SPCR    = (1&lt;&lt;SPE)|(1&lt;&lt;MSTR);<br />   <br />   SPSR=0x00;                	// clear SPIF bit in <br /><br />}<br /><br />and Slave as<br /><br />void spiInit()<br />{<br />cbi(DDRB, 6);	// set MISO as input<br />cbi(DDRB, 5);	// set MOSI as output<br />// enable SPI in slave Mode with SCK = CK/4<br />SPCR=0xC0;<br />SPSR=0x00;<br />}<br /><br />I checked the Clock at master i found that 15-16 Mhz not changing with changes the prescaler also. <br /><br />I am getting few junk byte at slave side some side. <br /><br />* Please suggest me am i doing initialization in write way or not<br />* why Clock frequency is not changes according to prescaler. <br /><br />Regards<br />Mukesh]]></description>
<pubDate>Tue, 10 Jun 2008 15:36:17 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t10000.html</guid>
</item>
						<item>
						<title>Re: Problem With Atmega32 SPI communication</title>
<link>http://www.8051projects.net/forum-t10000.html</link>
<description><![CDATA[I really don't see any problem with your code as such.<br /><br />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.<br /><br />are you using interrupts in Slave controller?<br />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>
<author>Ajay&lt;contact@nospam.com&gt;</author>
<pubDate>Tue, 10 Jun 2008 17:40:37 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t10000.html</guid>
</item>
						<item>
						<title>Re: Problem With Atmega32 SPI communication</title>
<link>http://www.8051projects.net/forum-t10000.html</link>
<description><![CDATA[Hello.<br /><br />Try this one out. I was having the same problem but have been solved.<br /><br /><div class='code_box'>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="c" style="font-family: monospace;"><span style="color: #339933;">#include &quot;spi_lib.h&quot;</span><br /><br /><span style="color: #808080; font-style: italic;">//*****************************</span><br /><span style="color: #808080; font-style: italic;">//</span><br /><span style="color: #808080; font-style: italic;">// &nbsp;SPI module initialization &nbsp;atmega32</span><br /><span style="color: #808080; font-style: italic;">//</span><br /><span style="color: #808080; font-style: italic;">//*****************************</span><br /><br /><span style="color: #339933;">#define DD_MOSI&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 5</span><br /><span style="color: #339933;">#define DD_MISO &nbsp; &nbsp; 6</span><br /><span style="color: #339933;">#define DD_SCK &nbsp; &nbsp; &nbsp;7</span><br /><span style="color: #339933;">#define DDR_SPI &nbsp; &nbsp; DDRB</span><br /><br /><br /><span style="color: #993333;">void</span> SPI_MasterInit<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set MOSI and SCK output, all others input</span><br />&nbsp; &nbsp; &nbsp; &nbsp; DDR_SPI = <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;DD_MOSI<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;DD_SCK<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Enable SPI, Master, set clock rate fck/16</span><br />&nbsp; &nbsp; &nbsp; &nbsp; SPCR = <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;SPE<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;MSTR<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>&lt;&lt;SPR1<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>&lt;&lt;SPR0<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>&lt;&lt;CPOL<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;CPHA<span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #993333;">void</span> SPI_sendString<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> * s<span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> i = <span style="color: #cc66cc;">0</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>i &lt; <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// don't get stuck if it is a bad string</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> s<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> == <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\0</span>'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span>; <span style="color: #808080; font-style: italic;">// quit on string terminator</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SPI_sendChar<span style="color: #66cc66;">&#40;</span> s <span style="color: #66cc66;">&#91;</span>i++<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #993333;">void</span> SPI_sendChar<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span> spiData<span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Start transmission */</span><br />&nbsp; &nbsp; &nbsp; &nbsp; SPDR = spiData;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Wait for transmission complete */</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #66cc66;">&#40;</span>SPSR &amp; <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;SPIF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; _delay_ms<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br /><br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #993333;">void</span> SPI_SlaveInit<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Set MISO output, all others input */</span><br />&nbsp; &nbsp; &nbsp; &nbsp; DDR_SPI = <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;DD_MISO<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Enable SPI */</span><br />&nbsp; &nbsp; &nbsp; &nbsp; SPCR = <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;SPE<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>&lt;&lt;SPR1<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>&lt;&lt;SPR0<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>&lt;&lt;CPOL<span style="color: #66cc66;">&#41;</span>|<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>&lt;&lt;CPHA<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; SPDR = 0xFE;<br /><span style="color: #66cc66;">&#125;</span><br /><br /><br /><span style="color: #808080; font-style: italic;">//**********************</span><br /><span style="color: #808080; font-style: italic;">//</span><br /><span style="color: #808080; font-style: italic;">// File Name&nbsp; &nbsp; : 'spi_lib.h'</span><br /><span style="color: #808080; font-style: italic;">//</span><br /><span style="color: #808080; font-style: italic;">//**********************</span><br /><span style="color: #339933;">#ifndef spi_LIB</span><br /><span style="color: #339933;">#define spi_LIB</span><br /><br /><span style="color: #339933;">#include &lt;avr/io.h&gt;#include &lt;avr/interrupt.h&gt;#include &lt;avr/sleep.h&gt;#include &lt;avr/delay.h&gt;void SPI_MasterInit(void);</span><br /><span style="color: #993333;">void</span> SPI_sendString<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> * s<span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #993333;">void</span> SPI_sendChar<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span> spiData<span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #993333;">void</span> SPI_SlaveInit<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span>;<br /><br /><span style="color: #339933;">#endif</span><br />&nbsp;</div></div><br />good luck <img src='http://www.8051projects.net/e107_images/emotes/yahoo/103.gif' alt='' style='vertical-align:middle; border:0' />]]></description>
<author>Amin Sharif&lt;projectam2004@nospam.com&gt;</author>
<pubDate>Mon, 23 Jun 2008 21:39:35 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t10000.html</guid>
</item>
						<item>
						<title>Re: Problem With Atmega32 SPI communication</title>
<link>http://www.8051projects.net/forum-t10000.html</link>
<description><![CDATA[Write in master controller main program.<br />	SPI_MasterInit();<br /><br />	SPI_sendChar('A');<br />	SPI_sendChar('B');<br />	SPI_sendChar('&#092;r');<br />	SPI_sendString("SPI Master Initialized&#092;r");<br /><br />Write in slave controller main program, You can use your own usart commands<br />It receives the character and increment and sends back to master.<br />	SPI_SlaveInit();<br />	while(1)		//loop demos<br />	{<br />	while(!(SPSR &amp; (1&lt;&lt;SPIF)));<br />		if (SPDR != 0xfe)<br />		{<br />			Tempdata = SPDR;<br />			USART_sendChar(Tempdata);<br />			SPDR = Tempdata + 1;<br />		}<br />	}]]></description>
<author>Amin Sharif&lt;projectam2004@nospam.com&gt;</author>
<pubDate>Mon, 23 Jun 2008 21:47:48 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t10000.html</guid>
</item>
				</channel>
				</rss>