<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>comp-e.com &#187; Freescale</title>
	<atom:link href="http://comp-e.com/tag/freescale/feed" rel="self" type="application/rss+xml" />
	<link>http://comp-e.com</link>
	<description>Computer Engineering</description>
	<lastBuildDate>Fri, 13 Nov 2009 06:57:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating Morse Code Using The HCS08 Microcontroller</title>
		<link>http://comp-e.com/creating-morse-code-using-the-hcs08-microcontroller</link>
		<comments>http://comp-e.com/creating-morse-code-using-the-hcs08-microcontroller#comments</comments>
		<pubDate>Sun, 22 Mar 2009 15:21:51 +0000</pubDate>
		<dc:creator>COMP-E</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[forum]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[computer engineering]]></category>
		<category><![CDATA[Freescale]]></category>
		<category><![CDATA[microcontroller]]></category>

		<guid isPermaLink="false">http://comp-e.com/?p=125</guid>
		<description><![CDATA[Recently I was faced with the task of sending data out of a HCS08 microcontroller wirelessly.  I had only one pin available to me and decided to effectively create Morse Code so that my receiver could decode the signal without having some sort of reference clock to distinguish the 1&#8217;s and 0&#8217;s.   What took many [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was faced with the task of sending data out of a HCS08 microcontroller wirelessly.  I had only one pin available to me and decided to effectively create Morse Code so that my receiver could decode the signal without having some sort of reference clock to distinguish the 1&#8217;s and 0&#8217;s.   What took many hours to conceptualize and diagram out on the blackboard, turned out to be a very small bit of code.</p>
<p>On the sender side is a simple function written in C that takes a byte and loops through masking each bit.  This masking is done inside an if / else block and the result determines whether or not you are getting a dit or a dash.</p>
<p>Tied to the RF receiver is another MC9S08QG8 which takes in the signal via interrupts and assembles eight interrupts into eight bytes.  It then does a series of bitwise operations on each of the eight bytes in order to reconstruct the original byte.  You will find that a few parts of the code are subject to change (the time for 0&#8217;s and 1&#8217;s can be adjusted and must be adjusted if you plan on implementing PLL or have a different desired data rate).  That byte is then sent to a PC vie RS232 serial port and stored using a free program called RS232 Data Logger from Eltima Software.  The code will be posted shortly under the microcontroller section on the COMP-E forum for you to use and <a title="Wireless Morse Code HCS08" href="http://comp-e.com/forum/viewtopic.php?f=40&amp;t=30">enjoy</a>.</p>
<p>- COMP-E</p>
<p>~ ALERT: This post does not return to main !!!</p>
]]></content:encoded>
			<wfw:commentRss>http://comp-e.com/creating-morse-code-using-the-hcs08-microcontroller/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using SPI EEPROM 25AA512 On An HCS08 Microcontroller</title>
		<link>http://comp-e.com/using-spi-eeprom-25aa512-on-an-hcs08-microcontroller</link>
		<comments>http://comp-e.com/using-spi-eeprom-25aa512-on-an-hcs08-microcontroller#comments</comments>
		<pubDate>Fri, 13 Mar 2009 21:23:21 +0000</pubDate>
		<dc:creator>COMP-E</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[comp-e]]></category>
		<category><![CDATA[forum]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[computer engineering]]></category>
		<category><![CDATA[Freescale]]></category>
		<category><![CDATA[microcontroller]]></category>

		<guid isPermaLink="false">http://comp-e.com/?p=102</guid>
		<description><![CDATA[This post will go to the forum eventually.  I need to fight with my hosting people first and get them to bump the limit on the amount of memory PHP can use.  So, for now, you can get all the good stuff here!
EDIT: I fixed the issue.  You can now view this topic on the [...]]]></description>
			<content:encoded><![CDATA[<p>This post will go to the forum eventually.  I need to fight with my hosting people first and get them to bump the limit on the amount of memory PHP can use.  So, for now, you can get all the good stuff here!</p>
<p>EDIT: I fixed the issue.  You can now view this topic on the forum.  Please post your comments there as well. <a title="Using External EEPROM on a HCS08" href="http://comp-e.com/forum/viewtopic.php?f=40&amp;t=25"> &gt;&gt;&gt;&gt;</a></p>
<p>-/-</p>
<p>Most things that use SPI are rather straight forward, a simple MISO, MOSI, and Slave Select and you&#8217;re good to go.  That was not the case in my pursuit to get this EEPROM to work.  It is incredibly finicky and took about a month hooked up to a logic analyzer and multiple revisions to the way instructions interact, before I was finally able to get it up in running.  I hope this code works for you.  The particular chip came from Microchip and you can find the data sheet easily enough by searching 25AA512.  I am including the .c and .h files here.  You will be able to view the entire project along with the .mcp file for which I used the memory end such.  I&#8217;m not ready to post that project yet but it will have &#8216;SWIM&#8217; somewhere in the topic title.</p>
<p>As a side note, make sure that Vcc on the EEPROM is tied to the Vcc of the microcontroller otherwise you will find as I did, that odd bits and data come back on reads instead of what you want!!</p>
<p>You will notice that slave select pin is not used.  Because I only used this one chip, I tied the SS, WP, and HOLD pins to hi/low as per my needs.</p>
<p>- COMP-E</p>
<p>~ XOR would be pleased</p>
<p>The following code was used in SPI1.c</p>
<p><span style="color: #888888;">[code]</span></p>
<pre><span style="color: #ff9900;">**     Settings  :
**          Bean name                                      : SPI1
**          Device                                         : SPI
**          Settings
**            Clock settings
**              Value of Preselection                      : 5
**              Value of Selection                         : 64
**              Frequency                                  : 12.5 kHz
**            Mode Select                                  : Master
**            Clock Polarity                               : active-high
**            Clock Phase                                  : First edge
**            Data shift order                             : MSB first
**            Bidirectional mode                           : Disabled
**            Output enable in Bidirect.                   : no
**            Stop in Wait Mode                            : Disabled
**          Pins
**            SCK pin                                      : PTB2_KBIP6_SPSCK_ADP6
**            SCK pin signal                               :
**            MISO pin allocation                          : Enabled
**            MISO pin                                     : PTB4_MISO
**            MISO pin signal                              :
**            MOSI pin allocation                          : Enabled
**            MOSI pin                                     : PTB3_KBIP7_MOSI_ADP7
**            MOSI pin signal                              :
**            SS pin allocation                            : Disabled
**          Interrupts
**            Interrupt                                    : Vspi
**            Receive and fault interrupt                  : Disabled
**            Transmit Interrupt                           : Disabled
**            ISR name                                     :
**          Initialization
**            Call Init in CPU init. code                  : yes
**            Enable SPI system                            : yes
**     Contents  :
**         Init - void SPI1_Init(void);
**

/* MODULE SPI1. */

#include "SPI1.h"

void SPI1_Init(void)
{
  /* SPIC1: SPIE=0,SPE=1,SPTIE=0,MSTR=1,CPOL=0,CPHA=0,SSOE=0,LSBFE=0 */
  setReg8(SPIC1, 0x50);
  /* SPIC2: ??=0,??=0,??=0,MODFEN=0,BIDIROE=0,??=0,SPISWAI=0,SPC0=0 */
  setReg8(SPIC2, 0x00);
  /* SPIBR: ??=0,SPPR2=1,SPPR1=0,SPPR0=0,??=0,SPR2=1,SPR1=0,SPR0=1 */
  setReg8(SPIBR, 0x45);  // note that specific baud rates were not functional
}                        // I believe I had success with 0x45 and 0x00

<span style="color: #888888;">[/code]</span></span></pre>
<p>This EEPROM specific initialization was key to getting things working.  It was a function in my main file, but probably belongs in the SPI1.c file.</p>
<pre><span style="color: #ff9900;">void powerUpEEprom(void) {

    CS_OFF;
    delay(2);
    SPI1_Init();
    delay(2);

    delay(2);
    CS_OFF;
    delay(1);
    CS_ON;
    delay(1);

    SPI_WREN();
    SPI_WRSR(0x00);

    /* A small bit of test code */
    SPI_WRITE(0x00, 0x00, 0x11);
    delay(10);
    SPI_WRITE(0x00, 0x01, 0x22);
    delay(10);
    SPI_WRITE(0x00, 0x02, 0x33);
    delay(10);
    SPI_WRITE(0x00, 0x03, 0x44);
    delay(10);
    SPI_WRITE(0x00, 0x04, 0x55);
    delay(10);
    testArray[1] = SPI_READ(0x00,0x00);
    delay(10);
    testArray[2] = SPI_READ(0x00,0x01);
    delay(10);
    testArray[3] = SPI_READ(0x00,0x02);
    delay(10);
    testArray[4] = SPI_READ(0x00,0x03);
    delay(10);
    testArray[5] = SPI_READ(0x00,0x04);
    delay(10);
}</span>

EEPROM.h</pre>
<pre>[code]</pre>
<pre><span style="color: #ff9900;">#ifndef __EEPROM_H
#define __EEPROM_H</span></pre>
<pre><span style="color: #ff9900;">#include "Events.h"</span></pre>
<pre><span style="color: #ff9900;">/* EEPROM OP-CODES */</span></pre>
<pre><span style="color: #ff9900;">#define READ    0x03          // Read  from mem array beg. at selected address
#define WRITE   0x02          // Write to mem array beg. at selected address
#define WREN    0x06          // Set   the latch (enable write operations)
#define WRDI    0x04          // Reset the latch (disable write operations)
#define RDSR    0x05          // Read         – STATUS register
#define WRSR    0x01          // Write        – STATUS register
#define PE      0x42          // Page Erase   – erase one page in mem array
#define SE      0xD8          // Sector Erase – erase one sector in mem array
#define CE      0xC7          // Chip Erase   – erase all sectors in mem array
#define RDID    0xAB          //
#define DPD     0xB9          //</span></pre>
<pre><span style="color: #ff9900;">/* Program Constants */</span></pre>
<pre><span style="color: #ff9900;">#define CS_ON     PTBD_PTBD6 = 0
#define CS_OFF    PTBD_PTBD6 = 1
#define DUMMY     0x00</span></pre>
<pre><span style="color: #ff9900;">/* MODULE EEPROM */</span></pre>
<pre><span style="color: #ff9900;">void delay(int);</span></pre>
<pre><span style="color: #ff9900;">/* Set the write enable latch on the chip */
void SPI_WREN(void);</span></pre>
<pre><span style="color: #ff9900;">/* Perform the read status register sequence */
byte SPI_RDSR(void);</span></pre>
<pre><span style="color: #ff9900;">/* Write to status register
*
* Pre: User sends 8 bit value
*
* Post: Status register written to
*/
void SPI_WRSR(byte val);</span></pre>
<pre><span style="color: #ff9900;">/* Generic transmit of single op code in
*   which chip select is toggled
*/
void SPI_trans(byte val);</span></pre>
<pre><span style="color: #ff9900;">/* Perform Read sequence
*
* Pre:  User sends upper and lower address bytes
*
* Post: User recieves value stored at given address
*/
byte SPI_READ(byte upAddr, byte lwAddr);
void Dummy_Read(byte upAddr, byte lwAddr);
/* Perform Write sequence
*
* Pre:   User sends upper and lower address bytes
*        User sends data byte he wishes to have
*             written to the EEPROM
* Post:  Data is written and clocked out of SPID reg
*/
void SPI_WRITE(byte upAddr, byte lwAddr, byte val);</span></pre>
<pre><span style="color: #ff9900;">/* END EEPROM */</span></pre>
<pre><span style="color: #ff9900;">#endif
[/code]</span></pre>
<pre><span style="color: #ff9900;"><span style="color: #888888;">~ Computer Engineering is going to the laundromat and saying, "yeah, i can so pipeline this"

EEPROM.c</span>
[code]</span></pre>
<pre><span style="color: #ff9900;">/* MODULE EEPROM */</span></pre>
<pre><span style="color: #ff9900;">#include "EEPROM.h"
unsigned char readin;
unsigned char garbage;</span></pre>
<pre><span style="color: #ff9900;">/*****************************************************************************+
*                        DELAY FUNCTIONS
*****************************************************************************/</span></pre>
<pre><span style="color: #ff9900;">void delay(int count)
{
int cnt;</span></pre>
<pre><span style="color: #ff9900;">for(cnt = 0; cnt &lt; count; cnt++)
{
int delay1 = 100;         // coarse adjustment
int delay2 = 100;         //  fine adjustment
while(delay1 &gt; 1)
{
--delay1;
while(delay2 &gt;= 1)
{
--delay2;
}
}
}
}</span></pre>
<pre><span style="color: #ff9900;">/*****************************************************************************+
*                        WRITE FUNCTIONS
*****************************************************************************/</span></pre>
<pre><span style="color: #ff9900;">void SPI_trans(byte val)
{
CS_ON;
delay(2);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));  // Wait until ready to send
SPID = val;           // Send byte value</span></pre>
<pre><span style="color: #ff9900;">delay(2);
CS_OFF;
delay(1);
}</span></pre>
<pre><span style="color: #ff9900;">void SPI_WREN(void)
{
CS_ON;
delay(2);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = WREN;               // Send byte value</span></pre>
<pre><span style="color: #ff9900;">delay(1);
CS_OFF;
delay(1);
}</span></pre>
<pre><span style="color: #ff9900;">void SPI_WRSR(byte val)
{
CS_ON;
delay(2);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = WRSR;               // Send byte value</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = val;                // Send byte value</span></pre>
<pre><span style="color: #ff9900;">delay(2);
CS_OFF;
delay(1);
}</span></pre>
<pre><span style="color: #ff9900;">void SPI_WRITE(byte upAddr, byte lwAddr, byte val)
{
SPI_WREN();</span></pre>
<pre><span style="color: #ff9900;">CS_ON;
delay(2);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = WRITE;              // Send write command</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = upAddr;             // Send upper address</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = lwAddr;             // Send lower address</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = val;                // Send data value</span></pre>
<pre><span style="color: #ff9900;">delay(4);
CS_OFF;
delay(1);
}</span></pre>
<pre><span style="color: #ff9900;">/*****************************************************************************+
*                        READ FUNCTIONS
*****************************************************************************/</span></pre>
<pre><span style="color: #ff9900;">byte SPI_RDSR(void)
{
CS_ON;
delay(2);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = RDSR;               // Send byte value</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = DUMMY;              // Send byte value
delay(1);
while (!(SPIS &amp; 0x80));    // Wait until ready to send</span></pre>
<pre><span style="color: #ff9900;">delay(4);
CS_OFF;
delay(1);
return SPID;
}</span></pre>
<pre><span style="color: #ff9900;">byte SPI_READ(byte upAddr, byte lwAddr)
{
Dummy_Read(upAddr,lwAddr);
CS_ON;
delay(2);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = READ;               // Send write command</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = upAddr;             // Send upper address</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = lwAddr;             // Send lower address</span></pre>
<pre><span style="color: #ff9900;">delay(1);
while (!(SPIS &amp; 0x80));    // Wait until ready to send
readin = SPID;             // Dummy read</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = DUMMY;              // Send dummy value</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x80));    // Wait until ready to send
readin = SPID;             // Contains data from memory
delay(5);
CS_OFF;
delay(1);</span></pre>
<pre><span style="color: #ff9900;">return readin;
}</span></pre>
<pre><span style="color: #ff9900;">void Dummy_Read(byte upAddr, byte lwAddr)
{
CS_ON;
delay(2);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = READ;               // Send write command</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = upAddr;             // Send upper address</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = lwAddr;             // Send lower address</span></pre>
<pre><span style="color: #ff9900;">delay(1);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x80));    // Wait until ready to send
garbage = SPID;            // Dummy read</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = DUMMY;              // Send dummy value</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x80));    // Wait until ready to send
garbage = SPID;            // Dummy read</span></pre>
<pre><span style="color: #ff9900;">delay(1);</span></pre>
<pre><span style="color: #ff9900;">while (!(SPIS &amp; 0x20));    // Wait until ready to send
SPID = DUMMY;</span></pre>
<pre><span style="color: #ff9900;">delay(5);
CS_OFF;
delay(1);</span></pre>
<pre><span style="color: #ff9900;">}</span></pre>
<pre><span style="color: #ff9900;">/* END EEPROM */</span></pre>
<pre>[/code]</pre>
]]></content:encoded>
			<wfw:commentRss>http://comp-e.com/using-spi-eeprom-25aa512-on-an-hcs08-microcontroller/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
