Clear a GPIO Pin

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

Clear a GPIO Pin

Jump to solution
869 Views
blakehodder
Contributor III

I am using CW 10.3 for the MCF52255. When I attempt

 

SETTJ_SETTJ5_BITMASK=1;

 

or

 

CLRTJ_CLRTJ5_BITMASK=0;

 

I get the error "not an lvalue".

 

How do set and clear this pin without using MQX.

 

Thanks,

 

Blake

Labels (1)
Tags (3)
0 Kudos
1 Solution
587 Views
TomE
Specialist II

This is a CodeWarrior question, so you could ask the question in that forum. You should also look for example code that uses those registers so you can copy working code.

Maybe you're familiar with 8-bit CPUs that have bit-set and bit-clear instructions that work on I/O pins, and are looking for an equivalent instruction in this one? The ColdFire CPU does have BSET and BCLR instructions, but that is a slow way to change an I/O pin. The Port Set and Clear registers are a faster way to set and clear pins, that's why they're there.

The next thing you should when you get this sort of error from the compiler do is to search in the provided header files for the definition of "SETTJ_SETTJ5_BITMASK" to find out what actual code the preprocessor is generation. My guess (I don't have CodeWarrior) is that it will be defined to something like "(1 << 5)" or 0x20. And because you have to write zeros to the bits in CLRTJ to clear bits (and ones to every other bit) I'd guess CLRTJ_CLRTJ5_BITMASK is defined as "~(1 << 5)" or 0xdf.

Read "15.6.3 Port Pin Data/Set Data Registers (PORTnP/SETn)" in the Reference Manual. In there it tells you to write an 8-bit value to the SETTJ port, and that bits written as "1" will set the port bits. Likewise 0's written to CLRTJ will clear a bit.

So writing "1" to it should set the bottom bit, and not all 8. I'd guess the way you're meant to use those definitions is to write:

SETTJ = SETTJ_SETTJ5_BITMASK;

CLRTJ = CLRTJ_CLRTJ5_BITMASK;

Tom

View solution in original post

0 Kudos
4 Replies
587 Views
JimDon
Senior Contributor III

This is the code I used in an actual CW project:

MCF_GPIO_SETTJ = MCF_GPIO_PORTTJ_PORTTJ5 ;      // Set a bit

MCF_GPIO_CLRTJ &= ~MCF_GPIO_PORTTJ_PORTTJ5 ;  // Clear the bit.

But that was 10.2, not sure where your defines are coming from. These are from MCF52255_GPIO.h.

Also not sure why you would use a define like MCF_GPIO_PORTTJ_PORTTJ5 as it really has no logical meaning and it not any better than 0x20.

I would use somethhing like DATA_STROBE or what ever that line is doing in the design.

0 Kudos
587 Views
blakehodder
Contributor III

I need to add, I can set or clear the entire port if I use SETTJ=1 or CLRTJ=0 but I cannot set a specific bit within that port.

Any hints on how to accomplish this or as to why it does not work?

Thanks,

Blake

0 Kudos
588 Views
TomE
Specialist II

This is a CodeWarrior question, so you could ask the question in that forum. You should also look for example code that uses those registers so you can copy working code.

Maybe you're familiar with 8-bit CPUs that have bit-set and bit-clear instructions that work on I/O pins, and are looking for an equivalent instruction in this one? The ColdFire CPU does have BSET and BCLR instructions, but that is a slow way to change an I/O pin. The Port Set and Clear registers are a faster way to set and clear pins, that's why they're there.

The next thing you should when you get this sort of error from the compiler do is to search in the provided header files for the definition of "SETTJ_SETTJ5_BITMASK" to find out what actual code the preprocessor is generation. My guess (I don't have CodeWarrior) is that it will be defined to something like "(1 << 5)" or 0x20. And because you have to write zeros to the bits in CLRTJ to clear bits (and ones to every other bit) I'd guess CLRTJ_CLRTJ5_BITMASK is defined as "~(1 << 5)" or 0xdf.

Read "15.6.3 Port Pin Data/Set Data Registers (PORTnP/SETn)" in the Reference Manual. In there it tells you to write an 8-bit value to the SETTJ port, and that bits written as "1" will set the port bits. Likewise 0's written to CLRTJ will clear a bit.

So writing "1" to it should set the bottom bit, and not all 8. I'd guess the way you're meant to use those definitions is to write:

SETTJ = SETTJ_SETTJ5_BITMASK;

CLRTJ = CLRTJ_CLRTJ5_BITMASK;

Tom

0 Kudos
587 Views
blakehodder
Contributor III

Thanks Tom,

That did work for setting a bit. For clearing a bit I had to change the header file as CLRTJ_CLRTJ5_BITMASK was defined as 0x20 instead of 0xdf.

Blake

0 Kudos