<?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: How to assign Modbus setting into MC9RS08KB4 chip ?</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530897#M22046</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like your first problem is that you're making assignments outside of a function - the "ch[16] = 0x0a" won't work.&amp;nbsp; That would compile to actual code and would have to be inside a function.&amp;nbsp; You could initialize the entire array where it's declared:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unsigned char ch[4] = {1, 2, 3, 4};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But you can't make assignments there.&amp;nbsp; As for &amp;lt;iostream&amp;gt; and the namespace, those are C++ features.&amp;nbsp; You're using a very low-end MCU with 4 KB of flash and 126 bytes of RAM.&amp;nbsp; C++ really isn't an option at that level.&amp;nbsp; In pure C you can certainly implement a Modbus sender in a device like that - my own implementation was 1234 bytes of flash and 229 of RAM + 64 bytes stack, and most of that was for buffering ADC samples, but if you don't have much embedded C experience you're not going to have a lot of margin on a device like that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your other thread you mentioned that you were trying to implement Modbus ASCII.&amp;nbsp; The fact that you've got a CRC 16 function here makes me think you're implementing Modbus RTU, since Modbus ASCII uses just a simple arithmetic sum, but your attempt to initialize ch[16] with a linefeed character looks like a Modbus ASCII message.&amp;nbsp; Which exactly are you trying to implement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, if it's Modbus RTU you're going for, are you sure that's the right CRC 16 calculation?&amp;nbsp; I can't see the whole thing but that doesn't look like the right polynomial.&amp;nbsp; Is that maybe CRC-16-CCITT?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Jul 2016 17:50:12 GMT</pubDate>
    <dc:creator>scottm</dc:creator>
    <dc:date>2016-07-05T17:50:12Z</dc:date>
    <item>
      <title>How to assign Modbus setting into MC9RS08KB4 chip ?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530894#M22043</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do anyone has any experience or sample coding for assigning Modbus setting into MC9RS08KB4 chip ? Currently, i am working on a project for this. My chip is able to transmit and receive signals via RS485 but the MOXa gateway is unable to recognize the device address to communication purposes.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone can help one this ?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your reply is highly appreciated. &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Jul 2016 09:33:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530894#M22043</guid>
      <dc:creator>joonsinchu</dc:creator>
      <dc:date>2016-07-01T09:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Modbus setting into MC9RS08KB4 chip ?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530895#M22044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you looked at the RS485 bus with a logic analyzer to see what's going on?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only time I've implemented Modbus-RTU on an 8-bit micro was for a hobby project a few years back.&amp;nbsp; I instrumented my travel trailer's holding tanks and power distribution system with sensors and used Modbus-RTU for the bus.&amp;nbsp; I remember it being fairly straightforward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Without a little more information or a capture of what's going on on the bus, all I can do is speculate.&amp;nbsp; Make sure your CRC calculation is correct.&amp;nbsp; If you can post an example of a frame that your Modbus code is sending I could see if it at least looks valid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 Jul 2016 03:59:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530895#M22044</guid>
      <dc:creator>scottm</dc:creator>
      <dc:date>2016-07-03T03:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Modbus setting into MC9RS08KB4 chip ?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530896#M22045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Scott,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/33005iE884AAEB4A049EA2/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any idea why there is an error for this ? i checked my overall code all my bracket is correct, but this error is keep poping out. &lt;/P&gt;&lt;P&gt;and can i add in the header file of #include &amp;lt;iostream&amp;gt; and using namespace std; into the code ? or CW has it owns files for these ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you. Hope to hear from you soon. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2016 04:09:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530896#M22045</guid>
      <dc:creator>joonsinchu</dc:creator>
      <dc:date>2016-07-05T04:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Modbus setting into MC9RS08KB4 chip ?</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530897#M22046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like your first problem is that you're making assignments outside of a function - the "ch[16] = 0x0a" won't work.&amp;nbsp; That would compile to actual code and would have to be inside a function.&amp;nbsp; You could initialize the entire array where it's declared:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unsigned char ch[4] = {1, 2, 3, 4};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But you can't make assignments there.&amp;nbsp; As for &amp;lt;iostream&amp;gt; and the namespace, those are C++ features.&amp;nbsp; You're using a very low-end MCU with 4 KB of flash and 126 bytes of RAM.&amp;nbsp; C++ really isn't an option at that level.&amp;nbsp; In pure C you can certainly implement a Modbus sender in a device like that - my own implementation was 1234 bytes of flash and 229 of RAM + 64 bytes stack, and most of that was for buffering ADC samples, but if you don't have much embedded C experience you're not going to have a lot of margin on a device like that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your other thread you mentioned that you were trying to implement Modbus ASCII.&amp;nbsp; The fact that you've got a CRC 16 function here makes me think you're implementing Modbus RTU, since Modbus ASCII uses just a simple arithmetic sum, but your attempt to initialize ch[16] with a linefeed character looks like a Modbus ASCII message.&amp;nbsp; Which exactly are you trying to implement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, if it's Modbus RTU you're going for, are you sure that's the right CRC 16 calculation?&amp;nbsp; I can't see the whole thing but that doesn't look like the right polynomial.&amp;nbsp; Is that maybe CRC-16-CCITT?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2016 17:50:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/How-to-assign-Modbus-setting-into-MC9RS08KB4-chip/m-p/530897#M22046</guid>
      <dc:creator>scottm</dc:creator>
      <dc:date>2016-07-05T17:50:12Z</dc:date>
    </item>
  </channel>
</rss>

