EmbeddedRelated.com
Forums

SW UART and DCO

Started by Dikefalos Aristidis October 10, 2008
Hello. I have this TI example

//********************************************************************
**********
// MSP-FET430x110 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, No
XTAL, ROSC
//
// Description: This program demonstrates a half-duplex 9600-baud
UART using
// Timer_A3 using no XTAL and an external resistor for DCO ROSC. DCO
used for
// TACLK UART baud generation. The program will wait in LPM4,
echoing back
// a received character using 8N1 protocol. On valid RX character,
the
// character is echoed back.
// Using a 100k resistor on ROSC, with default DCO setting, set
DCOCLK ~ 2MHz.
// ACLK = n/a, MCLK = SMCLK ~2MHz DCOCLK
// //* Use of external resistor reduces temperature sensitivity of
DCOCLK *//
//
// MSP430F1121
// -----------------
// /|\ /|\| XIN|-
// | | | |
// 100k --|RST XOUT|-
// | | |
// +-------|P2.5/ROSC |
// | CCI0A/TXD/P1.1|-------->
// | | 9600 8N1
// | CCI0B/RXD/P2.2|<--------
//
#define RXD 0x04 // RXD on P2.2
#define TXD 0x02 // TXD on P1.1

// Conditions for 9600 Baud SW UART, DCO ~ 2MHz

#define Bitime_5 104 // ~ 0.5 bit length
#define Bitime 208 // ~ 9615 baud

unsigned int RXTXData;
unsigned char BitCnt;

void TX_Byte (void);
void RX_Ready (void);

// M. Buccini
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//********************************************************************
*********

#include

void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL2 |= DCOR; // Rosc
_BIS_SR(OSCOFF); // XTAL not used
CCTL0 = OUT; // TXD Idle as Mark
TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode
P1SEL = TXD; // P1.1/TA0 for TXD
function
P1DIR = TXD; // TXD output on P1
P2SEL = RXD; // P2.2/TA0 as RXD input

// Mainloop
for (;;)
{
RX_Ready(); // UART ready to RX one
Byte
_BIS_SR(LPM4_bits + GIE); // Enter LPM0 w/ interr
until char RXed
TX_Byte(); // TX Back RXed Byte
Received
}
}
// Function Transmits Character from RXTXData Buffer
void TX_Byte (void)
{
BitCnt = 0xA; // Load Bit counter,
8data + ST/SP
CCR0 = TAR; // Current state of TA
counter
CCR0 += Bitime; // Some time till first
bit
RXTXData |= 0x100; // Add mark stop bit to
RXTXData
RXTXData = RXTXData << 1; // Add space start bit
CCTL0 = OUTMOD0 + CCIE; // TXD = mark = idle
while ( CCTL0 & CCIE ); // Wait for TX completion
}
// Function Readies UART to Receive Character into RXTXData Buffer
// Sync capture not possible as DCO=TACLK=SMCLK can be off !!
void RX_Ready (void)
{
BitCnt = 0x8; // Load Bit counter
CCTL0 = CM1 + CCIS0 + OUTMOD0 + CAP + CCIE; // Neg Edge, Cap
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0 (void)
{
CCR0 += Bitime; // Add Offset to CCR0

// RX
if (CCTL0 & CCIS0) // RX on CCI0B?
{
if( CCTL0 & CAP ) // Capture mode = start
bit edge
{
CCTL0 &= ~ CAP; // Switch from capture to
compare mode
CCR0 += Bitime_5;
_BIC_SR_IRQ(SCG1 + SCG0); // DCO reamins on after
reti
}
else
{
RXTXData = RXTXData >> 1;
if (CCTL0 & SCCI) // Get bit waiting in
receive latch
RXTXData |= 0x80;
BitCnt --; // All bits RXed?
if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
CCTL0 &= ~ CCIE; // All bits RXed, disable
interrupt
_BIC_SR_IRQ(CPUOFF); // Active mode on reti 0
(SR)
}
//>>>>>>>>>> Decode of Received Byte Here
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
// TX
else
{
if ( BitCnt == 0)
CCTL0 &= ~ CCIE; // All bits TXed, disable
interrupt
else
{
CCTL0 |= OUTMOD2; // TX Space
if (RXTXData & 0x01)
CCTL0 &= ~ OUTMOD2; // TX Mark
RXTXData = RXTXData >> 1;
BitCnt --;
}
}
}

I whant this to work with 8mhz DCO at 9600 baoud. Is this possible?

I add 2 lines of code

BCSCTL1 |= 0x87;
DCOCTL |=0xE0;

To set the max freq and also i have 123kresistor. The problem is
that i don't know what values i have to use here:

// Conditions for 9600 Baud SW UART, DCO ~ 2MHz

#define Bitime_5 104 // ~ 0.5 bit length
#define Bitime 208 // ~ 9615 baud

How can I calculate them?
Thanks.

Beginning Microcontrollers with the MSP430

Using MSP430F1xx you really need a crystal. The DCO frequency varies
from chip to chip and the dependencies on operating power/temperature
are too big.

You could consider using MSP430F2xx instead. Each chip has a set of
DCO calibrations and the power/temperature coefficients are smaller.

If you still want to use F1xx without crystal, you need to measure the
DCO frequency yourself. It will work only if power/temperature do not
vary much.

--- In m..., "Dikefalos Aristidis"
wrote:
>
> Hello. I have this TI example
>
> //********************************************************************
> **********
> // MSP-FET430x110 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, No
> XTAL, ROSC
> //
> // Description: This program demonstrates a half-duplex 9600-baud
> UART using
> // Timer_A3 using no XTAL and an external resistor for DCO ROSC. DCO
> used for
> // TACLK UART baud generation. The program will wait in LPM4,
> echoing back
> // a received character using 8N1 protocol. On valid RX character,
> the
> // character is echoed back.
> // Using a 100k resistor on ROSC, with default DCO setting, set
> DCOCLK ~ 2MHz.
> // ACLK = n/a, MCLK = SMCLK ~2MHz DCOCLK
> // //* Use of external resistor reduces temperature sensitivity of
> DCOCLK *//
> //
> // MSP430F1121
> // -----------------
> // /|\ /|\| XIN|-
> // | | | |
> // 100k --|RST XOUT|-
> // | | |
> // +-------|P2.5/ROSC |
> // | CCI0A/TXD/P1.1|-------->
> // | | 9600 8N1
> // | CCI0B/RXD/P2.2|<--------
> //
> #define RXD 0x04 // RXD on P2.2
> #define TXD 0x02 // TXD on P1.1
>
> // Conditions for 9600 Baud SW UART, DCO ~ 2MHz
>
> #define Bitime_5 104 // ~ 0.5 bit length
> #define Bitime 208 // ~ 9615 baud
>
> unsigned int RXTXData;
> unsigned char BitCnt;
>
> void TX_Byte (void);
> void RX_Ready (void);
>
> // M. Buccini
> // Texas Instruments Inc.
> // Feb 2005
> // Built with IAR Embedded Workbench Version: 3.21A
> //********************************************************************
> *********
>
> #include
>
>
>
> void main (void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> BCSCTL2 |= DCOR; // Rosc
> _BIS_SR(OSCOFF); // XTAL not used
> CCTL0 = OUT; // TXD Idle as Mark
> TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode
> P1SEL = TXD; // P1.1/TA0 for TXD
> function
> P1DIR = TXD; // TXD output on P1
> P2SEL = RXD; // P2.2/TA0 as RXD input
>
> // Mainloop
> for (;;)
> {
> RX_Ready(); // UART ready to RX one
> Byte
> _BIS_SR(LPM4_bits + GIE); // Enter LPM0 w/ interr
> until char RXed
> TX_Byte(); // TX Back RXed Byte
> Received
> }
> }
>
>
> // Function Transmits Character from RXTXData Buffer
> void TX_Byte (void)
> {
> BitCnt = 0xA; // Load Bit counter,
> 8data + ST/SP
> CCR0 = TAR; // Current state of TA
> counter
> CCR0 += Bitime; // Some time till first
> bit
> RXTXData |= 0x100; // Add mark stop bit to
> RXTXData
> RXTXData = RXTXData << 1; // Add space start bit
> CCTL0 = OUTMOD0 + CCIE; // TXD = mark = idle
> while ( CCTL0 & CCIE ); // Wait for TX completion
> }
>
>
> // Function Readies UART to Receive Character into RXTXData Buffer
> // Sync capture not possible as DCO=TACLK=SMCLK can be off !!
> void RX_Ready (void)
> {
> BitCnt = 0x8; // Load Bit counter
> CCTL0 = CM1 + CCIS0 + OUTMOD0 + CAP + CCIE; // Neg Edge, Cap
> }
>
>
> // Timer A0 interrupt service routine
> #pragma vector=TIMERA0_VECTOR
> __interrupt void Timer_A0 (void)
> {
> CCR0 += Bitime; // Add Offset to CCR0
>
> // RX
> if (CCTL0 & CCIS0) // RX on CCI0B?
> {
> if( CCTL0 & CAP ) // Capture mode = start
> bit edge
> {
> CCTL0 &= ~ CAP; // Switch from capture to
> compare mode
> CCR0 += Bitime_5;
> _BIC_SR_IRQ(SCG1 + SCG0); // DCO reamins on after
> reti
> }
> else
> {
> RXTXData = RXTXData >> 1;
> if (CCTL0 & SCCI) // Get bit waiting in
> receive latch
> RXTXData |= 0x80;
> BitCnt --; // All bits RXed?
> if ( BitCnt == 0)
> //>>>>>>>>>> Decode of Received Byte Here
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> {
> CCTL0 &= ~ CCIE; // All bits RXed, disable
> interrupt
> _BIC_SR_IRQ(CPUOFF); // Active mode on reti 0
> (SR)
> }
> //>>>>>>>>>> Decode of Received Byte Here
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> }
> }
> // TX
> else
> {
> if ( BitCnt == 0)
> CCTL0 &= ~ CCIE; // All bits TXed, disable
> interrupt
> else
> {
> CCTL0 |= OUTMOD2; // TX Space
> if (RXTXData & 0x01)
> CCTL0 &= ~ OUTMOD2; // TX Mark
> RXTXData = RXTXData >> 1;
> BitCnt --;
> }
> }
> }
>
>
>
> I whant this to work with 8mhz DCO at 9600 baoud. Is this possible?
>
> I add 2 lines of code
>
> BCSCTL1 |= 0x87;
> DCOCTL |=0xE0;
>
> To set the max freq and also i have 123kresistor. The problem is
> that i don't know what values i have to use here:
>
> // Conditions for 9600 Baud SW UART, DCO ~ 2MHz
>
> #define Bitime_5 104 // ~ 0.5 bit length
> #define Bitime 208 // ~ 9615 baud
>
>
>
> How can I calculate them?
>
>
> Thanks.
>

Katevase to slaa049 app note, explains UART baud rate calculations

On Fri, Oct 10, 2008 at 5:59 PM, old_cow_yellow
wrote:
> Using MSP430F1xx you really need a crystal. The DCO frequency varies
> from chip to chip and the dependencies on operating power/temperature
> are too big.
>
> You could consider using MSP430F2xx instead. Each chip has a set of
> DCO calibrations and the power/temperature coefficients are smaller.
>
> If you still want to use F1xx without crystal, you need to measure the
> DCO frequency yourself. It will work only if power/temperature do not
> vary much.
>
> --- In m..., "Dikefalos Aristidis"
> wrote:
>>
>> Hello. I have this TI example
>>
>> //********************************************************************
>> **********
>> // MSP-FET430x110 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, No
>> XTAL, ROSC
>> //
>> // Description: This program demonstrates a half-duplex 9600-baud
>> UART using
>> // Timer_A3 using no XTAL and an external resistor for DCO ROSC. DCO
>> used for
>> // TACLK UART baud generation. The program will wait in LPM4,
>> echoing back
>> // a received character using 8N1 protocol. On valid RX character,
>> the
>> // character is echoed back.
>> // Using a 100k resistor on ROSC, with default DCO setting, set
>> DCOCLK ~ 2MHz.
>> // ACLK = n/a, MCLK = SMCLK ~2MHz DCOCLK
>> // //* Use of external resistor reduces temperature sensitivity of
>> DCOCLK *//
>> //
>> // MSP430F1121
>> // -----------------
>> // /|\ /|\| XIN|-
>> // | | | |
>> // 100k --|RST XOUT|-
>> // | | |
>> // +-------|P2.5/ROSC |
>> // | CCI0A/TXD/P1.1|-------->
>> // | | 9600 8N1
>> // | CCI0B/RXD/P2.2|<--------
>> //
>> #define RXD 0x04 // RXD on P2.2
>> #define TXD 0x02 // TXD on P1.1
>>
>> // Conditions for 9600 Baud SW UART, DCO ~ 2MHz
>>
>> #define Bitime_5 104 // ~ 0.5 bit length
>> #define Bitime 208 // ~ 9615 baud
>>
>> unsigned int RXTXData;
>> unsigned char BitCnt;
>>
>> void TX_Byte (void);
>> void RX_Ready (void);
>>
>> // M. Buccini
>> // Texas Instruments Inc.
>> // Feb 2005
>> // Built with IAR Embedded Workbench Version: 3.21A
>> //********************************************************************
>> *********
>>
>> #include
>>
>> void main (void)
>> {
>> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>> BCSCTL2 |= DCOR; // Rosc
>> _BIS_SR(OSCOFF); // XTAL not used
>> CCTL0 = OUT; // TXD Idle as Mark
>> TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode
>> P1SEL = TXD; // P1.1/TA0 for TXD
>> function
>> P1DIR = TXD; // TXD output on P1
>> P2SEL = RXD; // P2.2/TA0 as RXD input
>>
>> // Mainloop
>> for (;;)
>> {
>> RX_Ready(); // UART ready to RX one
>> Byte
>> _BIS_SR(LPM4_bits + GIE); // Enter LPM0 w/ interr
>> until char RXed
>> TX_Byte(); // TX Back RXed Byte
>> Received
>> }
>> }
>> // Function Transmits Character from RXTXData Buffer
>> void TX_Byte (void)
>> {
>> BitCnt = 0xA; // Load Bit counter,
>> 8data + ST/SP
>> CCR0 = TAR; // Current state of TA
>> counter
>> CCR0 += Bitime; // Some time till first
>> bit
>> RXTXData |= 0x100; // Add mark stop bit to
>> RXTXData
>> RXTXData = RXTXData << 1; // Add space start bit
>> CCTL0 = OUTMOD0 + CCIE; // TXD = mark = idle
>> while ( CCTL0 & CCIE ); // Wait for TX completion
>> }
>> // Function Readies UART to Receive Character into RXTXData Buffer
>> // Sync capture not possible as DCO=TACLK=SMCLK can be off !!
>> void RX_Ready (void)
>> {
>> BitCnt = 0x8; // Load Bit counter
>> CCTL0 = CM1 + CCIS0 + OUTMOD0 + CAP + CCIE; // Neg Edge, Cap
>> }
>> // Timer A0 interrupt service routine
>> #pragma vector=TIMERA0_VECTOR
>> __interrupt void Timer_A0 (void)
>> {
>> CCR0 += Bitime; // Add Offset to CCR0
>>
>> // RX
>> if (CCTL0 & CCIS0) // RX on CCI0B?
>> {
>> if( CCTL0 & CAP ) // Capture mode = start
>> bit edge
>> {
>> CCTL0 &= ~ CAP; // Switch from capture to
>> compare mode
>> CCR0 += Bitime_5;
>> _BIC_SR_IRQ(SCG1 + SCG0); // DCO reamins on after
>> reti
>> }
>> else
>> {
>> RXTXData = RXTXData >> 1;
>> if (CCTL0 & SCCI) // Get bit waiting in
>> receive latch
>> RXTXData |= 0x80;
>> BitCnt --; // All bits RXed?
>> if ( BitCnt == 0)
>> //>>>>>>>>>> Decode of Received Byte Here
>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>> {
>> CCTL0 &= ~ CCIE; // All bits RXed, disable
>> interrupt
>> _BIC_SR_IRQ(CPUOFF); // Active mode on reti 0
>> (SR)
>> }
>> //>>>>>>>>>> Decode of Received Byte Here
>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>> }
>> }
>> // TX
>> else
>> {
>> if ( BitCnt == 0)
>> CCTL0 &= ~ CCIE; // All bits TXed, disable
>> interrupt
>> else
>> {
>> CCTL0 |= OUTMOD2; // TX Space
>> if (RXTXData & 0x01)
>> CCTL0 &= ~ OUTMOD2; // TX Mark
>> RXTXData = RXTXData >> 1;
>> BitCnt --;
>> }
>> }
>> }
>>
>> I whant this to work with 8mhz DCO at 9600 baoud. Is this possible?
>>
>> I add 2 lines of code
>>
>> BCSCTL1 |= 0x87;
>> DCOCTL |=0xE0;
>>
>> To set the max freq and also i have 123kresistor. The problem is
>> that i don't know what values i have to use here:
>>
>> // Conditions for 9600 Baud SW UART, DCO ~ 2MHz
>>
>> #define Bitime_5 104 // ~ 0.5 bit length
>> #define Bitime 208 // ~ 9615 baud
>>
>> How can I calculate them?
>> Thanks.
>>
I mesure the freq from pin P1.4 and i am working on 8mhz. The thing
that i don't know is the values to set on this 2 parametrs.

Thanks.
(8MHz) / (9.6kb/s) = 833
Half of that = 416

--- In m..., "Dikefalos Aristidis"
wrote:
>
> I mesure the freq from pin P1.4 and i am working on 8mhz. The thing
> that i don't know is the values to set on this 2 parametrs.
>
> Thanks.
>

I try them but they don't work.

:/

--- In m..., "old_cow_yellow"
wrote:
>
> (8MHz) / (9.6kb/s) = 833
> Half of that = 416
>
> --- In m..., "Dikefalos Aristidis"
> wrote:
> >
> > I mesure the freq from pin P1.4 and i am working on 8mhz. The thing
> > that i don't know is the values to set on this 2 parametrs.
> >
> > Thanks.
>
Hi ,

r using the Xtal oscillator or just DCO run by RC tankcircuit?.

if u r not using the Xtal, u cannot operate softeate emulated UART.

I hope this helps.

-suresh.

--- On Tue, 10/14/08, Dikefalos Aristidis wrote:

From: Dikefalos Aristidis
Subject: [msp430] Re: SW UART and DCO
To: m...
Date: Tuesday, October 14, 2008, 11:40 AM

I try them but they don't work.

:/

--- In msp430@yahoogroups. com, "old_cow_yellow"
wrote:
>
> (8MHz) / (9.6kb/s) = 833
> Half of that = 416
>
> --- In msp430@yahoogroups. com, "Dikefalos Aristidis"
> wrote:
> >
> > I mesure the freq from pin P1.4 and i am working on 8mhz. The thing
> > that i don't know is the values to set on this 2 parametrs.
> >
> > Thanks.
>