MC9S12C32 using codewarrior and P&E bdm debug module

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

MC9S12C32 using codewarrior and P&E bdm debug module

3,213 Views
frogdog
Contributor I
Can someone please tell me why PortA when used as an output produces a square wave? I tried redefining the port and each time I turn an output on I get what looks like a clock signal.  Code shown below:
 
#include <hidef.h>      /* common defines and macros */
#include <mc9s12c32.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12c32"
 
#define PORTAA (*(volatile unsigned char*) (0x00))
#define DDRAA (*(volatile unsigned char*) (0x02))
 
void main(void) {
DDRAA=0xff;
PORTAA= 0x01;
PORTAA= 0x00;
}
Labels (1)
0 Kudos
6 Replies

635 Views
frogdog
Contributor I
I am relativly sure that it is running in expanded mode but I cannot find in the startup files of codewarrior where this is happening. After perusing the 9s manual I am not sure that I want to turn off expanded mode entirely but I am not sure. I need to be able to use PortA and B for I/O I just want to turn the clocking bus signal off. I could not find anything to do this. Any help would be appreciated
Thanks
0 Kudos

635 Views
Alban
Senior Contributor II
Hello,

main() is a function the execution MUST always stay into.

An embedded program should not stop like a desktop application.

In your software, the execution starts and toggle the port. Then, the MCU does not know what to execute and RESETS.

When RESET occurs, PORTAA is an input until the execution arrives at DDRAA=0xFF execution.

At the end of the execution, within the main(), add a while(1) if you want to stop execution.

Cheers,
Alban.
0 Kudos

635 Views
frogdog
Contributor I
I was not running the code at speed but single stepping through it.  At speed I can see that yes it would toggle the ouput and thus appear as a clock however when simply stepping through the program and leaving the output latched high the signal looks like a clock signal.  It goes from about +5V to +3V I figured it had something to do with portA being an address line or something in one of the .H files but I could not figure out where.
Thanks
0 Kudos

635 Views
dog
Contributor I
hi frogdog,
 
Sounds like a scope ground problem to me but you might also want to check the levels on MODA & MODB pins to make sure you are not trying to run in an expanded bus mode.
 
And it won't toggle if you did run it Without some kind of loop it's going to execute the 3 instructions and get lost (code runaway). Embedded code should (always I think) have a loop of some kind so that it never reaches the } at the end of main.
 
dog
0 Kudos

635 Views
Alban
Senior Contributor II
Hi Frogdog,

I see better now.
It could be a earthing problem then. PORTA is only an address line when the chip is configured to be in one of the EXPANDED or EMULATION mode. In that case the oscillations would be down to 0V and would not still be a logical 1 at 3V.

Put a scope probe on PE4 to see if you have similar oscillations. PE4, when enabled, is also a pin to output the bus clock.

What is the frequency you see, and the frequency of your crystal ?

Alban.
0 Kudos

635 Views
frogdog
Contributor I
Both signals appear to be approx 10MHz I had the scope on DC before on AC both signals look very nearly identical but the signal is only present on PortA when the output is high.
Thanks
 
0 Kudos