Jump to content
Sign in to follow this  
leomar01

Change pin of software UART

Recommended Posts

Hello,

 

First the essential information: I'm using a MSP430G2553 on a launchpad.

I found some examples on software UART. To be precise, this one: http://www.msp430launchpad.com/2010/08/ ... chpad.html

My main question is: where is the pin defined, that is used for tx, rx? (I want to change it to port 2.0)

Very often in these examples, there is a statement like

 #define TXD BIT1 // TXD on P1.1
#define RXD BIT2 // RXD on P1.2

but it seems this is not exactly the definition of the pin. Later in the code I see

P1SEL |= TXD;
P1DIR |= TXD;

P1SEL is the port 1 selection register - I can't find an explanation what there is to be selected. Does it select the pin which the timer should affect.

P1DIR sets the direction of that pin -> output.

ok, let's leave it for the tx pin for now.

I can see in the datasheet, that Timer1 can only affect some pins on Port1. So I choose to use timer2.

What I don't understand: there are registers like CCR0, this register is defined multiple times in the datasheet (table 14 peripherals with word access). The other pseudo-names there are also used multiple times.

Sigh... :think: I need some ressource that explains all that for idiots ... -.-

 

leo

Share this post


Link to post
Share on other sites
P1SEL selects for each pin if it will be used as a digital I/O or for its secondary funcion (like analog input, PWM output, etc).

 

PISEL = 0x00; // select all P1 pins to be used as digital I/O

 

more can be found within the datasheet (i think) ;)

Share this post


Link to post
Share on other sites

your example from above does nothing else than to declare the PINs as digital I/O-Pins or even better - it declares your pin P1.1 to an digital output-pin ;)

 

edit: to change it to P2.0 it should look like:

 

#define TXD BIT0
P2SEL |= TXD;
P2DIR |= TXD;

Share this post


Link to post
Share on other sites

That is what I understood, what I don't understand is where in the above mentioned example this digital output pin is actually altered to do the communication. And thus I don't understand where to even search for what I have to change to get pin2.0 to do what p1.1 does right now.

Share this post


Link to post
Share on other sites

ahh now i see ... you use the 2553 - then you dont need software UART! it has hardware UART onboard - but on the Pins 1.1 and 1.2 ;) do you really need it on Port 2.0? Otherwise i would advice you to use the hardware UART - it is faster, more stable, needs less space - and at least easier to use ;)

 

for the msp430g2553:

P1.1 = RX

P1.2 = TX

if you use UART over the launchpad you will have to switch the jumpers that connect your

Share this post


Link to post
Share on other sites
do you really need it on Port 2.0?

unfortunately, yes - I allready built my pcb with a HD44780 display at port1. As I ran out of ROM in developing phase I ordered the big 2553. I broke out the port2 pins "for later use" while designing the layout. Now I want to have serial communication on this port2. I know that hardware uart would be much faster and easier - but I also want to understand how this software thing works. In future I want to be able to develop my own solutions - not copy&paste examples together to get it to work somehow.

Share this post


Link to post
Share on other sites

then have a look at the following part of your code - this is where the pin gets toggled (line 11 + line 13) - toggle pin 2.0 where it says // Set TX bit to 0

 

you can also have a look at: http://320volt.com/wp-content/uploads/2 ... 400.c.html

he has TX on the 1.5 - i can't test actually because i am not at home

 

if(!isReceiving)
{
CCR0 += Bit_time; // Add Offset to CCR0
if ( BitCnt == 0) // If all bits TXed
{
  TACTL = TASSEL_2; // SMCLK, timer off (for power consumption)
CCTL0 &= ~ CCIE ; // Disable interrupt
}
else
{
CCTL0 |= OUTMOD2; // Set TX bit to 0
if (TXByte & 0x01)
CCTL0 &= ~ OUTMOD2; // If it should be 1, set it to 1
TXByte = TXByte >> 1;
BitCnt --;
}
}

Share this post


Link to post
Share on other sites

Ok, I found it, so CCR0 = TACCR0 = TACCR0_ = TA0CCR0_ = TA0CCR0

but for Timer1 theres only TA1CCR0 what corresponds to these above, right?

 

and CCTL0 = TACCTL0 = TA0CCTL0 = TACCTL0_ = TA0CCTL0_ where, like above, only TA1CCTL0 exists for timer1.

 

 

with that information I can read this datasheet http://www.ti.com/lit/ds/symlink/msp430g2553.pdf

On page 17, table 14 it says CCR0 and CCTL0 (and all the others) two times, but - of course - with different adresses for the two different timers.

This thing puzzled me for allmost two days now - is this a bug in the datasheet, or am I still not getting it right?

Share this post


Link to post
Share on other sites

you will have to use Timer1 instead of Timer0 ;)

http://www.ti.com/lit/ds/symlink/msp430g2553.pdf - on page 6

 

/************************************************************
* Timer1_A3
************************************************************/
#define __MSP430_HAS_T1A3__           /* Definition to show that Module is available */

#define TA1IV_              (0x011Eu)  /* Timer1_A3 Interrupt Vector Word */
READ_ONLY DEFW( TA1IV          , TA1IV_)
#define TA1CTL_             (0x0180u)  /* Timer1_A3 Control */
DEFW(   TA1CTL            , TA1CTL_)
#define TA1CCTL0_           (0x0182u)  /* Timer1_A3 Capture/Compare Control 0 */
DEFW(   TA1CCTL0          , TA1CCTL0_)
#define TA1CCTL1_           (0x0184u)  /* Timer1_A3 Capture/Compare Control 1 */
DEFW(   TA1CCTL1          , TA1CCTL1_)
#define TA1CCTL2_           (0x0186u)  /* Timer1_A3 Capture/Compare Control 2 */
DEFW(   TA1CCTL2          , TA1CCTL2_)
#define TA1R_               (0x0190u)  /* Timer1_A3 */
DEFW(   TA1R              , TA1R_)
#define TA1CCR0_            (0x0192u)  /* Timer1_A3 Capture/Compare 0 */
DEFW(   TA1CCR0           , TA1CCR0_)
#define TA1CCR1_            (0x0194u)  /* Timer1_A3 Capture/Compare 1 */
DEFW(   TA1CCR1           , TA1CCR1_)
#define TA1CCR2_            (0x0196u)  /* Timer1_A3 Capture/Compare 2 */
DEFW(   TA1CCR2           , TA1CCR2_)

/* Bits are already defined within the Timer0_Ax */

/* T1_A3IV Definitions */
#define TA1IV_NONE          (0x0000u)    /* No Interrupt pending */
#define TA1IV_TACCR1        (0x0002u)    /* TA1CCR1_CCIFG */
#define TA1IV_TACCR2        (0x0004u)    /* TA1CCR2_CCIFG */
#define TA1IV_TAIFG         (0x000Au)    /* TA1IFG */

Share this post


Link to post
Share on other sites
you will have to use Timer1 instead of Timer0 ;)

you mean for using pin 2.0? yes - that's what I'm out for. I want to do the same thing as in all the examples (the timer directly affects the output pin) with timer1 on pin 2.0. In the datasheet I can see that Pin2.0 is

Timer1_A, capture: CCI0A input, compare: Out0 output

So I "only" need to get my timer1 configured correctly and it should get the transmission on pin2.0 going.

 

One other thing, just to make shure: What is meant by "counts" in the users guide? Does it mean "when the timer reaches that value" or does it mean "while the timer is counting up to that value"?

The output is set when the timer counts to the TACCRx value. It is reset when the timer counts to the TACCR0 value.

 

And another thing: Where do you have that part from?:

/************************************************************
* Timer1_A3
************************************************************/
#define __MSP430_HAS_T1A3__           /* Definition to show that Module is available */

#define TA1IV_              (0x011Eu)  /* Timer1_A3 Interrupt Vector Word */
READ_ONLY DEFW( TA1IV          , TA1IV_)
#define TA1CTL_             (0x0180u)  /* Timer1_A3 Control */
DEFW(   TA1CTL            , TA1CTL_)
#define TA1CCTL0_           (0x0182u)  /* Timer1_A3 Capture/Compare Control 0 */
DEFW(   TA1CCTL0          , TA1CCTL0_)
#define TA1CCTL1_           (0x0184u)  /* Timer1_A3 Capture/Compare Control 1 */
DEFW(   TA1CCTL1          , TA1CCTL1_)
#define TA1CCTL2_           (0x0186u)  /* Timer1_A3 Capture/Compare Control 2 */
DEFW(   TA1CCTL2          , TA1CCTL2_)
#define TA1R_               (0x0190u)  /* Timer1_A3 */
DEFW(   TA1R              , TA1R_)
#define TA1CCR0_            (0x0192u)  /* Timer1_A3 Capture/Compare 0 */
DEFW(   TA1CCR0           , TA1CCR0_)
#define TA1CCR1_            (0x0194u)  /* Timer1_A3 Capture/Compare 1 */
DEFW(   TA1CCR1           , TA1CCR1_)
#define TA1CCR2_            (0x0196u)  /* Timer1_A3 Capture/Compare 2 */
DEFW(   TA1CCR2           , TA1CCR2_)

/* Bits are already defined within the Timer0_Ax */

/* T1_A3IV Definitions */
#define TA1IV_NONE          (0x0000u)    /* No Interrupt pending */
#define TA1IV_TACCR1        (0x0002u)    /* TA1CCR1_CCIFG */
#define TA1IV_TACCR2        (0x0004u)    /* TA1CCR2_CCIFG */
#define TA1IV_TAIFG         (0x000Au)    /* TA1IFG */

because in my msp430g2553.h file this part looks like:

#define __MSP430_HAS_T1A3__                   /* Definition to show that Module is available */

SFR_16BIT(TA1IV);                             /* Timer1_A3 Interrupt Vector Word */
SFR_16BIT(TA1CTL);                            /* Timer1_A3 Control */
SFR_16BIT(TA1CCTL0);                          /* Timer1_A3 Capture/Compare Control 0 */
SFR_16BIT(TA1CCTL1);                          /* Timer1_A3 Capture/Compare Control 1 */
SFR_16BIT(TA1CCTL2);                          /* Timer1_A3 Capture/Compare Control 2 */
SFR_16BIT(TA1R);                              /* Timer1_A3 */
SFR_16BIT(TA1CCR0);                           /* Timer1_A3 Capture/Compare 0 */
SFR_16BIT(TA1CCR1);                           /* Timer1_A3 Capture/Compare 1 */
SFR_16BIT(TA1CCR2);                           /* Timer1_A3 Capture/Compare 2 */

 

leo

Share this post


Link to post
Share on other sites
... the headerfile they provided
seems much easier to understand - for me.

I just found out that the final adresses, used in ccs4, are defined in msp430g2553.cmd.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...