AnsweredAssumed Answered

Inconsistent bit numbering? (MPC5643L)

Question asked by Bjorn Nyman on Nov 17, 2011
Latest reply on Dec 14, 2011 by Spruce Up

Take a look at this short code and tell me what you think.

 

int main(void)
{
  volatile unsigned int i = 0;

  DisableSoftwareWatchdog();
  InitializeModesAndClock();

  init_IO();

  /* Loop forever */
  for (;;)
  {
    /* Toggle LED @ PD4, through GPDO */
  
    SIUL.GPDO52.R ^= 1<<7;   /* Doesn't work. According to datasheet
                                bit 7 in GPDO52 handles this IO, but
                                nothing happens when this code is
                                executed */
    asm(nop);
  
    SIUL.GPDO52.R ^= 1<<0;   /* This works. It seems the bit numbers are
                                written backwards in datasheet (they are
                                numbered from left to right in datasheet
                                but probably supposed to be numbered
                                from right to left(?)) */
    asm(nop);


    /* Toggle LEDs @ PD5-6, through PGPDO */
  
    SIUL.PGPDO3.R ^= 0x0060; /* This should toggle bits 5-6, right?
                                but this line does nothing to PD5-6. */
    asm(nop);
  
    SIUL.PGPDO3.R ^= 0x0600; /* Lets try this. Now PD5-6 are toggled.
                                it seems that this time the bits in
                                the chip is numbered from left to right,
                                just like in the datasheet. But this is
                                backwards from every digital logic
                                convention, right? */
    asm(nop);
  

    /* Delay */
    i = 0x00020000;
    while(--i)
    {
      ;
    }
  }
}

 

Outcomes