<?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>CodeWarrior for MCUのトピックRe: EEPROM write</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139935#M2371</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;Your SM1_SendChar() function would need to wait until the SPIF flag is set, and then read the SPI data register (to clear the flag), before exiting.&amp;nbsp; Otherwise you may be prematurely raising the CS signal before the SPI transfer is complete.&amp;nbsp; It is OK to use a constant value for the function parameter.&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;In addition to verifying the CPOL and CPHA settings, check that the SPI clock rate you are using is suitable for the EEPROM device.&amp;nbsp; There will be a setup delay required after lowering CS, but this will be minimal (typically less than 1 microsecond) for the SPI EEPROM devices I am familiar with.&amp;nbsp; Unless you are using a very high bus clock, the cycles require to exit the CS_PROM_ClrVal() function, and enter the SM1_SendChar() function, would normally provide sufficient delay.&amp;nbsp; I don't believe it would be necessary to have the delay after the completion of the WREN command because again, the minimum CS high period is likely also to be short.&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;Provided the SM1_SendChar() function is OK, if your&amp;nbsp;writes to the EEPROM are unsuccessful, this is more likely to be associated with the WRITE command, rather than the WREN command.&amp;nbsp; Do you hold CS continuously low while all bytes associated with the WRITE command are sent, and then raise CS?&amp;nbsp; Then do you wait a sufficient period for the EEPROM write process to complete, before attempting to read the data?&amp;nbsp; This might&amp;nbsp;take a few milliseconds.&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;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-12-15&lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;12:47 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Dec 2006 22:33:24 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2006-12-14T22:33:24Z</dc:date>
    <item>
      <title>HC08: EEPROM write</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139933#M2369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess, this is something they didn't teach in engineering school, or i must have slept througth the class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;i am just trying to write enable an eeprom through spi. Heres a part of the code&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;CS_PROM_ClrVal(); // select the chip low&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cpu_Delay100US(1);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;spiok = SM1_SendChar(WREN); //WREN is defined as 6 (0000 0110)instruction format&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CS_PROM_SetVal(); // deselect the chip&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cpu_Delay100US(TBD);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Q 1) it seems that the SPI doesn't work without putting a short delay after selecting the chip low. Also, after sending this char, does there have to be a delay before letting the chip go ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Q 2) is the correct instruction format being send this way ? or does the char have to be put in and officially declared as char ' ' ?&lt;/SPAN&gt;&lt;P&gt;Message Edited by CrasyCat on &lt;SPAN class="date_text"&gt;2007-04-13&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:22 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Dec 2006 01:09:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139933#M2369</guid>
      <dc:creator>tmyint</dc:creator>
      <dc:date>2006-12-14T01:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: EEPROM write</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139934#M2370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Q1) What do you mean with "SPI doesn't work"? Do you get any data comming out from the MOSI pin or is it the external device that doesn't work?&lt;BR /&gt;&lt;BR /&gt;Which Freescale processor are you using? On HCS12 you might have to map the SPI to the correct port through the MODRR register.&lt;BR /&gt;&lt;BR /&gt;Double-check that you set the clock polarity and clock phase bits correct (ie in the way the slave device expects them), this is the most common cause of SPI problems.&lt;BR /&gt;Also make sure that your routines are waiting for SPTEF to be set before writing more data to the data register.&lt;BR /&gt;&lt;BR /&gt;Naturally I can't speak for your external memory circuit, it might need some delays before/after writing to it, you tell us.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Q2) Yeah, SM1_SendChar() should expect a char as parameter if it is written correctly. What the function does, nobody knows. If you have questions about code, then please post it.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Dec 2006 16:31:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139934#M2370</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-12-14T16:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: EEPROM write</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139935#M2371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;Your SM1_SendChar() function would need to wait until the SPIF flag is set, and then read the SPI data register (to clear the flag), before exiting.&amp;nbsp; Otherwise you may be prematurely raising the CS signal before the SPI transfer is complete.&amp;nbsp; It is OK to use a constant value for the function parameter.&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;In addition to verifying the CPOL and CPHA settings, check that the SPI clock rate you are using is suitable for the EEPROM device.&amp;nbsp; There will be a setup delay required after lowering CS, but this will be minimal (typically less than 1 microsecond) for the SPI EEPROM devices I am familiar with.&amp;nbsp; Unless you are using a very high bus clock, the cycles require to exit the CS_PROM_ClrVal() function, and enter the SM1_SendChar() function, would normally provide sufficient delay.&amp;nbsp; I don't believe it would be necessary to have the delay after the completion of the WREN command because again, the minimum CS high period is likely also to be short.&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;Provided the SM1_SendChar() function is OK, if your&amp;nbsp;writes to the EEPROM are unsuccessful, this is more likely to be associated with the WRITE command, rather than the WREN command.&amp;nbsp; Do you hold CS continuously low while all bytes associated with the WRITE command are sent, and then raise CS?&amp;nbsp; Then do you wait a sufficient period for the EEPROM write process to complete, before attempting to read the data?&amp;nbsp; This might&amp;nbsp;take a few milliseconds.&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;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-12-15&lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;12:47 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Dec 2006 22:33:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139935#M2371</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-12-14T22:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: EEPROM write</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139936#M2372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Lundin and BigMac,&lt;BR /&gt;&lt;BR /&gt;Thanks for your replies and sorry that I left some of this information out in my earlier post. I am using HC08 with CW v5.0&lt;BR /&gt;basically, i m using SPI for 2 applications. In the first application, I used it on a low side driver basically to do serial to parallel transfer to drive some loads. After numerous at attempting to make it work, I realized that a delay was needed after selecting the chip low before sending, and another delay after sending before selecting the chip high. This problem I have taken care of.&lt;BR /&gt;in the 2nd application, I am writting to an ST95 part with 2 Mhz clock rate. In the SPI bean, I set the shift clock rate to 32microsec which should be fine. Also, the code generated by PE,&lt;BR /&gt;byte SM1_SendChar(SM1_TComData Chr)&lt;BR /&gt;{&lt;BR /&gt;if ((!SPSCR_SPTE)||(SerFlag&amp;amp;FULL_TX)) { /* Is last character sent? */&lt;BR /&gt;return ERR_TXFULL; /* If no then return error */&lt;BR /&gt;}&lt;BR /&gt;if(EnUser) { /* Is device enabled? */&lt;BR /&gt;SPDR = Chr; /* If yes, send character */&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;BufferWrite = Chr; /* If no, save character */&lt;BR /&gt;SerFlag |= FULL_TX; /* ...and set flag */&lt;BR /&gt;}&lt;BR /&gt;return ERR_OK; /* OK */&lt;BR /&gt;}&lt;BR /&gt;automatically checks for these flags. I am not sure what an SPIF flag is because it isn't listed in the SPI SPCR as well as SPSCR registers. Did u mean the SPRF flag and the SPDR need to be read again to clear this flag after sending the char ?&lt;BR /&gt;could it be that since SPI sends MSB first, does the bits need to be reversed in order that they are received in the correct order at the other end ?&lt;BR /&gt;Also,if it takes 10 ms for a write a cycle, does it mean that it will take 100 ms to write 10 bytes ?&lt;BR /&gt;one last Q is, if i read back char, how do i convert them to int to do calculations ? does atoi function still work in this compiler? sorry to make it so lengthy but thanks in advance.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Dec 2006 01:05:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139936#M2372</guid>
      <dc:creator>tmyint</dc:creator>
      <dc:date>2006-12-15T01:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: EEPROM write</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139937#M2373</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;If you have two SPI slave devices in the same project, the low-side driver and the EEPROM, you will require&amp;nbsp;a separate CS (SS)&amp;nbsp;line for each device.&amp;nbsp; If the driver requires the delays to be present, it is not necessary to include them for the EEPROM also.&amp;nbsp; It is quite possible that the SPI will need to be set up differently for each device, so you would run the&amp;nbsp;relevant initialisation function prior to communicating with&amp;nbsp;a particular&amp;nbsp;device.&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 initialisation that PE generates is not clear, and may not be correct for the EEPROM.&amp;nbsp; The CPOL,CPHA settings will need to be either 0,0 or 1,1.&amp;nbsp;&amp;nbsp; Of course, you will not be able to use the automatically generated SS signal (if available for the SPI module).&lt;/FONT&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE dir="ltr"&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;HR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;I am not sure what an SPIF flag is because it isn't listed in the SPI SPCR as well as SPSCR registers. Did u mean the SPRF flag and the SPDR need to be read again to clear this flag after sending the char ?&lt;BR /&gt;&lt;/FONT&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Yes, SPRF is another name for the same flag.&amp;nbsp; However, the&lt;/FONT&gt; &lt;FONT size="2"&gt;SM1_SendChar() function generated by PE does not wait for this flag to be set, so it is problematic to raise CS when this function exits.&amp;nbsp; This function seems to be overly complicated for the task in hand, since your code would need to be able to specifically handle each error return.&amp;nbsp; For SPI operation using higher clock rates, I usually prefer to simply wait until the required flag becomes set - generally only a few microseconds at most.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BLOCKQUOTE dir="ltr"&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;FONT size="2"&gt;could it be that since SPI sends MSB first, does the bits need to be reversed in order that they are received in the correct order at the other end ?&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;MSB first is correct for the EEPROM device.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;BLOCKQUOTE dir="ltr"&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Also,if it takes 10 ms for a write a cycle, does it mean that it will take 100 ms to write 10 bytes ?&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;Yes, if you write ten individual bytes.&amp;nbsp; However, if you use the "page write" mode for ten &lt;U&gt;consecutive&lt;/U&gt; bytes within the same page, the process would take 10ms.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BLOCKQUOTE dir="ltr"&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;if i read back char, how do i convert them to int to do calculations ? does atoi function still work in this compiler?&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;Each&amp;nbsp;data read back from the EEPROM will be a 8-bit binary value, in exactly the same format as the data was originally written.&amp;nbsp; It the data type stored requires more than 8 bits, multiple byte writes and reads will be required for each data element.&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>Fri, 15 Dec 2006 12:18:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139937#M2373</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-12-15T12:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: EEPROM write</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139938#M2374</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;The following thread may also be of interest to you.&amp;nbsp; It discusses an approach to the writing and reading of multiple byte values to serial EEPROM.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&amp;amp;message.id=2939" 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=16BITCOMM&amp;amp;message.id=2939" target="test_blank"&gt;http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&amp;amp;message.id=2939&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Dec 2006 19:35:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC08-EEPROM-write/m-p/139938#M2374</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-12-17T19:35:14Z</dc:date>
    </item>
  </channel>
</rss>

