<?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: 9S08SG16 problem with trim value</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/9S08SG16-problem-with-trim-value/m-p/157745#M9203</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear ttom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found that the operation of the clock trimming in the various HCS08 devices rather confusing too!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some comments:&lt;/P&gt;&lt;P&gt;===========================&lt;/P&gt;&lt;P&gt;For ICSTRM &amp;amp; FTRIM bit in ICSSC&lt;/P&gt;&lt;P&gt;===========================&lt;/P&gt;&lt;P&gt;For SOME devices (e.g. -SV16 -SE8) these locations are loaded from a hidden Flash location upon power-on-reset.&amp;nbsp; The location contains a factory-trimmed value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For SOME devices (e.g. -SG16) these locations are reset to 0x80 &amp;amp; 0 upon power-on-reset.&amp;nbsp; It is up to your program to copy the values from regular flash locations (NVTRIM:NVFTRIM).&amp;nbsp; This is usually done in the reset code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For SOME devices (e.g. -LG32) these locations are automatically loaded from the regular flash locations (NVTRIM:NVFTRIM) upon power-on-reset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To further confuse - Some devices have the&amp;nbsp; (NVTRIM:NVFTRIM) locations pre-programmed with factory trimmed values.&amp;nbsp; Others are programmed to zero (according to the manual!).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note also that the value in ICSTRM &amp;amp; FTRIM bit in ICSSC are NOT affected by normal resets - only POR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally - If operating in debug mode using a BDM then the above automatic initialisation from Flash locations doesn't happen and they are reset to default values of $80/0 only (I think!).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The outcome - very Carefully read the manual for the actual chip you are using to determine what happens.&amp;nbsp; The app notes may not apply directly to your chip!&amp;nbsp; The only safe alternative that works in all three cases is to assume the second case, do your own trimming &amp;amp; copying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above is further confused by whether the programmer you are using will:&lt;/P&gt;&lt;P&gt;Determine trim values.&lt;/P&gt;&lt;P&gt;Preserve the factory trim values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Comments on your specific questions:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;So I don't understand 3 things:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Why is the trim value == 0 (in flash) on my hardware with the S08SG16?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This sound like your BDM is not trimming the chip correctly OR&lt;/P&gt;&lt;P&gt;The program you are loading has a value for the trim location which is being used instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;And why is this value not transferred to the working register ICSTRM?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;See above - The transfer is not automatic for the -SG32.&amp;nbsp; In any case, the transfer wouldn't happen when using a BDM anyway.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Why is the trim value on the demo board (with 9S08SG32) in flash different to the value in the working register? (0xb4 and 0xb3).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Differ by 1 - No idea!&amp;nbsp; I don't even know why its getting initialised at all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope the above helps rather than confuses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bye&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example code to manually copy the trim values from Flash to clock registers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
// These locations _may not_ be copied automatically
// The volatile is needed to stop optimisation.
// The initialisation is needed to prevent the automatic creation of
// default variables with zero values.
volatile const byte NVFTRIM_INIT  @0x0000FFAE = 0xFF;
volatile const byte NVICSTRM_INIT @0x0000FFAF = 0xFF;

// This location is automatically copied to registers
// Alter to modify the security
const byte NVOPT_INIT    @0x0000FFBF = NVOPT_SEC01_MASK;

void init(void) {

   SOPT1 = SOPT1_BKGDPE_MASK; // Disable COP, enable BKGD pin
  
   if (NVFTRIM_INIT != 0xFF) {
     // Only done if trim locations have been programmed
     ICSSC  = NVFTRIM_INIT;
     ICSTRM = NVICSTRM_INIT; 

     // FLL Engaged Internal, BDIV=/1,
     ICSC1  = ICSC1_IREFS_MASK;
     ICSC2  = 0x00;//|ICSC2_BDIV0_MASK;
   }

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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>Thu, 29 Oct 2020 09:02:36 GMT</pubDate>
    <dc:creator>pgo</dc:creator>
    <dc:date>2020-10-29T09:02:36Z</dc:date>
    <item>
      <title>9S08SG16 problem with trim value</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/9S08SG16-problem-with-trim-value/m-p/157744#M9202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I use the 9S08SG16 and want to do serial communication with 19200 Baud and use the internal clock reference. I use the ICS module with locked FLL and reading the factory set trim value and so I should get a accuracy of about 1%.&lt;/P&gt;&lt;P&gt;As far as I understand the appnotes, the value of NVOPT is automatically read at startup from flash and stored in the ICSTRM working register.&lt;/P&gt;&lt;P&gt;In my hardware, I see a difference in the baud rate (having about 21000 Baud instead of 19200). I have already checked the register values for initializing the SCI - interface.&lt;/P&gt;&lt;P&gt;But now, I found in the memory view at the location 0xffaf (NVTRIM), that the trim value is equal to zero. But the value ICSTRM register is 0x80 (default value).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have checked in parallel with my demo board for 9S08SG32 (On the demo board I have a trim value of 0xB4).&lt;/P&gt;&lt;P&gt;I have the following differences between the demo board and my hardware (I have two simple projects with the same uart - module, because of two different controllers on demo board and my hardware):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On startup (when loading the flash with the hiwave - window), the process runs without any break on the demo board.&lt;/P&gt;&lt;P&gt;But on my hardware, I get a message "Initializing - error measureing trim values, device is secured. Erasing...", then comes up a Power Cycle Dialog, and then the flash is loaded to the device.&lt;/P&gt;&lt;P&gt;I see the value at 0xFFBF (NVOPT) = 0x7e, which means that device is unsecured (until next reset?) and a trim value of 0x00 at adress 0xFFAF (NVTRIM).&amp;nbsp; In the register ICSTRM (working register of ICS) there is the value 0x80.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the demo board, I have a value of 0x7E for the NVOPT (0xFFBF) and a trim value of 0xB4 (at 0xffaf). In the ICSTRM register is the value 0xb3. I think, this is ok.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I don't understand 3 things:&lt;/P&gt;&lt;P&gt;Why is the trim value == 0 (in flash) on my hardware with the S08SG16?&lt;/P&gt;&lt;P&gt;And why is this value not transferred to the working register ICSTRM?&lt;/P&gt;&lt;P&gt;Why is the trim value on the demo board (with 9S08SG32) in flash different to the value in the working register? (0xb4 and 0xb3).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May be silly qustions, sorry.&lt;/P&gt;&lt;P&gt;But I didn't find (or didn't understand?) answers in the appnotes or the other documentation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Nov 2009 18:41:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/9S08SG16-problem-with-trim-value/m-p/157744#M9202</guid>
      <dc:creator>ttom</dc:creator>
      <dc:date>2009-11-27T18:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: 9S08SG16 problem with trim value</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/9S08SG16-problem-with-trim-value/m-p/157745#M9203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear ttom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found that the operation of the clock trimming in the various HCS08 devices rather confusing too!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some comments:&lt;/P&gt;&lt;P&gt;===========================&lt;/P&gt;&lt;P&gt;For ICSTRM &amp;amp; FTRIM bit in ICSSC&lt;/P&gt;&lt;P&gt;===========================&lt;/P&gt;&lt;P&gt;For SOME devices (e.g. -SV16 -SE8) these locations are loaded from a hidden Flash location upon power-on-reset.&amp;nbsp; The location contains a factory-trimmed value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For SOME devices (e.g. -SG16) these locations are reset to 0x80 &amp;amp; 0 upon power-on-reset.&amp;nbsp; It is up to your program to copy the values from regular flash locations (NVTRIM:NVFTRIM).&amp;nbsp; This is usually done in the reset code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For SOME devices (e.g. -LG32) these locations are automatically loaded from the regular flash locations (NVTRIM:NVFTRIM) upon power-on-reset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To further confuse - Some devices have the&amp;nbsp; (NVTRIM:NVFTRIM) locations pre-programmed with factory trimmed values.&amp;nbsp; Others are programmed to zero (according to the manual!).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note also that the value in ICSTRM &amp;amp; FTRIM bit in ICSSC are NOT affected by normal resets - only POR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally - If operating in debug mode using a BDM then the above automatic initialisation from Flash locations doesn't happen and they are reset to default values of $80/0 only (I think!).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The outcome - very Carefully read the manual for the actual chip you are using to determine what happens.&amp;nbsp; The app notes may not apply directly to your chip!&amp;nbsp; The only safe alternative that works in all three cases is to assume the second case, do your own trimming &amp;amp; copying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above is further confused by whether the programmer you are using will:&lt;/P&gt;&lt;P&gt;Determine trim values.&lt;/P&gt;&lt;P&gt;Preserve the factory trim values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Comments on your specific questions:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;So I don't understand 3 things:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Why is the trim value == 0 (in flash) on my hardware with the S08SG16?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This sound like your BDM is not trimming the chip correctly OR&lt;/P&gt;&lt;P&gt;The program you are loading has a value for the trim location which is being used instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;And why is this value not transferred to the working register ICSTRM?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;See above - The transfer is not automatic for the -SG32.&amp;nbsp; In any case, the transfer wouldn't happen when using a BDM anyway.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Why is the trim value on the demo board (with 9S08SG32) in flash different to the value in the working register? (0xb4 and 0xb3).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Differ by 1 - No idea!&amp;nbsp; I don't even know why its getting initialised at all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope the above helps rather than confuses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bye&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example code to manually copy the trim values from Flash to clock registers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
// These locations _may not_ be copied automatically
// The volatile is needed to stop optimisation.
// The initialisation is needed to prevent the automatic creation of
// default variables with zero values.
volatile const byte NVFTRIM_INIT  @0x0000FFAE = 0xFF;
volatile const byte NVICSTRM_INIT @0x0000FFAF = 0xFF;

// This location is automatically copied to registers
// Alter to modify the security
const byte NVOPT_INIT    @0x0000FFBF = NVOPT_SEC01_MASK;

void init(void) {

   SOPT1 = SOPT1_BKGDPE_MASK; // Disable COP, enable BKGD pin
  
   if (NVFTRIM_INIT != 0xFF) {
     // Only done if trim locations have been programmed
     ICSSC  = NVFTRIM_INIT;
     ICSTRM = NVICSTRM_INIT; 

     // FLL Engaged Internal, BDIV=/1,
     ICSC1  = ICSC1_IREFS_MASK;
     ICSC2  = 0x00;//|ICSC2_BDIV0_MASK;
   }

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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>Thu, 29 Oct 2020 09:02:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/9S08SG16-problem-with-trim-value/m-p/157745#M9203</guid>
      <dc:creator>pgo</dc:creator>
      <dc:date>2020-10-29T09:02:36Z</dc:date>
    </item>
  </channel>
</rss>

