<?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>8-bit MicrocontrollersのトピックRe: MC68HC08EY16 and SPI</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187589#M14188</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Currently the code I'm using to send is the following&lt;BR /&gt;PTB_PTB1 = 0;&lt;BR /&gt;i = intSPI_SendChar(0b00001100); //0x0C&lt;BR /&gt;while(!SPSCR_SPTE);&lt;BR /&gt;i = intSPI_SendChar(0b10100000); //0xA0&lt;BR /&gt;while(!SPSCR_SPTE);&lt;BR /&gt;PTB_PTB1 = 1;&lt;BR /&gt;&lt;BR /&gt;where PortB pin 1 is the pin connected to the slave spi select pin (active low)&lt;BR /&gt;&lt;BR /&gt;the intSPI_SendChar is defined as the following&lt;BR /&gt;byte intSPI_SendChar(intSPI_TComData Chr)&lt;BR /&gt;{&lt;BR /&gt;if (!EnMode) { /* Is the device disabled in the actual speed CPU mode? */&lt;BR /&gt;return ERR_SPEED; /* If yes then error */&lt;BR /&gt;}&lt;BR /&gt;if (!SPSCR_SPTE) { /* Is last character sent? */&lt;BR /&gt;return ERR_TXFULL; /* If no then return error */&lt;BR /&gt;}&lt;BR /&gt;SPDR = Chr; /* Send character */&lt;BR /&gt;return ERR_OK; /* OK */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;When running checking the value of i in the debugger with a breakpoint set right after the code, i is set to ERR_OK&lt;BR /&gt;&lt;BR /&gt;I tried changing the value to 0x2A and I tried setting the DDR registers for the spi port explicitly in main (to avoid relying on processor expert to do it). But still with no luck.&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Sep 2008 12:19:05 GMT</pubDate>
    <dc:creator>Stigaard</dc:creator>
    <dc:date>2008-09-23T12:19:05Z</dc:date>
    <item>
      <title>MC68HC08EY16 and SPI</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187586#M14185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm working with a 908E626, which is a chip containing 2 die's one MC68HC08EY16 and one analog die (motor driver). To communicate between the die's one needs to use the SPI interface of the MC68HC08EY16 die. However it seems that no matter what I do I cannot get in contact with the analog die, the spi registers is set up to&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SPCR = 0x28&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SPSCR = 0x08&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and I'm running of a clock of 9.8304Mhz.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate any suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is how the spi is to be setup acording to the datasheet (a diagram is also attached)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The serial peripheral interface (SPI) creates the communication link between the microcontroller and the 908E626.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The interface consists of four pins (see Figure 11):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;•SS — Slave Select&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;•MOSI — Master-Out Slave-In&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;•MISO — Master-In Slave-Out&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;•SPSCK — Serial Clock (maximum frequency 4.0 MHz)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A complete data transfer via the SPI consists of 2 bytes. The master sends address and data, slave system status, and data of the selected address.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;During the inactive phase of SS, the new data transfer is prepared. The falling edge on the SS line indicates the start of a new data transfer and puts MISO in the low-impedance mode. The first valid data are moved to MISO with the rising edge of SPSCK.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The MISO output changes data on a rising edge of SPSCK. The MOSI input is sampled on a falling edge of SPSCK. The data transfer is only valid if exactly 16 sample clock edges are present in the active phase of SS.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After a write operation, the transmitted data is latched into the register by the rising edge of SS. Register read data is internally latched into the SPI at the time when the parity bit is transferred. SS HIGH forces MISO to high impedance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Sep 2008 21:28:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187586#M14185</guid>
      <dc:creator>Stigaard</dc:creator>
      <dc:date>2008-09-22T21:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: MC68HC08EY16 and SPI</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187587#M14186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello, and welcome to the forum.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Firstly, it would seem that the setting should be SPCR = 0x2A; otherwise the SPI module is not enabled.&amp;nbsp; The other register should perhaps be SPSCR = 0x00; since writing 1 to bit-2 does nothing.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I suspect that the frequency you refer to is an external crystal frequency rather than the bus frequency,&amp;nbsp;since the maximum bus frequency is limited to 8MHz.&amp;nbsp; In this case the bus frequency would be 2.4576MHz, and the SPI clock 1.2288MHz.&amp;nbsp; I presume this is OK for the E626 die.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When the SPI module is enabled, the SS pin is an input used for slave operation.&amp;nbsp; For master mode, you will need to determine the pin used for the SS output signal applied to the E626 die.&amp;nbsp; This pin will need to be controlled by your code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You do not provide the details of your communications code, but be aware that the values returned&amp;nbsp;as a result of&amp;nbsp;sending the command and address bytes will probably be meaningless, and to recover the "latched" bytes from the slave, you need to send one or more dummy bytes to the slave, after the SS signal has been raised.&amp;nbsp; The number of dummy bytes will depend on how many bytes are returned.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The typical code for the transfer of a single byte in each direction would be -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;byte SPI_trans( byte val)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; while (!SPSCR_SPTEF);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; SPDR = 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;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; while (!SPSCR_SPRF);&amp;nbsp; // Wait for completion of transfer&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; return SPDR;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;FONT face="Arial"&gt;&lt;FONT face="Arial"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It would appear that the following sequence of events&amp;nbsp;would then be required -&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;SS = 0;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;(void)SPI_trans( command); // Ignore return data&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;(void)SPI_trans( address);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;SS&amp;nbsp;= 1;&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; // Return data latched&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;dat = SPI_trans( 0);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Send dummy byte/return data byte&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;&lt;FONT face="Courier New"&gt;// Return further data bytes if required&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;Is this code something similar to what you are using?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Sep 2008 23:05:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187587#M14186</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-09-22T23:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: MC68HC08EY16 and SPI</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187588#M14187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I'm sorry about not including the code (will do as soon as I get back to the computer with the code on it).&lt;BR /&gt;The code I'm using for a reference for the spi is the one generated by the processor expert in codewarrior.&lt;BR /&gt;&lt;BR /&gt;The frequency I referred to is the external frequency (though from a signal generator for now), acording to the datasheet I should be able to run the E626 up to 4 MHz.&lt;BR /&gt;I will try your suggestions tomorrow and let you know how it goes.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Morten S. Laursen&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Sep 2008 23:20:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187588#M14187</guid>
      <dc:creator>Stigaard</dc:creator>
      <dc:date>2008-09-22T23:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: MC68HC08EY16 and SPI</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187589#M14188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Currently the code I'm using to send is the following&lt;BR /&gt;PTB_PTB1 = 0;&lt;BR /&gt;i = intSPI_SendChar(0b00001100); //0x0C&lt;BR /&gt;while(!SPSCR_SPTE);&lt;BR /&gt;i = intSPI_SendChar(0b10100000); //0xA0&lt;BR /&gt;while(!SPSCR_SPTE);&lt;BR /&gt;PTB_PTB1 = 1;&lt;BR /&gt;&lt;BR /&gt;where PortB pin 1 is the pin connected to the slave spi select pin (active low)&lt;BR /&gt;&lt;BR /&gt;the intSPI_SendChar is defined as the following&lt;BR /&gt;byte intSPI_SendChar(intSPI_TComData Chr)&lt;BR /&gt;{&lt;BR /&gt;if (!EnMode) { /* Is the device disabled in the actual speed CPU mode? */&lt;BR /&gt;return ERR_SPEED; /* If yes then error */&lt;BR /&gt;}&lt;BR /&gt;if (!SPSCR_SPTE) { /* Is last character sent? */&lt;BR /&gt;return ERR_TXFULL; /* If no then return error */&lt;BR /&gt;}&lt;BR /&gt;SPDR = Chr; /* Send character */&lt;BR /&gt;return ERR_OK; /* OK */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;When running checking the value of i in the debugger with a breakpoint set right after the code, i is set to ERR_OK&lt;BR /&gt;&lt;BR /&gt;I tried changing the value to 0x2A and I tried setting the DDR registers for the spi port explicitly in main (to avoid relying on processor expert to do it). But still with no luck.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2008 12:19:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187589#M14188</guid>
      <dc:creator>Stigaard</dc:creator>
      <dc:date>2008-09-23T12:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: MC68HC08EY16 and SPI</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187590#M14189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello Morten,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It seems there may be some misunderstanding about the operation of the flags SPTE and SPRF.&amp;nbsp; With the usual operation of the SPI as a master, the SPTE flag is relatively unimportant, since it is automatically set, and is usually so when an attempt to initiate a send is made.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;However, the SPRF flag is very important because it indicates when a both-way transfer of data has been completed by the master (eight SPI clock cycles after the send was initiated).&amp;nbsp; Your code must clear this flag in a timely manner to prevent an overrun condition.&amp;nbsp; If an overrun condition should occur, the received data will not update the register while the SPRF flag remains set.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;While it is possible to sequentially send two bytes without waiting for the SPRF flag to become set in between, I would strongly recommend that you do not do so.&amp;nbsp; Timing issues are introduced and must be met to prevent overrun from occurring.&amp;nbsp; Sending a single byte, and then waiting until&amp;nbsp;SPRF becomes set (per my previous &lt;FONT face="Courier New"&gt;SPI_trans()&lt;/FONT&gt; function), is safer and has no timing issues.&amp;nbsp; To clear the SPRF flag, you must read the SPI data register, even if you have no interest in the data returned.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Your existing code&amp;nbsp;probably does&amp;nbsp;not work because of the failure to clear the SPRF flag.&amp;nbsp; You do not show how you send a dummy byte in order to read the wanted return data from the motor driver -&amp;nbsp;following PTB_PTB1 = 1;&amp;nbsp; However, before&amp;nbsp;you could do&amp;nbsp;this, you would need to clear the SPRF flag twice.&amp;nbsp; Your&amp;nbsp;&lt;FONT face="Courier New"&gt;intSPI_SendChar()&lt;/FONT&gt;function does not make sense to me in the context of SPI operation.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2008 00:06:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC08EY16-and-SPI/m-p/187590#M14189</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-09-25T00:06:31Z</dc:date>
    </item>
  </channel>
</rss>

