MSP430 Baudrate Setting ändern

Gast #2342075
Lesenswert?

Ich habe folgendes Problem: Ich kann meine Baudrate des UART2 während 
des Betriebes mithilfe von DIP-Switches verändern: 
4800,9600,19200,38400; Die höheren 3 funktionieren ohne Problem nur 
sobald ich wieder auf 4800 zurückswitche funktionierts nicht mehr und im 
Receivebuffer steht 0x00; Zurück auf 9600 oder höher funktionierts 
wieder. Sobal ich aber einen Reset durchführe und die Baudrate auf 4800 
stelle funktioniert es!?
1
case MHz_1:
2
        CLEARPORTPIN(P9DIR, BIT4+BIT5);    // set port pin to INPUT
3
        SETPORTPIN(P9OUT, BIT4+BIT5);
4
        CLEARPORTPIN(P8OUT,ENABLE_TX);
5
       // SETPORTPIN(P9DIR,TXD_R_PULLUP+RXD_R_PULLUP);        // --> output
6
           
7
       // SETPORTPIN(P9OUT,TXD_R_PULLUP+RXD_R_PULLUP);        // pullup enable
8
        SETPORTPIN(P9SEL,RXD+TXD);                    //9.4+9.5
9
        // portpins are controlled by usci module
10
        UCA2IE &=~(1<< UCRXIE);
11
        UCA2CTL1 |= UCSWRST+UCRXEIE+UCBRKIE;                // put USCI state machine in reset
12
      
13
        // asynch. uart mode,1 stop bit,8databit,lsb first,no parity
14

15
        //        UCA1CTL1 |= UCSSEL_1;               // ACLK
16
        if (baud== bd_4800)
17
            UCA2CTL1 |= UCSSEL_1;               // ACLK --> REFO 32,768
18
        else
19
            UCA2CTL1 |= UCSSEL_2;        //SMCLK --> 1 MHZ
20

21

22
        // SMCLK Frequency = 1 MHz
23
        if (parity==even)
24
        {
25
            UCA2CTL0 |= UCPEN;
26
            UCA2CTL0 |=UCPAR;     //Even Parity
27
        }
28
        else if (parity==odd)
29
        {
30
            UCA2CTL0 |= UCPEN;
31
            UCA2CTL0 &=~UCPAR;
32
        }
33

34
        switch (baud)
35
        {
36

37
        case bd_4800:                  //not allowed
38
            UCA2BR0=6;
39
            UCA2BR1=0;
40
            UCA2MCTL = UCBRS_7;
41
            break;
42

43
        case bd_9600:
44
            UCA2BR0=104;
45
            UCA2BR1=0;
46
            UCA2MCTL = UCBRS_1;
47
            break;
48

49
        case bd_19200:
50
            UCA2BR0=52;
51
            UCA2BR1=0;
52
            UCA2MCTL = UCBRS_0;
53
            break;
54

55
        case bd_38400:
56
            UCA2BR0=26;
57
            UCA2BR1=0;
58
            UCA2MCTL = UCBRS_0;
59
            break;
60

61
        default:
62
            //9600
63
            UCA2BR0=104;
64
            UCA2BR1=0;
65
            UCA2MCTL = UCBRS_1;
66
            break;
67
        }
68

69
        break;
70
    case MHz_4:
71
        break;
72
    default:
73
        return false;
74
    }
75
    UCSCTL7 |= 0x0010;
76
   
77
    UCA2CTL1 &= ~UCSWRST;               // **Initialize USCI state machine**
78
    UCA2IE |= UCRXIE;
Gast #2342365
Lesenswert?

Also umgeschaltet wird in einer eigenen Funktion(interruptUNabhängig). 
Um aber eine Baudrate von 4800 zu erreichen wird die Clocksource von 
SMCLK auf REFCLK(32,768kHz) umgeschaltet. Die Register werden richtig 
gesetzt. Der korrekte Empfang funktioniert nicht mehr, es wird kein 
Interrupt mehr ausgelöst...
Gast #2343359
Lesenswert?

Nein, funktioniert auch nicht.
Ablauf:
Starte ich das Programm für Baudrate 4800 funktioniert es einwandfrei, 
wechsle ich die Baudraten durch (9600,19200,38400) funktioniert auch 
noch, aber sobald ich wieder auf 4800 zurückschalte funktioniert es 
nicht mehr, aber alle ab 9600 funktionieren noch ..?
Gast #2343391
Lesenswert?

1
        if (baud== bd_4800)
2
            UCA2CTL1 |= UCSSEL_1;               // ACLK --> REFO 32,768
3
        else
4
            UCA2CTL1 |= UCSSEL_2;        //SMCLK --> 1 MHZ

Wo wird denn UCA2CTL1 jemals wieder zurückgesetzt, damit UCSSEL_1 
überhaupt "wirken" kann?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren