This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cant write port output with str912 demo board

Hi, I am new to ARM (usually work with 8051), and am working on a little RS232 GPIO board. Project is a serial input on port 3 (uart 1) takes 3 bytes in and writes the values to ports 0-2, and 4-9.

The program seems to be working fine on ports 4,7,8 and 9. On the other ports the direction registers seem to be stuck as inputs. in my main routine I have lines to configure all the ports as outputs:

SCU->GPIOOUT[0] = 0x5555; GPIO0->DDR = 0xFF; "" "" SCU->GPIOOUT[9] = 0x5555; GPIO9->DDR = 0xFF;

When I stop the program and look at the output registers the GPIO_DIR[x] registers stay at 0x00 on ports 0,1,2,3 5 and 6.

I tried single step through my startup configuration
code and the direction registers never change. Is there something I am missing for using these
ports as outputs?

Thanks,
Andrew

Parents
  • Here is my source code:

    /*----------------------------------------------------------------------------
     *      Name:    GPIO
     *      Purpose: Serial - GPIO
     *
     *
     *---------------------------------------------------------------------------*/
    
    #include <stdio.h>                       /* standard I/O .h-file              */
    #include <ctype.h>                       /* character functions               */
    #include <91x_lib.h>                                       /* STR91x definitions                */
    
    #include "measure.h"                     /* global project definition file    */
    
    
    /******************************************************************************/
    /*          Default Interrupt Service Routine (necessary for STR91x)          */
    /******************************************************************************/
    __irq void defInterrupt (void) {
      ;                                            /* Do nothing                  */
    }
    /******************************************************************************/
    /*                Timer Counter 3 interrupt service function                  */
    /*                executes each 1ms @ 25 MHz Crystal Clock                    */
    /******************************************************************************/
    __irq void tc3 (void) {
    
      TIM3->SR   &= ~TIM_FLAG_OC2;                 /* Clear Timer Overflow flag   */
      TIM3->CNTR  = 0x0000;                        /* Setup TIM3 counter register */
    
      VIC0->VAR = 0;                               /* Acknowledge Interrupt       */
      VIC1->VAR = 0;
    }
    
    
    
    /******************************************************************************/
    /***************************      MAIN PROGRAM      ***************************/
    /******************************************************************************/
    int main (void)  {                             /* main entry for program      */
      char cmdbuf [15];                            /* command input buffer        */
      int i, Int_1, Int_2, Int_3, args;             /* storage for arguments                */
    
    
    
    
       GPIO0->DDR      = 0xFF;                 /* P0.0..7 Outputs (LED Data)       */
       GPIO1->DDR      = 0xFF;                 /* P1.0..7 Outputs (LED Data)       */
       GPIO2->DDR      = 0xFF;                 /* P2.0..7 Outputs (LED Data)       */
       GPIO4->DDR      = 0xFF;                 /* P4.0..7 Outputs (LED Data)       */
       GPIO5->DDR      = 0xFF;                 /* P5.0..7 Outputs (LED Data)       */
       GPIO6->DDR      = 0xFF;                 /* P6.0..7 Outputs (LED Data)       */
       GPIO7->DDR      = 0xFF;                 /* P7.0..7 Outputs (LED Data)       */
       GPIO8->DDR      = 0xFF;                 /* P8.0..7 Outputs (LED Data)       */
       GPIO9->DDR      = 0xFF;                 /* P9.0..7 Outputs (LED Data)       */
       SCU->GPIOOUT[0] = 0x5555;               /* P0.0..7 output - mode 1          */
       SCU->GPIOOUT[1] = 0x5555;               /* P1.0..7 output - mode 1          */
       SCU->GPIOOUT[2] = 0x5555;               /* P2.0..7 output - mode 1          */
       SCU->GPIOOUT[4] = 0x5555;               /* P4.0..7 output - mode 1          */
       SCU->GPIOOUT[5] = 0x5555;               /* P5.0..7 output - mode 1          */
       SCU->GPIOOUT[6] = 0x5555;               /* P6.0..7 output - mode 1          */
       SCU->GPIOOUT[7] = 0x5555;               /* P7.0..7 output - mode 1          */
    
    
    
    
    
      /* setup the default interrupt */
      VIC0->DVAR = (unsigned int)defInterrupt;
      VIC1->DVAR = (unsigned int)defInterrupt;
    
      /* setup the timer counter 3 interrupt, Vector Slot 7 */
      VIC0->VAiR[7]  = (unsigned int)tc3;     /* Setup TIM3 IRQ Hndl addr         */
      VIC0->VCiR[7]  = 0x20 | 7;              /* enable vector slot  7            */
      VIC0->INTER   |= (1<<7);                /* Enable TIM3 interrupt            */
    
      /* Timer 3 Configuration (TIM3) */
      #define _CLOCK       48000000
      #define _TICK            1000           /* 1000  (1ms)                      */
    
      TIM3->OC2R = (_CLOCK / _TICK / 100) - 5; /* -5 because cnt starts at 0xFFFC */
      TIM3->CR2  =  TIM_FLAG_OC2 | (100 - 1);      /* prescale 100                */
      TIM3->CR1  =  0x8000;                        /* Enable timer                */
    
      /*--------------------------------------------------------------------------*/
      init_serial ();                              /* initialite serial interface */
    
    
      while (1)  {                                 /* loop forever                */
        printf ("\nCommand: ");
        getline (&cmdbuf[0], sizeof (cmdbuf));     /* input command line          */
    
        for (i = 0; cmdbuf[i] != 0; i++)  {        /* convert to upper characters */
          cmdbuf[i] = toupper(cmdbuf[i]);
        }
    
        for (i = 0; cmdbuf[i] == ' '; i++);        /* skip blanks                 */
    
            args = sscanf (cmdbuf, "%d.%d.%d",
                     &Int_1,                   /* split string to 3 integers   */
                     &Int_2,
                     &Int_3);
    
    
         switch (Int_1)  {                      /* proceed to command function */
    
    
          case 1:                                /* write to port 0 & port 1 (noise attenuator) */
              GPIO0->DR[0xFF*4] = Int_2;
              GPIO1->DR[0xFF*4] = Int_3;
          break;
    
          case 2:                                /* write to port 2 & port 4 (Carrier attenuator)  */
              GPIO2->DR[0xFF*4] = Int_2;
              GPIO4->DR[0xFF*4] = Int_3;
          break;
    
          case 5:                               /* write to port 5 (Switch control)  */
          GPIO5->DR[0xFF*4] = Int_2;
          break;
    
              case 6:                               /* write to port 6 (Switch control)  */
          GPIO6->DR[0xFF*4] = Int_2;
          break;
    
          case 7:                               /* write to port 7 (Switch control)  */
          GPIO7->DR[0xFF*4] = Int_2;
          break;
    
              case 8:                               /* write to port 8 (Switch control)  */
          GPIO8->DR[0xFF*4] = Int_2;
          break;
    
              case 9:                               /* write to port 9 (Switch control)  */
          GPIO9->DR[0xFF*4] = Int_2;
          break;
    
          default:                                 /* Error Handling  - do nothing   */
          break;
        }
      }
    }
    

Reply
  • Here is my source code:

    /*----------------------------------------------------------------------------
     *      Name:    GPIO
     *      Purpose: Serial - GPIO
     *
     *
     *---------------------------------------------------------------------------*/
    
    #include <stdio.h>                       /* standard I/O .h-file              */
    #include <ctype.h>                       /* character functions               */
    #include <91x_lib.h>                                       /* STR91x definitions                */
    
    #include "measure.h"                     /* global project definition file    */
    
    
    /******************************************************************************/
    /*          Default Interrupt Service Routine (necessary for STR91x)          */
    /******************************************************************************/
    __irq void defInterrupt (void) {
      ;                                            /* Do nothing                  */
    }
    /******************************************************************************/
    /*                Timer Counter 3 interrupt service function                  */
    /*                executes each 1ms @ 25 MHz Crystal Clock                    */
    /******************************************************************************/
    __irq void tc3 (void) {
    
      TIM3->SR   &= ~TIM_FLAG_OC2;                 /* Clear Timer Overflow flag   */
      TIM3->CNTR  = 0x0000;                        /* Setup TIM3 counter register */
    
      VIC0->VAR = 0;                               /* Acknowledge Interrupt       */
      VIC1->VAR = 0;
    }
    
    
    
    /******************************************************************************/
    /***************************      MAIN PROGRAM      ***************************/
    /******************************************************************************/
    int main (void)  {                             /* main entry for program      */
      char cmdbuf [15];                            /* command input buffer        */
      int i, Int_1, Int_2, Int_3, args;             /* storage for arguments                */
    
    
    
    
       GPIO0->DDR      = 0xFF;                 /* P0.0..7 Outputs (LED Data)       */
       GPIO1->DDR      = 0xFF;                 /* P1.0..7 Outputs (LED Data)       */
       GPIO2->DDR      = 0xFF;                 /* P2.0..7 Outputs (LED Data)       */
       GPIO4->DDR      = 0xFF;                 /* P4.0..7 Outputs (LED Data)       */
       GPIO5->DDR      = 0xFF;                 /* P5.0..7 Outputs (LED Data)       */
       GPIO6->DDR      = 0xFF;                 /* P6.0..7 Outputs (LED Data)       */
       GPIO7->DDR      = 0xFF;                 /* P7.0..7 Outputs (LED Data)       */
       GPIO8->DDR      = 0xFF;                 /* P8.0..7 Outputs (LED Data)       */
       GPIO9->DDR      = 0xFF;                 /* P9.0..7 Outputs (LED Data)       */
       SCU->GPIOOUT[0] = 0x5555;               /* P0.0..7 output - mode 1          */
       SCU->GPIOOUT[1] = 0x5555;               /* P1.0..7 output - mode 1          */
       SCU->GPIOOUT[2] = 0x5555;               /* P2.0..7 output - mode 1          */
       SCU->GPIOOUT[4] = 0x5555;               /* P4.0..7 output - mode 1          */
       SCU->GPIOOUT[5] = 0x5555;               /* P5.0..7 output - mode 1          */
       SCU->GPIOOUT[6] = 0x5555;               /* P6.0..7 output - mode 1          */
       SCU->GPIOOUT[7] = 0x5555;               /* P7.0..7 output - mode 1          */
    
    
    
    
    
      /* setup the default interrupt */
      VIC0->DVAR = (unsigned int)defInterrupt;
      VIC1->DVAR = (unsigned int)defInterrupt;
    
      /* setup the timer counter 3 interrupt, Vector Slot 7 */
      VIC0->VAiR[7]  = (unsigned int)tc3;     /* Setup TIM3 IRQ Hndl addr         */
      VIC0->VCiR[7]  = 0x20 | 7;              /* enable vector slot  7            */
      VIC0->INTER   |= (1<<7);                /* Enable TIM3 interrupt            */
    
      /* Timer 3 Configuration (TIM3) */
      #define _CLOCK       48000000
      #define _TICK            1000           /* 1000  (1ms)                      */
    
      TIM3->OC2R = (_CLOCK / _TICK / 100) - 5; /* -5 because cnt starts at 0xFFFC */
      TIM3->CR2  =  TIM_FLAG_OC2 | (100 - 1);      /* prescale 100                */
      TIM3->CR1  =  0x8000;                        /* Enable timer                */
    
      /*--------------------------------------------------------------------------*/
      init_serial ();                              /* initialite serial interface */
    
    
      while (1)  {                                 /* loop forever                */
        printf ("\nCommand: ");
        getline (&cmdbuf[0], sizeof (cmdbuf));     /* input command line          */
    
        for (i = 0; cmdbuf[i] != 0; i++)  {        /* convert to upper characters */
          cmdbuf[i] = toupper(cmdbuf[i]);
        }
    
        for (i = 0; cmdbuf[i] == ' '; i++);        /* skip blanks                 */
    
            args = sscanf (cmdbuf, "%d.%d.%d",
                     &Int_1,                   /* split string to 3 integers   */
                     &Int_2,
                     &Int_3);
    
    
         switch (Int_1)  {                      /* proceed to command function */
    
    
          case 1:                                /* write to port 0 & port 1 (noise attenuator) */
              GPIO0->DR[0xFF*4] = Int_2;
              GPIO1->DR[0xFF*4] = Int_3;
          break;
    
          case 2:                                /* write to port 2 & port 4 (Carrier attenuator)  */
              GPIO2->DR[0xFF*4] = Int_2;
              GPIO4->DR[0xFF*4] = Int_3;
          break;
    
          case 5:                               /* write to port 5 (Switch control)  */
          GPIO5->DR[0xFF*4] = Int_2;
          break;
    
              case 6:                               /* write to port 6 (Switch control)  */
          GPIO6->DR[0xFF*4] = Int_2;
          break;
    
          case 7:                               /* write to port 7 (Switch control)  */
          GPIO7->DR[0xFF*4] = Int_2;
          break;
    
              case 8:                               /* write to port 8 (Switch control)  */
          GPIO8->DR[0xFF*4] = Int_2;
          break;
    
              case 9:                               /* write to port 9 (Switch control)  */
          GPIO9->DR[0xFF*4] = Int_2;
          break;
    
          default:                                 /* Error Handling  - do nothing   */
          break;
        }
      }
    }
    

Children
  • Just an update:

    I made sure the GPIO ports were getting clocked in the startup file:

    CLOCK_SETUP     EQU     1
    SCU_CLKCNTR_Val EQU     0x00020000
    SCU_PLLCONF_Val EQU     0x000BC019
    SCU_PCGR0_Val   EQU     0x000004FB
    SCU_PCGR1_Val   EQU     0x00FFC00B
    

    the PCGR1 register is set to 0x00FFC00B, so all the IO ports and the uart0 should be getting clocked. Im really stuck here as to why its not working unless there is some other register I am missing. Like I said I am new to ARM, so I would appreciate any input.

    Thanks,
    Andrew