EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Can we define bit in Code Composer

Started by John December 21, 2011
Hi all,

I was just wondering if we can define a bit in the code composer please.

Like the following example,

#define RES P3_3 // Reset
#define CS P3_4 // Chip Select

Now if we write RES=0 means bit 3 of PORT 3 is equal to zero. Of course this is 8051 family compiler example not the MSP430.

I am wondering if it can be done for the MSP430 as well.

Thanks,

John.

Beginning Microcontrollers with the MSP430

On 22/12/2011 02:33, John wrote:
>
> Hi all,
>
> I was just wondering if we can define a bit in the code composer please.
>
> Like the following example,
>
> #define RES P3_3 // Reset
> #define CS P3_4 // Chip Select
>
> Now if we write RES=0 means bit 3 of PORT 3 is equal to zero. Of course
> this is 8051 family compiler example not the MSP430.
>
> I am wondering if it can be done for the MSP430 as well.
>
> Thanks,
>
> John.
>

The 8051 can address bits directly (at least some bits), but like most
cpu's the msp430 cannot. So for the msp430, you have to tie the port
address and the bit number together in another way. There are lots of
ways to do this, with people using different styles.
--- In m..., "John" wrote:
> Hi all,
>
> I was just wondering if we can define a bit in the code composer please.
>
> Like the following example,
>
> #define RES P3_3 // Reset
> #define CS P3_4 // Chip Select
>
> Now if we write RES=0 means bit 3 of PORT 3 is equal to zero. Of course this is 8051 family compiler example not the MSP430.
>
> I am wondering if it can be done for the MSP430 as well.
>
> Thanks,
>
> John.
>
Certainly.

You need to define the port and pin separately though, to my knowledge:

#define CS BIT7
#define CS_SEL P3SEL
#define CS_OUT P3OUT
#define CS_DIR P3DIR

The code in C:

CS_SEL &=~ CS; // PxSEL = 0 for GPIO

CS_DIR |= CS; // PxDIR = 1 CS is output

CS_OUT |= CS; // CS = 1

CS_OUT &= ~CS; // CS = 0

I hope this helps.

I would also recommend looking at the example code provided by TI for your particular chip.

-K

I'm late responding but this can be done, as described in this file (I
recall finding this on the TI forum in response to a similar question).
This explanation is for a different processor, but it's straight C code
and should work as well for CCS for the MSP430.

As the file explains, the generated code (for processsors that don't
have native single-bit manipulation instructions) for writing is a
read-modify-write operation (and likewise, reading one bit will access a
register, reading ALL its bits), and so shouldn't be used where a read
operation would clear a peripheral register bit that you rely on to
check a status. It would be nice to have I/O registers defined this way
in the include files TI provides, but the "gotcha" of accidentally
clearing a clear-on-read status bit can be a hard to find bug, and
perhaps that's why TI doesn't put this in the includes.

http://www.ti.com/lit/an/spraa85b/spraa85b.pdf

On 12/21/2011 8:33 PM, John wrote:
> Hi all,
>
> I was just wondering if we can define a bit in the code composer please.
>
> Like the following example,
>
> #define RES P3_3 // Reset
> #define CS P3_4 // Chip Select
>
> Now if we write RES=0 means bit 3 of PORT 3 is equal to zero. Of course this is 8051 family compiler example not the MSP430.
>
> I am wondering if it can be done for the MSP430 as well.
>
> Thanks,
>
> John.
>


Memfault Beyond the Launch