[Driver cho TUSB3410] MSP430 APPLICATION UART

Đây là driver cho Kit MSP430 LaunchPad giao tiếp uart. Ngoài ra theo mình nghĩ thì Kit này còn có chức năng như là Module FT232 vậy. Mọi người có thể sử dụng các chân Tx Rx của phần nạp trên Kit để giao tiếp với Board MCU khác, mọi người thử xem sao ha. .::Muốn biết thêm thông tin thì tìm hiểu con TUSB3410::.
[Hy vọng bài viết này có ích]:o
 

Attachments

thienminh_npn

Thành Viên PIF
Lauchpad: 32k crystal and baudrate?

Hi dudes, how's your 32kHz crystal working on launchpad? Mine is about 32 Hz instead, very low!!
Any1 would contribute some precious commentary on my codes below? It's uart simulation utilizing timer A. I choose a 100bps baurate but it seems like the actual rate is 1000 times greater on the reciever (the virtual com on my lap) so they're not really synchronized at all!

/*
* main.c
*/

#include "msp430g2231.h"
#define Ts 1E6/100
#define START_BIT 0
#define STOP_BIT 9

unsigned int tx_buff=0, bit_index;

void FaultRoutine(void)
{
P1DIR |= 0x01; //set P1.0 as osc. fault indicator
P1OUT = 0x01; // red LED on
while(1); // TRAP
}

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
//setup clocks
if (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF) // If calibration data is erased
FaultRoutine(); // run FaultRoutine()

BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_0 + DIVS_0; // MCLK=DCOCLK, SMCLK=DCOCLK, MCLK/1, SMCLK/1

//setup tranmission and indicator
P1DIR |= (BIT1+BIT0); //P1.1 as TXD, P1.0 to red LED to indicate transmission line state
P1DIR &= ~BIT2; //P1.2 as RXD
P1OUT |= BIT1 + BIT0; //idle state high

//setup timerA as synchronous clock
TACCR0 = Ts-1; //interrupt every Ts
TACTL = TASSEL_2 + MC_1; //TA CLK = SMCLK, UP mode
TACCR0 = Ts-1; //interrupt every Ts

tx_buff=0xAA;

bit_index = START_BIT;

TACCTL0 = CCIE;
_BIS_SR(GIE); // enable interrupt;

while(1)
{while(1);};
}

#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A(void)
{
switch (bit_index)
{
case START_BIT:
P1OUT &= ~(BIT1+BIT0);
bit_index+=1;
break;
case STOP_BIT:
P1OUT |= (BIT1+BIT0);
// bit_index = START_BIT; //prepare to re-send
TACCTL0 &= ~CCIE;
// TACTL &= 0xFFCF;
break;
default:
if(tx_buff & (1 << (bit_index-1))) //mask out the bit in buffer to set on the trans. line
P1OUT |= (BIT1+BIT0);
else P1OUT &= ~(BIT1+BIT0);
bit_index++;
break;
}
}
 
Hi, I dont think a 32Hz crytal is available. You might read it wrongly. As what you said, it is completely a 32Khz crytal.
100bps baudrate, what do you intend to do at this rate ? Even my boards with upscale MCUs cant work properly at this rate.
About the code, I have no idea, sorry.
 

thienminh_npn

Thành Viên PIF
It's a joke bro, i meant that it's very slow. I used a 100-cycle delay and it took almost a minute to finish when MCLK was sourced from that crystal. I wonder if i made something incorrectly. The code was to use timeA as the synch clock to shift bits in an uart-like method and 100 bps is to for visual observation only. The case is my virtual COM port (buffered by a tme's ft232 kit) reads it so much faster that i dont find any sense.
 
Try it on osciloscope. Send an 'A' to determine time between 2 signal changes, you'll get the baudrate.
U can use your sound card as an osciloscope, 100bps would be fine viewed.
 

ttnghiabk

Trứng gà
hi all

now, I'm working with msp4302452 and want to use uart port but surperisingly I can not find any uart port of it

I read features of msp40 in its datasheet and realize this thing, have I misunderstanded
can anyone explain it to me? thanks in advanced
 
hi all

now, I'm working with msp4302452 and want to use uart port but surperisingly I can not find any uart port of it

I read features of msp40 in its datasheet and realize this thing, have I misunderstanded
can anyone explain it to me? thanks in advanced
Those above was about emulation of UART with GPIO pins. Your MCU does not have any UART port, and such emulation is not encorage. Try others with real UART module.
 
Top