<?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: [S08SH] problem with data direction</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170514#M11385</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;+1 to what Mac said.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was only half way through your post, when I tought of the same thing: The 25Hz routine is using read/modify/write, and it is changing the 0 on SDA to a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to write a zero to the SDA data bit EVERY TIME you set the bit to output.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 18 Dec 2010 04:06:16 GMT</pubDate>
    <dc:creator>rocco</dc:creator>
    <dc:date>2010-12-18T04:06:16Z</dc:date>
    <item>
      <title>[S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170511#M11382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm driving a open collector device (I2C memory) using self made driver. I use PTB2 and PTB3 as SDA and SCL. On another pin of the same port (PTB4) I have a LED which blink at low frequency (25z). To drive SDA I switch the associated data direction bit (PTBDD3) to input, with external pullup resistor, if I want an high level, to output with value 0 if I want a low level.&lt;/P&gt;&lt;P&gt;In this situation, if I run the firmware it give to me write errors after a random time (2s, 9s, ...). I have the same problem if I remove physically the led but I keep unaltered the led driver (square wave at 25Hz).&lt;/P&gt;&lt;P&gt;I solve the problem if I remove the square wave on the led pin and/or change the port, from PTB to PTA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;This is a very annoying problem. Could anyone help me?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thank you in advance&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Dec 2010 18:31:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170511#M11382</guid>
      <dc:creator>utall</dc:creator>
      <dc:date>2010-12-17T18:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170512#M11383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might help if you posted the LED blinking and I2C Send routines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This sounds like a concurrency problem.&amp;nbsp; If these two actions might happen concurrently (at random points in time), you need to make sure the port updates are atomic (ie. with interrupts disabled.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Dec 2010 19:15:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170512#M11383</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2010-12-17T19:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170513#M11384</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;The most likely cause of this problem is that, for the port pin you are using as SDA, you are not writing a low to the output bit &lt;U&gt;after&lt;/U&gt; you have changed the direction from input to output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the LED pin, or any other&amp;nbsp; output pin on the same port, should have its state altered using a read-modify-write instruction (e.g. BSET or BCLR),&amp;nbsp; the SDA bit within the output register will not remain low if the data direction is currently input.&amp;nbsp; This is because an input pin with high state (due to pullup) will read as high, and this state will then&amp;nbsp;be written back to the port output register.&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>Sat, 18 Dec 2010 02:07:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170513#M11384</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-12-18T02:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170514#M11385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;+1 to what Mac said.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was only half way through your post, when I tought of the same thing: The 25Hz routine is using read/modify/write, and it is changing the 0 on SDA to a 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to write a zero to the SDA data bit EVERY TIME you set the bit to output.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Dec 2010 04:06:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170514#M11385</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2010-12-18T04:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170515#M11386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Thanks for replies.&lt;/P&gt;&lt;P&gt;The firmware as only a MTIM interrupt (80us) and the led routine run into this interrupt. All what it does is to switch a fixed output pin from 0 to 1 and viceversa. The IIC routine run in main and it's not atomic so the interrupt never stops. Ok, this could be a problem, but why when I change the port this problem disappear? Can I set the output value BEFORE changing the direction to "output"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Dec 2010 15:36:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170515#M11386</guid>
      <dc:creator>utall</dc:creator>
      <dc:date>2010-12-20T15:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170516#M11387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;rocco wrote:&lt;BR /&gt;&lt;P&gt;You need to write a zero to the SDA data bit EVERY TIME you set the bit to output.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define SetData&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bitI2C_SDA = kINPUT&lt;BR /&gt;#define ClrData&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ioI2C_SDA = 0; bitI2C_SDA = kOUTPUT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define ioI2C_SDA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTBD_PTBD3&lt;BR /&gt;#define bitI2C_SDA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTBDD_PTBDD3&lt;BR /&gt;#define kINPUT&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; 0&lt;BR /&gt;#define kOUTPUT&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; 1&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;:-)I always use these defines to drive the port...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Dec 2010 15:39:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170516#M11387</guid>
      <dc:creator>utall</dc:creator>
      <dc:date>2010-12-20T15:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170517#M11388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In general, the recommended sequence to alter a pin state is to first change the data, and then the direction.&amp;nbsp; This avoids possible contention (however short that may be), and possible "spurious" edges.&amp;nbsp;&amp;nbsp; However, in the presence of ISR which alter the same port (even if different pins on that port) these two actions must occur as one (atomically).&amp;nbsp; Not the whole IIC routine has to be atomic, just the pin change operation.&amp;nbsp; This is because if the ISR that toggles the LED, happens right after the data write (and before the direction change), the data will be changed to the current input of the pin (since you have not yet made it an output).&amp;nbsp; In assembly, it would be something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;sei&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;bclr IIC_PIN,IIC_PORT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;EM&gt;(interrupt could occur right here, if interrupts are not masked with SEI)&lt;/EM&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;bset IIC_PIN,IIC_PORT+DDR&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;cli&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(The ISR is already atomic, unless you re-enable interrupts within it for some reason.).&amp;nbsp; The LED toggle should look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;LDA LED_PORT&amp;nbsp;&amp;nbsp; ;if previous code not atomic, the current input IIC state may be used&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;EOR #LED_PIN_MASK&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;STA LED_PORT&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Dec 2010 18:20:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170517#M11388</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2010-12-20T18:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170518#M11389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Ok I will try to apply your suggestions, but my question is: why if I change the led output port all problems disappear? If there is a firmware problem this modification shouldn't interfere. It can be a PCB problem, or a micro peculiarity that I did not consider. I often encounter this problem and I'd like to know how to solve it. When I programmed Microchip I never had this problem... many others, but not this.&lt;/P&gt;&lt;P&gt;Thanks again for your patience&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Dec 2010 21:31:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170518#M11389</guid>
      <dc:creator>utall</dc:creator>
      <dc:date>2010-12-20T21:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170519#M11390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Apparently, you haven't understood what the real problem is, or you wouldn't be asking this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The processor only deals with complete bytes at all times.&amp;nbsp; It can NOT change single bits (such as single pins).&amp;nbsp; Even with the BSET/BCLR instructions which are meant to change single bits (from a logical point of view), they do this by reading in a whole byte (the whole port), changing the specific bit (pin) using OR (for BSET) or AND (with inverted mask for BCLR), and finally writing the whole byte back out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you use different ports, then the two read-modify-write operations cannot possibly affect one another because they belong in different bytes.&amp;nbsp; The problem is only evident&amp;nbsp; when dealing with the same port (or same byte).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, to be on the safe side, and given that over an application's life span a lot of changes may occur to the firmware, and sometimes new (formerly unused) pins become used in different ways than originally planned, it would be good to follow this method of updating pins regardless of how the current code affects the ports.&amp;nbsp; This will save you from future troubles debugging "ghosts" that appeared out of nowhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Dec 2010 21:45:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170519#M11390</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2010-12-20T21:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170520#M11391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Andrea,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is your ClrData macro!&amp;nbsp; Making some substitutions to clarify the operation, the macro becomes as follows -&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define ClrData&amp;nbsp;&amp;nbsp;PTBD_PTBD3 = 0;&amp;nbsp;PTBDD_PTBDD3 = 1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the MTIM interrupt should occur after the first part of the macro has completed, but prior to the second part, the PTBD3 state will revert to a 1, for the reason previously mentioned.&amp;nbsp; This problem should be eliminated with either of the following variations -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define ClrData&amp;nbsp;&amp;nbsp;__asm sei; PTBD_PTBD3 = 0;&amp;nbsp;PTBDD_PTBDD3 = 1; __asm cli&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;This is equivalent to Tony P's xuggestion, and will prevent the interrupt from occurring at the critical point.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define ClrData&amp;nbsp;&amp;nbsp;PTBDD_PTBDD3 = 1; PTBD_PTBD3 = 0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;This&amp;nbsp;may actively drive the pin high for a few cycles before the port pin is set low, but may be acceptable for the IIC case, provided the slave device is not driving low at this point.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should also handle the SCL pin in a similar manner for the clock low state.&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, 21 Dec 2010 02:07:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170520#M11391</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-12-21T02:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: [S08SH] problem with data direction</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170521#M11392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, I understand. Sorry but I misunderstand previous posts. Now it's more clear. I'll try and I post the results if this can help other users.&lt;/P&gt;&lt;P&gt;Best regards and thank you again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Dec 2010 15:50:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/S08SH-problem-with-data-direction/m-p/170521#M11392</guid>
      <dc:creator>utall</dc:creator>
      <dc:date>2010-12-21T15:50:32Z</dc:date>
    </item>
  </channel>
</rss>

