Pular para o conteúdo principal
Knowledgebase
Home
Renesas Brasil - Knowledgebase

Failure to generate a stop condition when using simple I2C in RL78 code generation

Last Updated:05/24/2017

Question:

Generation of a stop condition fails when using simple I2C in RL78 code generation.

Answer:

Observe the following timing requirement when writing 1 to the CKOmn bit in the flow chart for stop condition generation in simple I2C:
Timing that satisfies the SCL low width standard of the I2C bus
See section 12.8.4, Stop condition generation, in RL78/G13 User’s Manual: Hardware, Rev3.30.

Generation of a stop condition might fail when using 32 MHz for the high-speed on-chip oscillator clock.
In this case, add wait processing to generated code by referring to the following:

Example: When channel 0 of serial array unit 0 is set for simple I2C

Add wait processing to function void R_IIC00_StopCondition(void) in file [r_cg_serial.c].

Before modification:

  void R_IIC00_StopCondition(void)
 {
      volatile uint8_t w_count;
      ST0 |= _0001_SAU_CH0_STOP_TRG_ON;           /* disable IIC00 */
      SOE0 &= ~_0001_SAU_CH0_OUTPUT_ENABLE;       /* disable IIC00 output */
      SO0 &= ~_0001_SAU_CH0_DATA_OUTPUT_1;        /* clear IIC00 SDA */
      SO0 |= _0100_SAU_CH0_CLOCK_OUTPUT_1; /* set IIC00 SCL */     

      /* Change the waiting time according to the system */

      for (w_count = 0U; w_count <= IIC00_WAITTIME; w_count++)
   {
          NOP();
      }
      SO0 |= _0001_SAU_CH0_DATA_OUTPUT_1;         /* set IIC00 SDA */
  }

After modification (Part indicated by arrows () is added)

  void R_IIC00_StopCondition(void)
  {
      volatile uint8_t w_count;

      ST0 |= _0001_SAU_CH0_STOP_TRG_ON;           /* disable IIC00 */
      SOE0 &= ~_0001_SAU_CH0_OUTPUT_ENABLE;       /* disable IIC00 output */
      SO0 &= ~_0001_SAU_CH0_DATA_OUTPUT_1;        /* clear IIC00 SDA */
   for (w_count = 0U; w_count < 10; w_count++)
   {
       NOP();
   }

      SO0 |= _0100_SAU_CH0_CLOCK_OUTPUT_1; /* set IIC00 SCL */      

      /* Change the waiting time according to the system */

      for (w_count = 0U; w_count <= IIC00_WAITTIME; w_count++)
   {
          NOP();
      }

      SO0 |= _0001_SAU_CH0_DATA_OUTPUT_1;         /* set IIC00 SDA */
  }

Note that the added part is deleted after code has been generated. You have to add the wait processing each time you execute code generation.

Suitable Products

e² studio
CS+ (formerly CubeSuite+)
Code Generator
Applilet3
AP4