BKGD/PTA4 how to normal output pin in MC9S08SH8

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

BKGD/PTA4 how to normal output pin in MC9S08SH8

1,304 Views
Gardo
Contributor I
Hi Forum,
I work with a MC9S08SH8 and I finished normal pins to drive my peripheral devices in SPI. I have to use the pin that normal I use to debugging; my hardware constrain me to use BKGD how to chip select to a devices.
Fortunately, only for a small time, at the start of my system, I have to contact this peripheral devices and then nevermore. So, I think , only if I need in my firmware, I disable Debugger, I reconfigure pin BKGD/PTA4/ACMP0/MS to a normal output pin with pull-up, then I use to drive my pheripheral and at the end I reconfigure this pin how to debugger.
The problem is that it's doesn't work. When I see the signal on the scope I don't see never change on this pin.
 
My code is :
 
              DisableInterrupts;                           //    I try to disable all Interrupts 
              for(rit=0;rit<=40000;rit++){} ;           // delay
              SOPT1_BKGDPE = 0;                   // Disable debugger               
              PTADD_PTADD4 = 1;                    // configure pin PTAD4 how to output pin 
              PTAPE_PTAPE4 = 0;                     // pull-up on pin PTAD4 
                          
              PTAD_PTAD4 = 0;                         // I trigger chip select on my devices (low active)
              PTAD_PTAD1 = 0;                         //  I turn on LED( OK I see led  blinking)
              
              for(rit=0;rit<=2000;rit++){};              // delay 
              
              SPIC1_SPE = 1 ;                           // Enable SPI comunication
              while(SPIS_SPTEF == 0){};          // check buffer trasmission (is full?)
              SPID = 0b00000000;                     //  data trasmitt to pheriperals
                 
              PTAD_PTAD4 = 1;                        // I "turn off" chip select on my devices
              PTAD_PTAD1 = 1;                        // turn off LED              
              for(rit=0;rit<=3000;rit++){};            // delay   
                                  
               PTADD_PTADD4 = 0;           // reconfigure pin PTAD4 how to input pin 
               SOPT1_BKGDPE = 1;            // Enable debugger
              
               EnableInterrupts;
    
 
I forget something ? I disable debugger , enable output pin , re-enable debugger correctly?
 
Any suggestions are welcome.
Thanks a lot.
 
Gardo          
Labels (1)
0 Kudos
2 Replies

352 Views
Ake
Contributor II
Hello,
A good idea, but one thing cannot be done.
You can't set the values in SOPT1 more than once after each reset.
 
Maybe it is possible to have the MCU power up, looks at a flag and enters a certain SOPT1 value.
Then it sets the flag and reset itself.
It looks at the flag and when it is set, enters another SOPT1 value.
 
The flag should be something like 0x1ba6 when set, everything else is clear.
 
Regards,
Ake
0 Kudos

352 Views
peg
Senior Contributor IV
Hello,

Yes unfortunately if you are going to use the BKGD pin for other uses and you want to debug, you have to be able to do without that other use.
Once you disable the BKGD function it stays disabled. The only way in then is by going into backgound mode at reset. Then doing something to prevent the BKGD function from being disabled.
So then you will be running without any control of this output.
You also must ensure that whatever is connected to the pin does not interfere with the BDM operation.

This severely limits what you can do with this pin, but it is still better than having it totally dedicated to the debug function.

0 Kudos