Port A : Pin out problem PTA5/IRQ/TCLK/RESET

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Port A : Pin out problem PTA5/IRQ/TCLK/RESET

Jump to solution
886 Views
RChris
Contributor I

Hi,

 

I use the freescale processor MC9S08QG4 (HCS08  family) and i worked on a program that use the pin PTA5/IRQ/TCLK/RESET as an input.

 

In the documentation i found that this pin has several functions and i try to deactivate them but i still unable to used PTA5 as an input.

 

In the function that make the initialisation, i set the Port A and B pins and i set the SCI module. I use the following code to init the chip.

 

void MCU_init(void)
{
    /* ### MC9S08QG8_16 "Cpu" init code ... */
    /*  PE initialization code after reset */

  /* SOPT1: COPE=0,COPT=1,STOPE=0,BKGDPE=0,RSTPE=0 */
  //SOPT1 = 0x50;                                      
  SOPT1 = 0x52; // Debug                                      
  /* SPMSC1: LVDF=0,LVDACK=0,LVDIE=0,LVDRE=1,LVDSE=1,LVDE=1,BGBE=0 */
  SPMSC1 = 0x1C;                                      
  /* SPMSC2: PDF=0,PPDF=0,PPDACK=0,PDC=0,PPDC=0 */
  SPMSC2 = 0x00;                                      
  /* SPMSC3: LVDV=0,LVWV=0 */
  SPMSC3 &= (unsigned char)~0x30;                     
  /*  System clock initialization */
  ICSTRM = *(unsigned char*far)0xFFAF; /* Initialize ICSTRM register from a non volatile memory */
  ICSSC = *(unsigned char*far)0xFFAE;  /* Initialize ICSSC register from a non volatile memory */
  /* ICSC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=0,IREFSTEN=0 */
  ICSC1 = 0x04;                        /* Initialization of the ICS control register 1 */
  /* ICSC2: BDIV=0,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */
  ICSC2 = 0x00;                        /* Initialization of the ICS control register 2 */
  /* Common initialization of the CPU registers */
  /* PTASE: PTASE5=0,PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 */
  PTASE &= (unsigned char)~0x3F;                     
  /* PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0,PTBSE0=0 */
  PTBSE = 0x00;                                      
  /* PTADS: PTADS5=0,PTADS4=0,PTADS3=0,PTADS2=0,PTADS1=0,PTADS0=0 */
  PTADS = 0x00;                                      
  /* PTBDS: PTBDS7=0,PTBDS6=0,PTBDS5=0,PTBDS4=0,PTBDS3=0,PTBDS2=0,PTBDS1=0,PTBDS0=0 */
  PTBDS = 0x00;                                      
  /* ### Init_GPIO init code */
  /* PTADD: PTADD5=0,PTADD4=1,PTADD3=0,PTADD2=0 */
  PTADD = (PTADD & (unsigned char)~0x2C) | (unsigned char)0x10;
  /* ### Init_GPIO init code */
  /* PTBDD: PTBDD5=0,PTBDD4=0,PTBDD3=1,PTBDD2=0 */
  PTBDD = (PTBDD & (unsigned char)~0x34) | (unsigned char)0x08;
 
  PTAD &= ((1<<4) && (1<<5));
  PTBD = 0x00;
 
 
  /* ### Init_SCI init code */
  /* SCIC2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
  SCIC2 = 0x00;                        /* Disable the SCI module */
  (void)(SCIS1 == 0);                  /* Dummy read of the SCIS1 registr to clear flags */
  (void)(SCID == 0);                   /* Dummy read of the SCID registr to clear flags */
  /* SCIBD: SBR12=0,SBR11=0,SBR10=0,SBR9=0,SBR8=0,SBR7=0,SBR6=0,SBR5=1,SBR4=1,SBR3=0,SBR2=1,SBR1=0,SBR0=0 */
  SCIBD = 0x34;                                      
  /* SCIC1: LOOPS=0,SCISWAI=0,Rsrc=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
  SCIC1 = 0x00;                                      
  /* SCIC2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=1,RE=1,RWU=0,SBK=0 */
  SCIC2 = 0x0C;                                      
  /* SCIC3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
  SCIC3 = 0x00;                                      
  /* SCIS2: BRK13=0,RAF=0 */
  SCIS2 = 0x00;                                      

} /*MCU_init*/

 

The main function is also simple, i make a loop and i toggle 2 pin on the Port A, PTA4 and PTA5 and 1 pin on Port B (PTB3).

This program doesn't not work for PTA5 but work well for the other pins (PTA4 and PTB3). I use an

oscilloscope  to confirm that there is nothing on the PTA5 pin.

 

void main(void)
{
  char hello_word[] = "Hello world\n\0";
  short counter = 0;
  unsigned char check = 0;
 
  /* Init Register */
  MCU_init();

  EnableInterrupts; /* enable interrupts */
  /* include your code here */

  for(;:smileywink:
  {
    __RESET_WATCHDOG(); /* feeds the dog */
    
      if(!counter)
      {
        PTAD_PTAD5   = ~PTAD_PTAD5;
        PTBD_PTBD3   = ~PTBD_PTBD3;
        PTAD_PTAD4   = ~PTAD_PTAD4;
        
        send2serial( hello_word );
        
        check = PTAD_PTAD5;
        
        if(! check)
        {
           send2serial( "PTA5=0\n\0" );
        }
        
        check = PTBD_PTBD3;
        
        if(! check)
        {
           send2serial( "PTB3=0\n\0" );
        }
        
        check = PTAD_PTAD4;
        
        if(! check)
        {
           send2serial( "PTA4=0\n\0" );
        }
        
      }
        
      counter = (counter + 1) % 10000;

  } /* loop forever */
  /* please make sure that you never leave main */
}

Labels (1)
0 Kudos
1 Solution
229 Views
RChris
Contributor I

Hi,

 

I found the reason why it is not possible to use the pin PTA5 as a output, it is mentionned in the datascheet of the processor MC9S08QG4 (HCS08  family) in the section "2.2 Recommended System Connections".

 

There is a diagram (Figure 2-4. Basic System Connections) that explains that the pin PTA5 could be used only as an input.

 

The problem is solved.

View solution in original post

0 Kudos
1 Reply
230 Views
RChris
Contributor I

Hi,

 

I found the reason why it is not possible to use the pin PTA5 as a output, it is mentionned in the datascheet of the processor MC9S08QG4 (HCS08  family) in the section "2.2 Recommended System Connections".

 

There is a diagram (Figure 2-4. Basic System Connections) that explains that the pin PTA5 could be used only as an input.

 

The problem is solved.

0 Kudos