<?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>ColdFire/68K Microcontrollers and Processors中的主题 Re: Question about SPI communications between MCF51MM256 and external RTC</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169937#M6235</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;OL&gt;&lt;LI&gt;Double check CPOL and CPHA settings.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. You are setting CS off prematurely in Init_RTC(). SPTEF flag is set long before transfer is complete. I hope&amp;nbsp;you have scope to check it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. You can't read SPID output buffer. Reads from data register return data from SPI input buffer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Dec 2010 02:05:57 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2010-12-16T02:05:57Z</dc:date>
    <item>
      <title>Question about SPI communications between MCF51MM256 and external RTC</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169936#M6234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have problems trying to communicate a MCF51MM256 with PCF2127A RTC through SPI. I am using a TWR_MCF51MM-Kit. I set MCF51MM256 as master and it seems that the transfer of commands and data go out but i am not getting the answer I hope from the RTC, i.e, when I try to do a sequential red i just got a byte with an illogical value. I'll put my code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;//*************************************
//&amp;nbsp;&amp;nbsp; MCF51MM256 Init
//***************************************/
void MCU_Init(void)
{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; SOPT1 = 0x23;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* disable COP, enable stop mode, enable BKGD and RESET pin */
&amp;nbsp;&amp;nbsp;&amp;nbsp; SCGC1 = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Disable Bus clock to unused peripherals */
&amp;nbsp;&amp;nbsp;&amp;nbsp; SCGC2 = 0x01;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Bus Clock to the SPI1 module is enable */
&amp;nbsp;&amp;nbsp;&amp;nbsp; SCGC3 = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Disable Bus clock to unused peripherals */
}

//*************************************
//&amp;nbsp;&amp;nbsp; SPI_Init
//**********************************/
void SPI_Init(void)
{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1C1 = 0x54;// Enable SPI1, sets SPI as master Device,
&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; // transfers start with most significant bit
&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1C2 = 0x00;// SPI1 in 8-bit mode, separate pins for input/ output&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1BR = 0x04;&amp;nbsp; // prescale divisor 1, baudrate divisor 32
&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; // getting aprox 131 kHz

&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI2C1 = 0x00;&amp;nbsp; //0 0 0 0 0 0 0 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; // Disable SPI2
&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;&amp;nbsp; SPI1S = 0x00;
&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; // Wait until ready to send
&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( !(SPI1S &amp;amp; SPI1S_SPTEF_MASK) );
&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1ML = 0xFF;
}

//*********************************
// Init_RTC
//***************************************/
void Init_RTC( void)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; byte i, buffer[ 2 ];

&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer[0] = 0x20 | 0x03;&amp;nbsp; // command for writng Seconds register on RTC
&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer[1] = i2bcd( 15 ); // value to write on Seconds register

&amp;nbsp;&amp;nbsp;&amp;nbsp; CS_ON;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // set chip enable sign for RTC through a GPIO
&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( !(SPI1S &amp;amp; SPI1S_SPTEF_MASK) );&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for ( i = 0; i &amp;lt; 2; i++ )
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1DL = buffer[i];&amp;nbsp;&amp;nbsp; // Send byte value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while( !(SPI1S &amp;amp; SPI1S_SPTEF_MASK) );
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; CS_OFF;&amp;nbsp; // disable connection sign to RTC
}

//********************************
// Read_RTC
//**************************************/
byte Read_RTC( void)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; byte i, buffer[ 2];

&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer[0] = 0xA0 | 0x03; // command for reading Seconds register on RTC

&amp;nbsp;&amp;nbsp;&amp;nbsp; CS_ON; // set chip enable sign for RTC through a GPIO
&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( !(SPI1S &amp;amp; SPI1S_SPTEF_MASK) );
&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1D = buffer[0];&amp;nbsp;&amp;nbsp; // Send command byte
&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( !(SPI1S &amp;amp; SPI1S_SPTEF_MASK) );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( !(SPI1S &amp;amp; SPI1S_SPRF_MASK) );&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer[1]= SPI1DL;
&amp;nbsp;&amp;nbsp;&amp;nbsp; CS_OFF;
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return bcd2i(buffer[1]);
}

//***************************************
// MainLoop
//*************************************/
void main(void)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; EnableInterrupts; /* enable interrupts */ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* include your code here */
&amp;nbsp;&amp;nbsp;&amp;nbsp; MCU_Init();
&amp;nbsp;&amp;nbsp;&amp;nbsp; // ... Use here some code that initializes the Ports of the MCU
&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI_Init();

&amp;nbsp;&amp;nbsp;&amp;nbsp; Init_RTC();
&amp;nbsp;&amp;nbsp;&amp;nbsp; // ... Use here some dummy code to introduce a time delay
&amp;nbsp;&amp;nbsp;&amp;nbsp; byte s = Read_RTC();

&amp;nbsp;&amp;nbsp;&amp;nbsp; for(;;)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __RESET_WATCHDOG();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; } //
&amp;nbsp;&amp;nbsp;&amp;nbsp; // please make sure that you never leave main
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some suggestions about causes for not getting the "logical" values ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While I am trying to debug this code with CodeWarrior Real Time Debugger&amp;nbsp; I can not see changes in the contents of the Memory at the address of SPI1DL register after&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SPI1DL = buffer[i];&lt;/PRE&gt;&lt;P&gt;instructions is executed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;i2bcd() and bcd2i() are just funstions for coding numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your attention, in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:18:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169936#M6234</guid>
      <dc:creator>aydsae</dc:creator>
      <dc:date>2020-10-29T09:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SPI communications between MCF51MM256 and external RTC</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169937#M6235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;OL&gt;&lt;LI&gt;Double check CPOL and CPHA settings.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. You are setting CS off prematurely in Init_RTC(). SPTEF flag is set long before transfer is complete. I hope&amp;nbsp;you have scope to check it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. You can't read SPID output buffer. Reads from data register return data from SPI input buffer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Dec 2010 02:05:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169937#M6235</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2010-12-16T02:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SPI communications between MCF51MM256 and external RTC</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169938#M6236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much Kef for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have archived a lot of progress... However, I&amp;nbsp;can&amp;nbsp;not found the way to read data from the slave. As I understand, master have to generate the clock signal to the slave but I have not found in the documentation how&amp;nbsp;set it. I have&amp;nbsp;tested using the GPIO ports and I get data from the RTC properly. But when I use the&amp;nbsp;SPI module, I see in the scope that clock&amp;nbsp;is stoped&amp;nbsp;when I want to get data. I guess I am missing something but not idea about what.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Dec 2010 00:56:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169938#M6236</guid>
      <dc:creator>aydsae</dc:creator>
      <dc:date>2010-12-17T00:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SPI communications between MCF51MM256 and external RTC</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169939#M6237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you know what FLS module is? You disabled clock to them, but maybe it is somehow coupled to SPI?&lt;/P&gt;&lt;P&gt;S08 have similar SPI modules. Try searching 8-bitters forum for code examples.&lt;/P&gt;&lt;P&gt;I think your code should produce some SPI clocks, though I don't have MCF51MM to try what's wrong. I can only advice that routine for master I/O, both read from spi and write to spi &amp;nbsp;should look like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;char spiio(char tosend)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; while ( !(SPI1S &amp;amp; SPI1S_SPTEF_MASK) );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPIDL = tosend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; while ( !(SPI1S &amp;amp; SPI1S_SPRF_MASK) );&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return&amp;nbsp; SPIDL;.&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doing master&amp;nbsp;SPI you can't receive without sending something. Also when&amp;nbsp;sending, you receive some data, like you that or not. Routine is for both send and receive.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Dec 2010 15:39:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169939#M6237</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2010-12-17T15:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Question about SPI communications between MCF51MM256 and external RTC</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169940#M6238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks kef, yesterday I made some tests and everything went right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I consider that the sentence&lt;/P&gt;&lt;P&gt;"Doing master&amp;nbsp;SPI you can't receive without sending something"&lt;/P&gt;&lt;P&gt;is the principal point that I was not applying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Dec 2010 17:17:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Question-about-SPI-communications-between-MCF51MM256-and/m-p/169940#M6238</guid>
      <dc:creator>aydsae</dc:creator>
      <dc:date>2010-12-18T17:17:04Z</dc:date>
    </item>
  </channel>
</rss>

