<?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: Receiving &amp;quot;ack&amp;quot; over SCI</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181628#M6180</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;with the two statements&amp;nbsp; you are disabeling the receiver right after enabling it.&lt;/P&gt;&lt;P&gt;So you wont receive an ACK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dont know about the random bytes, but maybe you need a pullup on RX and TX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eckhard&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 
  SCI2C2 = 0b00000100;  //enable R
  SCI2C2 = 0b00001000;  //enable T


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:32:05 GMT</pubDate>
    <dc:creator>eckhard</dc:creator>
    <dc:date>2020-10-29T09:32:05Z</dc:date>
    <item>
      <title>Receiving "ack" over SCI</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181627#M6179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to interface a HCS08QE32 to the uDRIVE-uSD-G1 (an embedded DOS uSD card module), which has a command set for reading/writing etc to it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I am trying to write a file to it, this requires the micro to:&lt;BR /&gt;wait some time for device to settle,&lt;BR /&gt;send byte to lock onto baud rate,&lt;BR /&gt;micro should receive "ack" byte,&lt;BR /&gt;send bytes to set up file,&lt;BR /&gt;receive ack,&lt;BR /&gt;send file data bytes.&lt;BR /&gt;receive ack.&lt;BR /&gt;&lt;BR /&gt;...problem is, my program sends the auto-baud command (tested with serial terminal, Docklight), then just sends random bytes while waiting for ack. I have tried removing the wait-for-ack code, replacing with delays, and just sending the commands, which seems to send all required bytes, followed by random bytes, but does not create file.&lt;BR /&gt;&lt;BR /&gt;I can write a file by sending the commands through Docklight (and getting the expected acks), so uSD module is working fine.&lt;BR /&gt;&lt;BR /&gt;I think the problem must lie in either my wait-for-ack code, or possibly the initial delay time (which I've tried changing a bit). Should I disable the micro Tx pin while waiting for ack, rather than let it send random data? Any Ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations *///Delay functionvoid delay( long val){&amp;nbsp;&amp;nbsp; for ( ; val; val--);}void main(void) {&amp;nbsp;&amp;nbsp;&amp;nbsp; SCI2BD = 26; //set baud rate 96000 with busclock=4MHz&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;&amp;nbsp;&amp;nbsp; //delay while device settles (should be ~500ms)&amp;nbsp;&amp;nbsp; delay(5000);&amp;nbsp;&amp;nbsp;&amp;nbsp; SCI2C2 = 0b00000100;&amp;nbsp; //enable R&amp;nbsp; SCI2C2 = 0b00001000;&amp;nbsp; //enable T&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x55; //auto baud&amp;nbsp;&amp;nbsp;&amp;nbsp; //wait for ack&amp;nbsp; do&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; while(!SCI2S1_RDRF); //wait for received byte&amp;nbsp; }&amp;nbsp;&amp;nbsp; while (SCI2D != 0x06); //check for ack&amp;nbsp; //&amp;nbsp; delay(100);&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set up file&amp;nbsp;&amp;nbsp;&amp;nbsp; //write&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x40;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x74;&amp;nbsp; //no handshaking&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp; //file name&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x46;&amp;nbsp; //"F"&amp;nbsp;&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x6E;&amp;nbsp; //"N"&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x74;&amp;nbsp; //"T"&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x31;&amp;nbsp; //"1"&amp;nbsp; //null&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x00;&amp;nbsp; //file size&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x00;&amp;nbsp; while (!SCI2S1_TDRE); // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x00;&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x00;&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x05;&amp;nbsp; //5 bytes&amp;nbsp;&amp;nbsp;&amp;nbsp; delay(100);&amp;nbsp;&amp;nbsp;&amp;nbsp; //wait for ack&amp;nbsp; do&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; while(!SCI2S1_RDRF); //wait for received byte&amp;nbsp; }&amp;nbsp;&amp;nbsp; while (SCI2D != 0x06);&amp;nbsp; //check for ack&amp;nbsp; //&amp;nbsp;&amp;nbsp;&amp;nbsp; //send data&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x68;&amp;nbsp; //"h"&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x65;&amp;nbsp; //"e"&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x6C;&amp;nbsp; //"l"&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x6C;&amp;nbsp; //"l"&amp;nbsp; while (!SCI2S1_TDRE);&amp;nbsp; // wait for the transmit buffer to be empty&amp;nbsp; SCI2D = 0x6F;&amp;nbsp; //"o"&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; delay(100);&amp;nbsp;&amp;nbsp;&amp;nbsp; //wait for ack&amp;nbsp; do&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; while(!SCI2S1_RDRF); //wait for received byte&amp;nbsp; }&amp;nbsp;&amp;nbsp; while (SCI2D != 0x06); //check for ack&amp;nbsp; //&amp;nbsp;&amp;nbsp; while(1);}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Iain&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:32:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181627#M6179</guid>
      <dc:creator>Iain</dc:creator>
      <dc:date>2020-10-29T09:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Receiving "ack" over SCI</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181628#M6180</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;with the two statements&amp;nbsp; you are disabeling the receiver right after enabling it.&lt;/P&gt;&lt;P&gt;So you wont receive an ACK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dont know about the random bytes, but maybe you need a pullup on RX and TX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eckhard&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 
  SCI2C2 = 0b00000100;  //enable R
  SCI2C2 = 0b00001000;  //enable T


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:32:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181628#M6180</guid>
      <dc:creator>eckhard</dc:creator>
      <dc:date>2020-10-29T09:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Receiving "ack" over SCI</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181629#M6181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Also, if your compiler is CW, then your delay function is never executed. CW will optimize it away. Delay functions like that shouldn't be used in embedded systems anyhow, as they are incredibly hardware &amp;amp; interrupt-intensity dependant. Instead, use the on-chip hardware timers.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Mar 2010 21:48:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181629#M6181</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-03-08T21:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Receiving "ack" over SCI</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181630#M6182</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 do question the basis of the previous statement that "CW will optimize it (the function) away".&amp;nbsp; This has not been my experience when using a similar function, and which also appears to have been utilised as a "quick and dirty" delay function in some of the examples given in Fabio Pereira's "HCS08 Unleashed".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would also perceive that there is a difference between a "delay function" and a "timing function".&amp;nbsp; The delay function is used by the OP to create a minimum delay period, with the upper limit being non-critical.&amp;nbsp; True, the delay will be interrupt intensity dependent, but so will be the execution of the remainder of the code in which the delay function is used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I might question the delay calibration implied within the&amp;nbsp;code.&amp;nbsp; A delay value of 100 us per loop seems rather a lot for this simple function, assuming a reasonably fast bus clock is used.&amp;nbsp; The delay&amp;nbsp;calibration might bear checking out, using full chip simulation, to ensure that the delay generated is sufficient.&amp;nbsp; With potentially long delay periods generated, COP timer reset will need to be implemented within the delay loop.&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>Tue, 09 Mar 2010 01:29:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181630#M6182</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-03-09T01:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Receiving "ack" over SCI</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181631#M6183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="lia-message-author-username"&gt;&lt;SPAN class="UserName lia-user-name"&gt;eckhard - thanks for pointing that out the control register mistake, however the configuration was correct in a previous version of the code, so that's not the problem unfortunately.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-message-author-username"&gt;&lt;SPAN class="UserName lia-user-name"&gt;I added the pull up resistors, but they did not seem to fix the random output problem, even stranger, while my micro Tx pin is always high, the Rx pin is now always low...and I'm sure it was not like this even before adding the pull-ups.&lt;/SPAN&gt;&lt;BR /&gt;When connected to a compatible USB-serial interface (with sucessful communication i.e. proper operation), the Tx and Rx are pulled high. Anyway this is a hardware issue, and probably not for this forum section.&lt;/DIV&gt;&lt;DIV class="lia-message-author-username"&gt;The delay function implemented was taken from Fabio Pereira's book, I know there are better ways of creating a delay, but I was just trying something basic. I will see if I check my delays are in the range I want with full chip simulation.&lt;/DIV&gt;&lt;DIV class="lia-message-author-username"&gt;Regards,&lt;/DIV&gt;&lt;DIV class="lia-message-author-username"&gt;Iain&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Mar 2010 05:26:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181631#M6183</guid>
      <dc:creator>Iain</dc:creator>
      <dc:date>2010-03-09T05:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Receiving "ack" over SCI</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181632#M6184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Depending on how you set up your optimizer, I bet you will get the code to behave differently. It is certainly completely non-portable. Just a simple thing such as whether you use "long", "int", "short" or "char" as the counter variable, will make tremendous differences in delay time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the very least you should make the counter variable volatile.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whenever someone comes up with delays like this, I always ask them why they don't use hardware timers instead. The only answer to that question seems to be "I'm lazy and I don't know how timers work in the CPU I'm using". &amp;nbsp;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Mar 2010 16:37:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181632#M6184</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-03-10T16:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Receiving "ack" over SCI</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181633#M6185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The Tx pin is driven high from the SCI, it is an output so you shouldn't need pull resistors on that one. The Rx pin will be held at a certain level by external circuitry. Perhaps you have some sort of hardware issue with your tranceiver circuit?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Mar 2010 16:43:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Receiving-quot-ack-quot-over-SCI/m-p/181633#M6185</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-03-10T16:43:17Z</dc:date>
    </item>
  </channel>
</rss>

