<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: help with spi function - QG8 in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185898#M13920</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Clearly format is CPOL=CPHA=0. Look at figure 4-1 in Atmel datasheet. You may notice that 1) before communication clock idles low, 2) in-data is sampled on rising edge, 3) out-data is shifted out on falling clock edge. Now open your QE reference manual and look at two figures with CPHA=0 format and CPHA=1 format. Clearly CPOL should be 0, because clock should idle low. Now decide do you need CPHA=0 or CPHA=1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SPI configuration you enabled SSOE bit. Clearly your&amp;nbsp;should not use automatic SS and toggle chip select pin from your code. It looks like you are trying to do so, but SS pins is already driven automatically from SPI module.&amp;nbsp;Try disabling SSOE and MODFEN.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please comment all your magic (and annoying) figures, what each bit means. It is not nice at all to decifier them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Sep 2010 13:26:32 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2010-09-14T13:26:32Z</dc:date>
    <item>
      <title>help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185876#M13898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;im very new to freescale and microcontrollers as a whole and im trying to use one to receive data from an EEPROM chip connected to the SPI port my code is very simple and im using polling rather than interrupts but is not working&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;[code]&lt;/DIV&gt;&lt;DIV&gt;PTBD_PTBD5 = 0;&amp;nbsp;&amp;nbsp; /* chip select low */&lt;BR /&gt;SPID = 0x03;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* send read instruction to memory */&lt;BR /&gt;while ((SPIS &amp;amp; 0x20) == 0) ;&amp;nbsp;&amp;nbsp; /* Wait for instruction byte to be sent */&lt;BR /&gt;SPID = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* provide first read address */&lt;BR /&gt;while ((SPIS &amp;amp; 0x20) == 0) ;&amp;nbsp;&amp;nbsp; /* wait for address byte to be sent */&lt;BR /&gt;&amp;nbsp;SPIC1 = 0x46;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* set spi as slave to receive data&amp;nbsp; */&lt;BR /&gt;for (memorycounter =0 ;memorycounter &amp;lt; 50000; memorycounter ++)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; while ((SPIS &amp;amp; 0x80) == 0) ;&amp;nbsp;&amp;nbsp; /* Wait for memory data byte to be sent back */&lt;BR /&gt;&amp;nbsp; memorydata = SPID;&lt;BR /&gt;&amp;nbsp; SCID = memorydata;&lt;BR /&gt;&amp;nbsp; while ((SCIS1 &amp;amp; 0x80) == 0) ;&amp;nbsp;&amp;nbsp; /* Memory data out serially to RS232/computer */&lt;BR /&gt;}&lt;BR /&gt;PTBD_PTBD5 = 1;&amp;nbsp;&amp;nbsp; /* chip select high */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;[/code]&lt;/DIV&gt;&lt;DIV&gt;i basically just want to read the first 50,000 bytes of memory from EEPROM, just wondering if anything in my code jump out at anyone as being particularly wrong? before i get into the nity gritty stuff.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Much Appreciated&lt;/DIV&gt;&lt;DIV&gt;Rick&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;sorry forgot to mention the micro is a hcs08 QG8&lt;/DIV&gt;&lt;DIV&gt;and in the debug mode my code seems to send the instruction byte ok ( i think) but then then gets stuck sending the address to the EEPROM ( code does not reach any instructions after this one) so maybe im not reseting the status register properly or something?&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by rick123 on &lt;SPAN class="date_text"&gt;2008-02-04&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;06:28 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="time_text"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="time_text"&gt;Added p/n to subject.&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by NLFSJ on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-02-05&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;07:42 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 02:22:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185876#M13898</guid>
      <dc:creator>rick123</dc:creator>
      <dc:date>2008-02-05T02:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185877#M13899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;For one thing, you don't become a slave (in this case), to read back data from the device. What you do is write 0xff and send it, then read back what you got when the sending is done.&lt;BR /&gt;&lt;BR /&gt;With this type of device you have a wire 'or' bus, and by writing 0xff, you let the devices data dominate the bus&lt;BR /&gt;&lt;BR /&gt;This device has no clock, so you must clock it by sending the 0xff.&lt;BR /&gt;&amp;nbsp;You may have other problems, but I don't have the spec right in front of me. If this does not solve it, say so.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;Also you could try creating a test project, and use Processor Expert the generate at least some sample code. I am trying to encourage posters to take this route - even if you don't like to make the whole project P&amp;amp;E it is a great way to get sample code tailored to your usage.&lt;BR /&gt;&lt;BR /&gt;Message Edited by JimDon on &lt;SPAN class="date_text"&gt;2008-02-04&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:19 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 04:06:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185877#M13899</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-02-05T04:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185878#M13900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi Rick,&lt;BR /&gt;&lt;BR /&gt;Well, you have quite a few issues here.&lt;BR /&gt;A good start would be to search for SPI in this forum, there should be lots of examples.&lt;BR /&gt;Also I'm quite unsure of why (or how) Jimdon is suggesting you make a non standard connection to the memory whem you have not told us what EEPROM you are using.&lt;BR /&gt;&lt;BR /&gt;For starters you can't just go writing to the SPID, see &lt;A href="http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=6713" target="_blank"&gt;here.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Then in order to pause until the data is sent you must wait for SPRF not SPTEF. This is because the transmitter is buffered and recieve happens at the same time as send. There is no check for send finish so you use recieve finish as it has the same timing.&lt;BR /&gt;&lt;BR /&gt;Ditto re. not flipping to slave mode, stay in master and send bytes in order to recieve them.&lt;BR /&gt;&lt;BR /&gt;Also does your device only need one byte of address sent? I think you will find it needs more.&lt;BR /&gt;&lt;BR /&gt;Again, for the details &amp;amp; code, search the forum.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 05:01:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185878#M13900</guid>
      <dc:creator>peg</dc:creator>
      <dc:date>2008-02-05T05:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185879#M13901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BR /&gt;Huh? What did I say that implied non-standard?&lt;BR /&gt;&lt;BR /&gt;If it was taken to mean that you should tie dout to din when the device has discrete din and a dout, then let me clarify - don't do that. Some devices do have a single I/O pin, and sometimes this make people think that they need to become a slave to turn the line around.&lt;BR /&gt;&lt;BR /&gt;As we both seem to agree, you do need to clock the device while reading. Normally on a din/dout device di is don't care while it is sending.&amp;nbsp; However, if you write ff, then single data wire devices will also work.&lt;BR /&gt;&lt;BR /&gt;Is still wish I could convince you to try PE - while it might be fun to sit here and answer the same questions over and over, PE can take care of most of this. A lot of time and effort (and money) went in to PE and I have yet to find a case where it generates incorrect code. Also, if you take a few moments to figure out PE when you move to other freescale mcus, it will be a snap to set things up.&lt;BR /&gt;It will set up the module, generate correct read and write code - either interrupt driven on not. It will save you time and money as well.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 05:34:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185879#M13901</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-02-05T05:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185880#M13902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi thanks for all your replies i have tried to do most of what you have said i am able to send data out now and recieve i think but it is comng back garbled &lt;IMG alt=":smileysad:" class="emoticon emoticon-smileysad" id="smileysad" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-sad.gif" title="Smiley Sad" /&gt; im displaying the data from EPROM &amp;nbsp;via SCI which i know is said up correctly&amp;nbsp;as im using that in a similar project. (displaying info through hyperterminal)&lt;/DIV&gt;&lt;DIV&gt;the chip im using is a microchip&amp;nbsp;25LC1024, this is the entire code any idea what&amp;nbsp;else have i missed?&amp;nbsp; Im not sure what you mean by send off hex ff, what does this do ?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks again&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;#include "derivative.h" /* include peripheral declarations */&lt;BR /&gt;#include "MC9S08QG8.h" /* include peripheral declarations */&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;void main(void)&lt;BR /&gt;{&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/********** SETUP VARIABLES ***********************************/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;long int memorycounter=0;&lt;BR /&gt;unsigned char memorydata=0;&lt;BR /&gt;long int address=0;&lt;BR /&gt;unsigned char temp=0;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;for(;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;__RESET_WATCHDOG(); /* feeds the dog */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/************* DATA DIRECTION AND PULL UP REGISTERS** *********/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&lt;BR /&gt;PTADD = 0x00;&lt;BR /&gt;PTAPE = 0x24;&lt;BR /&gt;PTBDD = 0xee;&lt;BR /&gt;PTBPE = 0x11;&lt;BR /&gt;PTBD_PTBD5 = 1;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/**************************************************************/&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/************ SET UP SPI REGISTERS*****************************/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SPIC1 = 0x52;&lt;BR /&gt;SPIC2 = 0x10;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SPIBR = 0x00;&lt;BR /&gt;/************************************************************/&lt;BR /&gt;/**************************************************************/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/************ SET UP SCI REGISTERS ****************************/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SCIBDH = 0;&lt;BR /&gt;SCIBDL = 26;&amp;nbsp;&amp;nbsp; /* 9600 baud */&lt;BR /&gt;SCIC1 = 0x00; /* Normal mode, 8 bits,&amp;nbsp; no parity */&lt;BR /&gt;SCIC2 = 0x4C; /* Enable transmitter and receiver, no interrupts */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/*************************************************************/&lt;BR /&gt;/**************************************************************/&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/******************** DETERMINE MODE READ/WRITE **************/&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;if (PTAD_PTAD2 == 0)&amp;nbsp; /* read chip */&lt;BR /&gt;{&lt;BR /&gt;for (address =0; address &amp;lt;50 ; address ++) {&amp;nbsp;&lt;BR /&gt;PTBD_PTBD5 = 0;&amp;nbsp;&amp;nbsp; /* chip select low */&lt;BR /&gt;SPID = 0x03;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* send read instruction to memory */&lt;BR /&gt;while ((SPIS &amp;amp; 0x80) == 0) ;&amp;nbsp;&amp;nbsp; /* Wait for instruction byte to be sent */&lt;BR /&gt;temp = SPID;&lt;BR /&gt;temp = SPIS;&lt;BR /&gt;SPID = address;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* provide first read address */&lt;BR /&gt;while ((SPIS &amp;amp; 0x80) == 0) ;&amp;nbsp;&amp;nbsp; /* wait for address byte to be sent */&lt;BR /&gt;temp = SPID;&lt;BR /&gt;temp = SPIS;&lt;BR /&gt;while ((SPIS &amp;amp; 0x20) == 0) ;&amp;nbsp;&amp;nbsp; /* Wait for memory data byte to be sent back */&lt;BR /&gt;temp = SPIS;&lt;BR /&gt;memorydata = SPID;&lt;BR /&gt;PTBD_PTBD5 = 1;&amp;nbsp;&amp;nbsp; /* chip select high */&lt;BR /&gt;SCID = memorydata;&lt;BR /&gt;while ((SCIS1 &amp;amp; 0x80) == 0) ; /* Memory data out serially to RS232/computer */&lt;BR /&gt;}&lt;BR /&gt;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by rick123 on &lt;SPAN class="date_text"&gt;2008-02-04&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:51 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 07:48:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185880#M13902</guid>
      <dc:creator>rick123</dc:creator>
      <dc:date>2008-02-05T07:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185881#M13903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;Ok, first of all to read a byte you have to send a byte to clock the chip. If you have to send a byte, I am suggesting that it be FF. I the case of this chip it does not matter, because the spec says the SI line is "don't care" when the chip is sending data.&lt;BR /&gt;&lt;BR /&gt;It would make life easier if you created a function to send/recieve a byte.&lt;BR /&gt;&lt;BR /&gt;byte SendRecieveSPI( byte data )&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; SPID = data;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while(!SPIS_SPRF) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; data = SPID;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return data;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Also as peg pointed out, you should do this in your init code, &lt;B&gt;before&lt;/B&gt; you start using the SPI:&lt;BR /&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; (void)SPIS;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read the status register&lt;BR /&gt;&amp;nbsp; (void)SPID;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read the device register&lt;BR /&gt;&lt;/FONT&gt;&lt;BR /&gt;You should also declare temp as &lt;FONT face="Courier New"&gt;volatile&lt;/FONT&gt; in&amp;nbsp; case&amp;nbsp; the compiler decides to optimize away the code that in it's mind is not doing any thing useful.&lt;BR /&gt;&lt;BR /&gt;You need to send a 24 bit address.&lt;BR /&gt;Quoting the spec.&lt;BR /&gt;The device is selected by pulling CS low. The 8-bit read instruction is transmitted to the 25XX1024 &lt;I&gt;followed by the 24-bit address&lt;/I&gt;, with seven MSBs of the address being don’t care bits. After the correct read instruction and address are sent, the data stored in the memory at the selected address is shifted out on the SO pin. The data stored in the memory at the next address can be read sequentially by continuing to provide clock pulses. The internal address pointer is automatically incremented to the next higher address after each byte of data is shifted out. When the highest address is reached (1FFFFh), the address counter rolls over to address 00000h allowing the read cycle to be continued indefinitely. &lt;I&gt;The read operation is terminated by raising the CS pin&lt;/I&gt; (Figure 2-1).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So what you need to do is:&lt;BR /&gt;Raise Chip Select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do this to be sure you have cleared the chip&lt;BR /&gt;Lower Chip Select&lt;BR /&gt;Send Read Command&lt;BR /&gt;(Send address &amp;gt;&amp;gt; 16) &amp;amp; 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Send the highest byte - only the lsb counts here.&lt;BR /&gt;(Send address &amp;gt;&amp;gt; 8) &amp;amp; 0xff&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Send the middle&lt;BR /&gt;(Send&amp;nbsp; address) &amp;amp; 0xff&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Send&amp;nbsp; the lo byte.&lt;BR /&gt;&lt;BR /&gt;Now you can loop on reading back as many bytes as you need.&lt;BR /&gt;Note however, you must NOT raise the CS line until you are done reading.&lt;BR /&gt;Raising the CS line signals you are done and resets the chip to receive another command.&lt;BR /&gt;However, when you are done reading and wish to start another command, you MUST raise the CS line.&lt;BR /&gt;Also, don't forget you must erase a sector or a block before writing.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN class="time_text"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="time_text"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="time_text"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by JimDon on &lt;SPAN class="date_text"&gt;2008-02-04&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;08:45 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 09:37:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185881#M13903</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-02-05T09:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185882#M13904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello Rick,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The following old thread may be of assistance for your problem.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=2191" target="_blank"&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=2191" target="test_blank"&gt;http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=2191&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-02-05&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;06:18 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 15:16:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185882#M13904</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-02-05T15:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185883#M13905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi again thanks for the reply im really not getting this however i have done what you have mentioned in the code but im not sure im grasping the whole thing here could you please show me which part of my code to change&amp;nbsp; ( im prettysure my sendign 0xff bit is wrong ) really new to this thanks for your patience.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;void main(void)&lt;BR /&gt;{&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/********** SETUP VARIABLES ***********************************/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;long int memorycounter=0;&lt;BR /&gt;unsigned char memorydata=0;&lt;BR /&gt;unsigned char address=0;&lt;BR /&gt;volatile char temp=0;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;for(;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;__RESET_WATCHDOG(); /* feeds the dog */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/************* DATA DIRECTION AND PULL UP REGISTERS** *********/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&lt;BR /&gt;PTADD = 0x00;&lt;BR /&gt;PTAPE = 0x24;&lt;BR /&gt;PTBDD = 0xee;&lt;BR /&gt;PTBPE = 0x11;&lt;BR /&gt;PTBD_PTBD5 = 1;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/**************************************************************/&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/************ SET UP SPI REGISTERS*****************************/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SPIC1 = 0x52;&lt;BR /&gt;SPIC2 = 0x10;&amp;nbsp;&amp;nbsp; /* 9600 baud */&lt;BR /&gt;SPIBR = 0x00; /* Normal mode, 8 bits,&amp;nbsp; no parity */&lt;BR /&gt;(void)SPIS;&lt;BR /&gt;(void)SPID;&lt;BR /&gt;/************************************************************/&lt;BR /&gt;/**************************************************************/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;/************ SET UP SCI REGISTERS ****************************/&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SCIBDH = 0;&lt;BR /&gt;SCIBDL = 26;&amp;nbsp;&amp;nbsp; /* 9600 baud */&lt;BR /&gt;SCIC1 = 0x00; /* Normal mode, 8 bits,&amp;nbsp; no parity */&lt;BR /&gt;SCIC2 = 0x4C; /* Enable transmitter and receiver, no interrupts */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/*************************************************************/&lt;BR /&gt;/**************************************************************/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/**************************************************************/&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/******************** DETERMINE MODE READ/WRITE **************/&lt;BR /&gt;/**************************************************************/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;if (PTAD_PTAD2 == 0)&amp;nbsp; /* read chip */&lt;BR /&gt;{&lt;BR /&gt;PTBD_PTBD5 = 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //chip select low&lt;BR /&gt;SPID = 0xff;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //send the byte to clock the chip?&lt;BR /&gt;while (!SPIS_SPRF) ;&lt;BR /&gt;PTBD_PTBD5 = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //chip select high&lt;BR /&gt;PTBD_PTBD5 = 0;&amp;nbsp;&amp;nbsp; /* chip select low */&lt;BR /&gt;SPID = 0x03;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* send read instruction to memory */&lt;BR /&gt;while (!SPIS_SPRF) ;&amp;nbsp;&amp;nbsp; /* Wait for read instruction byte to be sent */&lt;BR /&gt;temp = SPID;&lt;BR /&gt;temp = SPIS;&lt;BR /&gt;SPID = 0x000;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* provide first read address */&lt;BR /&gt;for (memorycounter=0; memorycounter&amp;lt;50; memorycounter ++)&lt;BR /&gt;{&lt;BR /&gt;while (!SPIS_SPRF) ;&amp;nbsp;&amp;nbsp; /* wait for address byte to be sent */&lt;BR /&gt;temp = SPID;&lt;BR /&gt;temp = SPIS;&lt;BR /&gt;while (!SPIS_SPRF) ;&amp;nbsp;&amp;nbsp; /* Wait for memory data byte to be sent back */&lt;BR /&gt;temp = SPIS;&lt;BR /&gt;memorydata = SPID;&lt;BR /&gt;SCID = memorydata;&lt;BR /&gt;while ((SCIS1 &amp;amp; 0x80) == 0) ; /* Memory data out serially to RS232/computer */&lt;BR /&gt;}&lt;BR /&gt;PTBD_PTBD5 = 1;&amp;nbsp;&amp;nbsp; /* chip select high */&lt;BR /&gt;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 20:24:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185883#M13905</guid>
      <dc:creator>rick123</dc:creator>
      <dc:date>2008-02-05T20:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185884#M13906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BR /&gt;You need to send 3 bytes of address.&lt;BR /&gt;Please consider doing as&amp;nbsp; mac hassuggested, use a subroutine to send /receive from the spi.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2008 21:05:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185884#M13906</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-02-05T21:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185885#M13907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;The for loop used to clock the data from the EEPROM is still incorrect.&amp;nbsp; You are never sending dummy data (0xFF) to the EEPROM so that it will send the data you want back to you.&amp;nbsp; All you are doing is reading the SPI Status Register and SPI Data Register.&amp;nbsp;&amp;nbsp;I would suggest you read&amp;nbsp;the wiki page on SPI to get a better understanding of how SPI communication works:&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank"&gt;http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You really should be using a function to send/receive through the SPI, it will make the code much&amp;nbsp;cleaner and easier to use in the future.&amp;nbsp; From the link bigmac provided is the following simple function to send/receive SPI data, it has been modified for your microcontroller registers:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;byte SPI_proc (byte data){   while (!SPIS_SPTEF);  /* Wait for Tx buffer empty */   SPDR = data;          /* Send byte */   while (!SPIS_SPRF);   /* Wait for Rx buffer full */   return (SPDR);        /* Received byte value */}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Now before your for loop you need to send 3 address bytes, you declared the address as an unsigned character but you need 17 bits to address all of the EEPROM so declare it as an unsigned long.&amp;nbsp; To start a read from address 0 then set the variable address to 0 then:&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;SPI_proc(3);     // Command to read data from EEPROMSPI_proc((address &amp;gt;&amp;gt; 16) &amp;amp; 0x01);  // Send highest byte, only LSB mattersSPI_proc((address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF);   // Send middle byteSPI_proc(address &amp;amp; 0xFF);          // Send lowest byte&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Now you have your for loop and you simply&amp;nbsp;send dummy bytes,&amp;nbsp;0xFF will work but so will any other byte.&lt;/DIV&gt;&lt;DIV&gt;Using the variables you provided:&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;for (memorycounter=0; memorycounter&amp;lt;50; memorycounter ++){   memorydata = SPI_proc(0xFF);   // Read in a byte from the EEPROM   while (!SCIS1_TDRE);           // Make sure SCI transmit buffer is empty   SCID = memorydata;             // Send the byte over the SCI}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;The first time that you use the SPI module though it should be initialized by the&amp;nbsp;code&amp;nbsp;JimDon posted:&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; (void)SPIS;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read the status register&lt;BR /&gt;&amp;nbsp; (void)SPID;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read the device register&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;All that being&amp;nbsp;said,if you haven't written anything to the&amp;nbsp;EEPROM yet&amp;nbsp;all you will read is&amp;nbsp;0xFF from it.&amp;nbsp; I would suggest testing the above code with that in mind then using&amp;nbsp;the SPI_proc function to&amp;nbsp;test writing then reading the same data back from the EEPROM.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by allawtterb on &lt;SPAN class="date_text"&gt;2008-02-05&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:59 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:36:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185885#M13907</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2020-10-29T09:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185886#M13908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;A minor point -&lt;/FONT&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;allawtterb wrote:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The first time that you use the SPI module though it should be initialized by the&amp;nbsp;code&amp;nbsp;JimDon posted:&lt;/FONT&gt;&lt;/P&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp; (void)SPIS;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read the status register&lt;BR /&gt;&amp;nbsp; (void)SPID;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read the device register&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;My understanding is that, for HCS08 and HCS12 devices (but not for HC08 devices), it is required to read SPIS prior to the first write to SPID.&amp;nbsp; It is not necessary to read SPID.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Since the SPI_proc() function incorporates the test of the SPTEF flag, this will provide the required first-time read for SPIS.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2008 00:54:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185886#M13908</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-02-06T00:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185887#M13909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi all thanks for your help i now have it working and receiving FF data responses as expected , cheers for all your patience!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2008 00:41:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185887#M13909</guid>
      <dc:creator>rick123</dc:creator>
      <dc:date>2008-02-07T00:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185888#M13910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi sorry i have one more question i am able as i said before to read the memory and i can erase it but i seem to run into a problem when writing to i.&lt;/DIV&gt;&lt;DIV&gt;Im trying to just as a test write the character "A" to memory location 4, but it seems to write a completley different character to memory location 0 instead?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;not sure why, i assumed it would be very similar to the coding you have given me on this forum already&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;if (PTAD_PTAD5 == 0) //write to the chip  {    address = 4;    PTBD_PTBD5 = 0;  //chip select low    SPI_proc(6);     // Command to enable the write latch    PTBD_PTBD5 = 1;  // chip select high    PTBD_PTBD5 = 0;  // chip select low    SPI_proc(2);     // Command to write data to EEPROM    SPI_proc((address &amp;gt;&amp;gt; 16) &amp;amp; 0x01);  // Send highest byte, only LSB matters    SPI_proc((address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF);   // Send middle byte    SPI_proc(address &amp;amp; 0xFF);    SPI_proc('A' &amp;amp; 0xFF);  // send charcter "A" to memory location 4    PTBD_PTBD5 = 1; //chip selct high  }&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;using the function below that you have me already&amp;nbsp;to actually send the data byte&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;byte SPI_proc (byte data){   while (!SPIS_SPTEF);  /* Wait for Tx buffer empty */   SPID = data;          /* Send byte */   while (!SPIS_SPRF);   /* Wait for Rx buffer full */   return (SPID);        /* Received byte value */}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;any&amp;nbsp;ideas?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by rick123 on &lt;SPAN class="date_text"&gt;2008-02-08&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:18 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:36:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185888#M13910</guid>
      <dc:creator>rick123</dc:creator>
      <dc:date>2020-10-29T09:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185889#M13911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;What does it write? Does it alway write the same thing?&lt;BR /&gt;&lt;BR /&gt;You are supposed to read the status register to know when the write is done.&lt;BR /&gt;&lt;BR /&gt;See the RDSR command. You should loop until the WIP bit goes to 0.&lt;BR /&gt;Also, it is hard to say that you can read if you can't write - when you are reading back FF you don't know&lt;BR /&gt;what address you are reading - are you sure you are reading the correct address back?&lt;BR /&gt;Do you do an erase before each test run?&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 23:03:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185889#M13911</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-02-08T23:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185890#M13912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Yeh just as a test i was havin the same character written to just one memory address.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The read code im pretty sure is working since i read the first 50 memory locations and each has FF&amp;nbsp;data ( once erased) .&amp;nbsp; when i use my write code memory address 0 takes the value 0x01 even though in the code it&amp;nbsp;says write "A" &amp;nbsp;to memory address 4.&lt;/DIV&gt;&lt;DIV&gt;im leaving at least&amp;nbsp; 3 second gaps between reading/writing/erasing so the previous read/write or erase action should defineltey have been completed.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 23:23:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185890#M13912</guid>
      <dc:creator>rick123</dc:creator>
      <dc:date>2008-02-08T23:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185891#M13913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Well, I don't know how you are timing this, and a chip erase can take up to 4 seconds.&lt;BR /&gt;&lt;BR /&gt;I also don't know how you can say with any degree of certainty that you are reading correctly when you are reading FF at all locations. You should write an&amp;nbsp; address in address test - meaning you write 0 in address 0 and 1 in address&amp;nbsp; 1 and so on&amp;nbsp; from 0 to 255&amp;nbsp; to prove that all is working.&lt;BR /&gt;&lt;BR /&gt;I am just trying to share with you the problems I had.&lt;BR /&gt;&lt;BR /&gt;You should write a function to poll the status register and wait for the&amp;nbsp; WIP to be zero. Even if this is not a problem now it will be a problem later. If you use a timer, then for one thing you will be mostly waiting too long, and if you ever change the time period of the timer down the road, all of a sudden your flash code may stop working and you will be wondering why.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2008 23:53:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185891#M13913</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-02-08T23:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185892#M13914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I agree with Jim, try writing 0-255 to address 0-255 then read all the data back and see what you get.&amp;nbsp; Also, try to poll the status register.&amp;nbsp; All it takes to do this is:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void SPI_Write_Wait(void){   unsigned char Status_Register = 0x01;   // Perhaps turn on an LED here if one is avaliable   while (Status_Register == 0x01)      // Continue until bit is cleared   {      PTBD_PTBD5 = 0;                   // Select the EEPROM      SPI_proc(5);                      // Command to read the status register      Status_Register = (SPI_proc(0xFF) &amp;amp; 0x01); // Write dummy bytes, read data back in and mask it      PTBD_PTBD5 = 1;                   // Disable the EEPROM select   }   // Turn LED off if available}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;You might be able to put the chip select and de-select outside of the whlie loop.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The steps should be:&lt;/DIV&gt;&lt;DIV&gt;1) Page erase of page to be written&lt;/DIV&gt;&lt;DIV&gt;2) Call SPI_Write_Wait for erase to complete&lt;/DIV&gt;&lt;DIV&gt;3) Write all 256 bytes&lt;/DIV&gt;&lt;DIV&gt;4) Call SPI_Write_Wait for write to complete&lt;/DIV&gt;&lt;DIV&gt;5) Read back in all 256 bytes&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:36:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185892#M13914</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2020-10-29T09:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185893#M13915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Tried everything&amp;nbsp; you have told me, not sure why it is not working, when i write to the chip it is writing rubbish.&amp;nbsp; I know the erase part works since when i erase it and re-read all the garbled bits have value FF so it is just the write function that is not working am i setting up the the control registers wrong&amp;nbsp;or something i really dont have a clue... &lt;IMG alt=":smileysad:" class="emoticon emoticon-smileysad" id="smileysad" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-sad.gif" title="Smiley Sad" /&gt;&lt;/DIV&gt;&lt;DIV&gt;i thought&amp;nbsp;i would include the code as an attachment, it is a really small program however.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any last ideas&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by rick123 on &lt;SPAN class="date_text"&gt;2008-02-11&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:33 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2008 21:32:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185893#M13915</guid>
      <dc:creator>rick123</dc:creator>
      <dc:date>2008-02-11T21:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185894#M13916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;You can remove the SPI_erase, it seems the chip does an erase automatically before a write.&amp;nbsp; Also, can you explain what you mean when you say it writes rubbish?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 01:50:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185894#M13916</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-02-12T01:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: help with spi function - QG8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185895#M13917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Some comments about your posted code -&lt;/FONT&gt;&lt;/DIV&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;When you read each byte, you send the raw value to the SCI.&amp;nbsp; If you are monitoring this using Hyperterminal, or similar, the displayed results will probably not make sense unless you are writing an ASCII character.&amp;nbsp; If not ASCII,&amp;nbsp;you will need to convert the raw value to some sort of ASCII format, perhaps two hexadecimal characters to represent each byte.&amp;nbsp; Incidently, it would be usual to test the TDRE flag prior to writing to the SCI, not following the write.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Within your EEPROM write process, you seem to be writing the same ASCII character "$" to all locations.&amp;nbsp; Not sure whether this was your intent.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Check the EEPROM specification, but it may be possible to send consecutive bytes to the EEPROM, without the need to repeatedly enable writes, and separately send&amp;nbsp;each address value.&amp;nbsp; If this is possible, you need to be aware of the internal buffer size within the EEPROM.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;The function SPI_Statuscheck() may be problematic because of the use of a while loop.&amp;nbsp; For the first pass through the loop, the value within Status_Register has not been updated.&amp;nbsp; Alternatively, you might use a do/while loop.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;You have a setting of CPHA = 0, CPOL = 0.&amp;nbsp; Check that this matches the EEPROM requirements.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;You seem to be manually&amp;nbsp;controlling&amp;nbsp;PTBD5 as the SS (CS) output line.&amp;nbsp; Yet you have also enabled automatic SS output at PTB5.&amp;nbsp; The automatic operation will take precedence over GPIO control, and this will not meet the requirements of the EEPROM device.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-02-12&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:33 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 11:18:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-spi-function-QG8/m-p/185895#M13917</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-02-12T11:18:35Z</dc:date>
    </item>
  </channel>
</rss>

