<?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>S12 / MagniV MicrocontrollersのトピックRe: HC12 SPI communication with an EEPROM</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192770#M7590</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached some sample code associated with EEPROM operations.&amp;nbsp; These functions make use of the low level SPI function &lt;FONT face="courier new,courier"&gt;SPI_trans()&lt;/FONT&gt; &lt;FONT face="arial,helvetica,sans-serif"&gt;which would take the following form:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;// SPI transfer of single byte&lt;BR /&gt;byte SPI_trans( byte val)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while (!SPISR_SPTEF);&amp;nbsp; // Wait until ready to send&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SPIDR = val;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Send byte value&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while (!SPISR_SPIF);&amp;nbsp;&amp;nbsp; // Wait until transfer complete&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return SPIDR;&lt;BR /&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition to a SPI initialisation function, you will also need to allocate a GPIO pin for CS usage, with&amp;nbsp;macros similar to those in the header file.&amp;nbsp; These will need to be altered to suit your hardware configuration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Apr 2010 07:37:15 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2010-04-21T07:37:15Z</dc:date>
    <item>
      <title>HC12 SPI communication with an EEPROM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192767#M7587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Freescale lovers and users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am glad that I have the opportunity to learn and work with a Freescale microcontroller!&lt;/P&gt;&lt;P&gt;But I need your help! I am a beginner in embedded world and some things are fuzzy to me!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a MC9S12C32 microcontroller and want to write/read, erase data on/in a EEPROM memory trough SPI.&lt;/P&gt;&lt;P&gt;The first step was to write the functions that I need:&lt;/P&gt;&lt;P&gt;- void SPISetup(void)&lt;/P&gt;&lt;P&gt;- void SPI_selectCS(int state)&lt;/P&gt;&lt;P&gt;- void SPI_writeData(double Data)&lt;/P&gt;&lt;P&gt;- void SPI_readData(double Data)&lt;/P&gt;&lt;P&gt;- void SPI_eraseData(void)&lt;/P&gt;&lt;P&gt;(These are good functions? Could I add/change some other functions?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second step is to write effectively the functions! I was able to write the SPISetup() and SPI_selectCS()...after this is more complicated for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;I know that Freescale documentations are &amp;nbsp;very good and well structured (a colleague of mine told me this) but can anyone tell me or give me some links where can I find programs/tutorials/examples etc with &lt;STRONG&gt;SPI communication with an EEPROM&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've found some pdf files but I am stuck at something and I don't know how to continue!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After, if you can and want to give me some links, if is necessary I will add the code from my functions to see if are correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your support and sorry if there are other topics with the same subject!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice day!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 17 Apr 2010 23:54:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192767#M7587</guid>
      <dc:creator>VasiaUVI</dc:creator>
      <dc:date>2010-04-17T23:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: HC12 SPI communication with an EEPROM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192768#M7588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have not indicated which EEPROM type you are using.&amp;nbsp; The code that is written must have a specific EEPROM in mind.&amp;nbsp; For the higher level functions, you would need to decide whether the function is required to handle a single EEPROM byte, or multiple EEPROM bytes.&amp;nbsp; The EEPROM will usually&amp;nbsp;contain an internal page buffer, to give the option to write or read multiple bytes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would seem that the parameters shown for your read and write functions&amp;nbsp;may be inappropriate (assuming these are intermediate level functions).&amp;nbsp; The storage of floating point data within EEPROM would usually be a higher level function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would normally expect to see parameters for a single data byte value, or a pointer to a data buffer, plus an address at which the data is to be written or read.&amp;nbsp; If handling multiple bytes, the number of bytes would also need to be a parameter.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The read function will need to return&amp;nbsp;a data byte, or alternatively&amp;nbsp;use a pointer to a&amp;nbsp;data buffer&amp;nbsp;.&amp;nbsp; It is also less likely that you would need an erase function, since each byte will be automatically erased before it is written.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition to &lt;FONT face="courier new,courier"&gt;SPI_setup()&lt;/FONT&gt; function, you will need a low level SPI function for the bi-directional transfer of a single byte (for every byte sent a byte is received).&amp;nbsp; This would be used for both read and write processes, and might have the following prototype:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;byte SPI_transfer( byte val);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I would tend to handle the CS pin control as macros, perhaps &lt;FONT face="courier new,courier"&gt;CS_ON&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;CS_OFF&lt;/FONT&gt;.&amp;nbsp; The multiple byte&amp;nbsp;read and write&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;functions might possibly have the following prototypes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void EE_nwrite( word address, byte *buf, byte n);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void EE_nread( word address, byte *buf, byte n);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;These would be typical for binary data.&amp;nbsp; For the storage of string data the form might be a little different.&amp;nbsp; The detail of these functions will depend, to some extent, on the EEPROM type.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 Apr 2010 23:14:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192768#M7588</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-04-18T23:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: HC12 SPI communication with an EEPROM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192769#M7589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mr. Bigmac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for replaying and for your time!&lt;/P&gt;&lt;P&gt;First I've just wanted to know some GOOD tutorials for beginners about HC12 microcontrollers, and specially some &lt;U&gt;example codes&amp;nbsp;&lt;/U&gt; about SPI communication.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;What I want is to try writing and reading some patterns to an EEPROM when I stress the memory part to different temperatures, different voltages, maybe different baud rates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The EEPROM that I want to use is from &lt;STRONG&gt;ST Electronics M95160&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today I've managed to send some data trough SPI and saw the signals on oscilloscope. &amp;nbsp; Next is to write some patterns and write/read to SPI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will have in mind your advices and thank you very much for them. But because embedded C is not my strength is difficult to make code without seeing some tutorials and codes made by others.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, tomorrow I will put here my code until now (it's very small) but hope that this threat to be open and to receive your help in my learning.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Apr 2010 00:42:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192769#M7589</guid>
      <dc:creator>VasiaUVI</dc:creator>
      <dc:date>2010-04-20T00:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: HC12 SPI communication with an EEPROM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192770#M7590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached some sample code associated with EEPROM operations.&amp;nbsp; These functions make use of the low level SPI function &lt;FONT face="courier new,courier"&gt;SPI_trans()&lt;/FONT&gt; &lt;FONT face="arial,helvetica,sans-serif"&gt;which would take the following form:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;// SPI transfer of single byte&lt;BR /&gt;byte SPI_trans( byte val)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while (!SPISR_SPTEF);&amp;nbsp; // Wait until ready to send&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SPIDR = val;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Send byte value&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while (!SPISR_SPIF);&amp;nbsp;&amp;nbsp; // Wait until transfer complete&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return SPIDR;&lt;BR /&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition to a SPI initialisation function, you will also need to allocate a GPIO pin for CS usage, with&amp;nbsp;macros similar to those in the header file.&amp;nbsp; These will need to be altered to suit your hardware configuration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 07:37:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192770#M7590</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-04-21T07:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: HC12 SPI communication with an EEPROM</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192771#M7591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mr. Bigmac,&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;I will try at work to see I can to write and read in/from EEPROM.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Apr 2010 19:44:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/HC12-SPI-communication-with-an-EEPROM/m-p/192771#M7591</guid>
      <dc:creator>VasiaUVI</dc:creator>
      <dc:date>2010-04-25T19:44:08Z</dc:date>
    </item>
  </channel>
</rss>

