EmbeddedRelated.com
Forums
Memfault Beyond the Launch

#define help

Started by Hithesh October 28, 2012
How do I #define port1.4 as CS(chip select), so that I can use directly
write CS=0 and CS=1 in the code?


Beginning Microcontrollers with the MSP430

Against my better judgement I'll answer your question.. People really need to learn to search the archives.. This question comes up fairly often.. The last time I answered it was back in 2009.. see message # 42196
 

>________________________________
> From: Hithesh
>To: msp430
>Sent: Sunday, October 28, 2012 7:28 AM
>Subject: [msp430] #define help
>
>

>
>How do I #define port1.4 as CS(chip select), so that I can use directly
>write CS=0 and CS=1 in the code?
>
>
>
>
>



Hello!

Try something like this:

#define CS_HIGH() P1OUT |= BIT4
#define CS_LOW() P1OUT &= ~BIT4

This way, everytime you call CS_HIGH() and CS_LOW() in your code, it will
run as defined above.

Just to get something clear: When you do |= you're operating
the port with an OR operation. This means only the bit you've specified
will be changed. The same happens with &= ~ - only in this case
you're unselecting the specified bit.

Good luck!

Fero Santos

On Sun, Oct 28, 2012 at 9:28 AM, Hithesh wrote:

> **
> How do I #define port1.4 as CS(chip select), so that I can use directly
> write CS=0 and CS=1 in the code?
>
>
>
>
>


Fero

Woooohoooo!
Thanks. That works great.

-Hithesh

On Mon, Oct 29, 2012 at 3:57 PM, Fero Santos wrote:

> Hello!
>
> Try something like this:
>
> #define CS_HIGH() P1OUT |= BIT4
> #define CS_LOW() P1OUT &= ~BIT4
>
> This way, everytime you call CS_HIGH() and CS_LOW() in your code, it will
> run as defined above.
>
> Just to get something clear: When you do |= you're operating
> the port with an OR operation. This means only the bit you've specified
> will be changed. The same happens with &= ~ - only in this case
> you're unselecting the specified bit.
>
> Good luck!
>
> Fero Santos
>
> On Sun, Oct 28, 2012 at 9:28 AM, Hithesh wrote:
>
> > **
> >
> >
> > How do I #define port1.4 as CS(chip select), so that I can use directly
> > write CS=0 and CS=1 in the code?
> >
> >
> >
> >
> >
>
>
>

Memfault Beyond the Launch