Forum: Mikrocontroller und Digitale Elektronik UART, Interrupt RX, F28335 von TI


von Alexander (Gast)


Angehängte Dateien:

Lesenswert?

Hi,
und frohe Weihnachten. Bevor es nachher mit dem Familienfest losgeht, 
wollte ich gerne noch mal ein wenig mit dem F28335 von TI herumspielen, 
scheitere jedoch am UART mit Interruptbetrieb.

Es funktioniert irgendwie, aber nicht so richtig. Zunächst dauert es 
einmal ca. 13 Tastendrücke, bevor ich das erste mal in die ISR springe.

Nachdem ich das erste mal in der ISR war, dauert es anschließend 2 
Tastendrücke, bis ich wieder in die ISR reinspringe. Und letztendlich 
wird auch nicht die gedrückte Taste auf dem Display wiedergegeben, 
sondern vorige Tasten. Soll heißen, dass die gedrückte Taste erst nach 
einigen weiteren Tastendrücken angezeigt wird.

Ein Screenshot von HyperTerminal ist im Anhang, falls das irgendwie 
hilft. Meine Vermutung ist, dass der String in der ISR irgendwie 
fehlerhaft geschrieben/ausgewertet wird.

Vielen Dank an alle.

Gruß,

Und der Code:
1
/*
2
 * This example sets up the UART to send data to and receive data from the laptop
3
 * When the data is received, an interrupt occurs and the data will then be taken from the buffer
4
 */
5
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
6
__interrupt void UART_isr(void);
7
8
void scia_init();
9
void scia_xmit(int a);
10
void scia_msg(char *msg);
11
Uint16 bla;
12
Uint16 ReceivedChar;
13
char *msg;
14
15
#define UART_MAXSTRLEN 10
16
volatile Uint16 uart_str_complete = 0;     // 1 .. String komplett empfangen
17
volatile Uint16 uart_str_count = 0;
18
volatile char uart_string[UART_MAXSTRLEN + 1] = "";
19
20
21
22
void main(void) {
23
24
  ReceivedChar=0;
25
    bla=0;
26
27
  // Step 1: Setting the PLL, Watchdog, enable peripheral clocks
28
  InitSysCtrl();
29
30
  // Step 3: Initialize the PIE control registers
31
//  DINT; // Only necessary here if InitPieCtrl() does not have DINT; included
32
  InitPieCtrl();
33
34
  IER = 0x0000;
35
  IFR = 0x0000;
36
37
  // Step 4: Initialize the PIE vector table to default ISR
38
  InitPieVectTable();
39
40
  // Configure the interrupt handling
41
  // Setting up the XINT1 trigger, Table 112
42
  EALLOW;
43
  PieVectTable.SCIRXINTA = &UART_isr;
44
  EDIS;
45
46
  // Enable XINT1 in the PIE
47
//  PieCtrlRegs.PIECTRL.bit.ENPIE = 1;  // Enables the PIE interrupt table. Already done in InitPieVectTable();
48
  PieCtrlRegs.PIEIER9.bit.INTx1 = 1;  // Figure 87
49
  IER |= M_INT9;            // Sets the interrupt enable bit of group 9
50
  EINT;                // Enable global interrupts INTM
51
  // Step 5: Initialize other device peripherals
52
53
  // We need to initialize our SCI
54
  InitSciGpio();
55
56
  // Step 6: Write your code
57
  scia_init();  // Initialize Sci FIFO
58
  msg = "\r\nHello Alexander!\0";
59
    scia_msg(msg);
60
  
61
  msg = "\r\nHow are you?\0";
62
    scia_msg(msg);
63
64
  for(;;)
65
  {
66
         // Wait for inc character
67
         while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state
68
  }
69
}
70
71
void scia_init()
72
{
73
  /*
74
   * FIFO configuration
75
   */
76
  // SCIFFTX registers
77
  SciaRegs.SCIFFTX.bit.SCIRST = 1;  // Sci reset
78
  SciaRegs.SCIFFTX.bit.SCIFFENA = 1;  // Sci enhancements enabled
79
  SciaRegs.SCIFFTX.bit.TXFIFOXRESET = 1;  // Re-enable transmit FIFO operation
80
  SciaRegs.SCIFFTX.bit.TXFFST = 0;  // Transmit FIFO is empty
81
  SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1;  // Clears TXFFINT flag
82
  SciaRegs.SCIFFTX.bit.TXFFIENA = 0;  // TX FIFO interrupt is disabled
83
84
  // SCIFFRX registers
85
  SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;  // Re-enable receive FIFO operation
86
  SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;  // Clears RXFFINT flag
87
  SciaRegs.SCIFFRX.bit.RXFFIENA = 1;  // RX FIFO interrupt is enabled
88
//  SciaRegs.SCIFFRX.bit.RXFFIL = 0x1F; // 1111
89
90
  // SCIFFCT registers
91
  SciaRegs.SCIFFCT.all = 0;      // Lets leave it as it is for now
92
93
  /*
94
   * Echoback configuration
95
   */
96
  // SCICCR registers
97
  SciaRegs.SCICCR.bit.STOPBITS = 0;  // 1 stop bit
98
  SciaRegs.SCICCR.bit.PARITY = 0;    // Odd Parity - but will be disabled anyways
99
  SciaRegs.SCICCR.bit.PARITYENA = 0;  // Parity disabled
100
  SciaRegs.SCICCR.bit.LOOPBKENA = 0;  // Loopback test mode disabled
101
  SciaRegs.SCICCR.bit.ADDRIDLE_MODE = 0;  // Idle line mode
102
  SciaRegs.SCICCR.bit.SCICHAR = 7;  // 8 char bits
103
104
  // SCICTL1 registers
105
  SciaRegs.SCICTL1.bit.RXERRINTENA = 0;  // Receive error interrupt disabled
106
  SciaRegs.SCICTL1.bit.SWRESET = 0;  // Initializing operating flags to the reset condition
107
  SciaRegs.SCICTL1.bit.TXWAKE = 0;  // Wake-up mode disabled
108
  SciaRegs.SCICTL1.bit.SLEEP = 0;    // Sleep mode disabled
109
  SciaRegs.SCICTL1.bit.TXENA = 1;    // Enable transmitter
110
  SciaRegs.SCICTL1.bit.RXENA = 1;    // Enable receiver
111
112
  // SCICTL2 registers
113
  SciaRegs.SCICTL2.bit.TXRDY = 0;    // SCITXBUF is full
114
  SciaRegs.SCICTL2.bit.TXEMPTY = 0;  // Transmitter buffer is loaded with data
115
  SciaRegs.SCICTL2.bit.RXBKINTENA = 1;  // Receiver buffer interrupt enabled
116
  SciaRegs.SCICTL2.bit.TXINTENA = 1;  // TXRDY interrupt enabled
117
118
  // SCIHBAUD registers for BAUD rate
119
    SciaRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 37.5MHz.
120
    SciaRegs.SCILBAUD    =0x00E7;
121
122
    // SCICTL1 registers again
123
    SciaRegs.SCICTL1.all = 0x0023;  // WTF?
124
}
125
126
void scia_xmit(int a)
127
{
128
  // Wait until sending is possible
129
  while(SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
130
  SciaRegs.SCITXBUF = a;  // Sending the data
131
  bla=a-'0';
132
}
133
134
void scia_msg(char * msg)
135
{
136
  //
137
  int i;
138
  i = 0;
139
  while(msg[i] != '\0')
140
  {
141
    //
142
    scia_xmit(msg[i]);
143
    i++;
144
  }
145
}
146
147
__interrupt void UART_isr(void)
148
{
149
    // Get character
150
    ReceivedChar = SciaRegs.SCIRXBUF.all;
151
    if( uart_str_complete == 0 ) {  // wenn uart_string gerade in Verwendung, neues Zeichen verwerfen
152
153
      // Daten werden erst in uart_string geschrieben, wenn nicht String-Ende/max Zeichenlänge erreicht ist/string gerade verarbeitet wird
154
      if( ReceivedChar != '\n' &&
155
          ReceivedChar != '\r' &&
156
          uart_str_count < UART_MAXSTRLEN ) {
157
        uart_string[uart_str_count] = ReceivedChar;
158
        uart_str_count++;
159
      }
160
      else {
161
        uart_string[uart_str_count] = '\0';
162
        uart_str_count = 0;
163
        uart_str_complete = 1;
164
      }
165
    }
166
    msg = "\r\nYou sent: \0";
167
    scia_msg(msg);
168
    scia_xmit(ReceivedChar);
169
170
  SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag
171
  SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;  // Clears RXFFINT flag to enable new incoming interrupts
172
  // Acknowledge this interrupt to get more from group 1
173
  PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
174
}

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Der Aufruf von scia_msg im Empfangsinterrupt ist keine gute Idee.

von Alexander (Gast)


Lesenswert?

Hi Rufus,
Rufus Τ. F. schrieb:
> Der Aufruf von scia_msg im Empfangsinterrupt ist keine gute Idee.

Vielen Dank für den Hinweis. Ich habe den Code nun insofern abgeändert, 
als dass lediglich der Datenempfang in der ISR geschieht, und ich 
überprüfe die Variablen in Code Composer Studio im Watch Window (also 
gar nicht mehr über Echoback ans Hyperterminal zu senden).

Auch ist der Code in der ISR so angeändert, dass die Daten aus dem 
Buffer direkt in die Variable "ReceivedChar" geschrieben wird.

Hier mal ein paar Daten zum Ergebnis:
1. Die Taste muss zunächst 17 mal gedrückt werden, bis die ISR das erste 
Mal aufgerufen wird. Ich drücke beispielsweise die Taste 1 (ASCII) 17 
mal, bis die ISR aufgerufen ist und ReceivedChar mit 49 (was dem ASCII 1 
entspricht) belegt ist.
2. Dann muss ich zwei mal mehr eine Taste drücken, bis die ISR erneut 
aufgerufen wird. Z.B. drücke ich die Taste 2, was entsprechend 50 in der 
ASCII Tabelle wäre. Allerdings zeigt mir mein Watch Window, dass im 
Buffer immer noch 49 steht.
3. Ich muss die ISR 7 weitere mal aufrufen (also 8 in der Summe, 
entsprechend 16 weiteren Tastendrücken), bis ich im Watch Window sehe, 
dass mein Buffer den neuen Inhalt besitzt (50, dem äquivalent zum ASCII 
Zeichen "2").

Von hier an wiederholt sich das ganze Spiel, soll heißen, ich muss die 
ISR 8 mal aufrufen (16 Tastendrücke insgesamt), bis der Inhalt meines 
Buffers aktualisiert wird.

Da Software eher ein Hobby ist, ist es für mich schwer, meinen Fehler zu 
sehen bzw. zu beheben.

Irgendwelche Ideen?

Danke und Gruß.
1
/*
2
 * This example sets up the UART to send data to and receive data from the laptop
3
 * When the data is received, an interrupt occurs and the data will then be taken from the buffer
4
 */
5
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
6
__interrupt void UART_isr(void);
7
8
void scia_init();
9
Uint16 bla;
10
Uint16 ReceivedChar;
11
12
13
14
void main(void) {
15
16
  ReceivedChar=0;
17
    bla=0;
18
19
  // Step 1: Setting the PLL, Watchdog, enable peripheral clocks
20
  InitSysCtrl();
21
22
  // Step 3: Initialize the PIE control registers
23
//  DINT; // Only necessary here if InitPieCtrl() does not have DINT; included
24
  InitPieCtrl();
25
26
  IER = 0x0000;
27
  IFR = 0x0000;
28
29
  // Step 4: Initialize the PIE vector table to default ISR
30
  InitPieVectTable();
31
32
  // Configure the interrupt handling
33
  // Setting up the XINT1 trigger, Table 112
34
  EALLOW;
35
  PieVectTable.SCIRXINTA = &UART_isr;
36
  EDIS;
37
38
  // Enable XINT1 in the PIE
39
//  PieCtrlRegs.PIECTRL.bit.ENPIE = 1;  // Enables the PIE interrupt table. Already done in InitPieVectTable();
40
  PieCtrlRegs.PIEIER9.bit.INTx1 = 1;  // Figure 87
41
  IER |= M_INT9;            // Sets the interrupt enable bit of group 9
42
  EINT;                // Enable global interrupts INTM
43
  // Step 5: Initialize other device peripherals
44
45
  // We need to initialize our SCI
46
  InitSciGpio();
47
48
  // Step 6: Write your code
49
  scia_init();  // Initialize Sci FIFO
50
51
  for(;;)
52
  {
53
         // Wait for inc character
54
         while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state
55
  }
56
}
57
58
void scia_init()
59
{
60
  /*
61
   * FIFO configuration
62
   */
63
  // SCIFFTX registers
64
  SciaRegs.SCIFFTX.bit.SCIRST = 1;  // Sci reset
65
  SciaRegs.SCIFFTX.bit.SCIFFENA = 1;  // Sci enhancements enabled
66
  SciaRegs.SCIFFTX.bit.TXFIFOXRESET = 1;  // Re-enable transmit FIFO operation
67
  SciaRegs.SCIFFTX.bit.TXFFST = 0;  // Transmit FIFO is empty
68
  SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1;  // Clears TXFFINT flag
69
  SciaRegs.SCIFFTX.bit.TXFFIENA = 0;  // TX FIFO interrupt is disabled
70
71
  // SCIFFRX registers
72
  SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;  // Re-enable receive FIFO operation
73
  SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;  // Clears RXFFINT flag
74
  SciaRegs.SCIFFRX.bit.RXFFIENA = 1;  // RX FIFO interrupt is enabled
75
//  SciaRegs.SCIFFRX.bit.RXFFIL = 0x1F; // 1111
76
77
  // SCIFFCT registers
78
  SciaRegs.SCIFFCT.all = 0;      // Lets leave it as it is for now
79
80
  /*
81
   * Echoback configuration
82
   */
83
  // SCICCR registers
84
  SciaRegs.SCICCR.bit.STOPBITS = 0;  // 1 stop bit
85
  SciaRegs.SCICCR.bit.PARITY = 0;    // Odd Parity - but will be disabled anyways
86
  SciaRegs.SCICCR.bit.PARITYENA = 0;  // Parity disabled
87
  SciaRegs.SCICCR.bit.LOOPBKENA = 0;  // Loopback test mode disabled
88
  SciaRegs.SCICCR.bit.ADDRIDLE_MODE = 0;  // Idle line mode
89
  SciaRegs.SCICCR.bit.SCICHAR = 7;  // 8 char bits
90
91
  // SCICTL1 registers
92
  SciaRegs.SCICTL1.bit.RXERRINTENA = 0;  // Receive error interrupt disabled
93
  SciaRegs.SCICTL1.bit.SWRESET = 0;  // Initializing operating flags to the reset condition
94
  SciaRegs.SCICTL1.bit.TXWAKE = 0;  // Wake-up mode disabled
95
  SciaRegs.SCICTL1.bit.SLEEP = 0;    // Sleep mode disabled
96
  SciaRegs.SCICTL1.bit.TXENA = 1;    // Enable transmitter
97
  SciaRegs.SCICTL1.bit.RXENA = 1;    // Enable receiver
98
99
  // SCICTL2 registers
100
  SciaRegs.SCICTL2.bit.TXRDY = 0;    // SCITXBUF is full
101
  SciaRegs.SCICTL2.bit.TXEMPTY = 0;  // Transmitter buffer is loaded with data
102
  SciaRegs.SCICTL2.bit.RXBKINTENA = 1;  // Receiver buffer interrupt enabled
103
  SciaRegs.SCICTL2.bit.TXINTENA = 1;  // TXRDY interrupt enabled
104
105
  // SCIHBAUD registers for BAUD rate
106
    SciaRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 37.5MHz.
107
    SciaRegs.SCILBAUD    =0x00E7;
108
109
    // SCICTL1 registers again
110
    SciaRegs.SCICTL1.all = 0x0023;  // WTF?
111
}
112
113
__interrupt void UART_isr(void)
114
{
115
    // Get character
116
    ReceivedChar = SciaRegs.SCIRXBUF.all;
117
    bla = ReceivedChar-'0';
118
119
  SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag
120
  SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;  // Clears RXFFINT flag to enable new incoming interrupts
121
  // Acknowledge this interrupt to get more from group 1
122
  PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
123
}

von Alexander (Gast)


Angehängte Dateien:

Lesenswert?

Hallo noch mal,
ich scheine auch nach mehrmaligem Lesen des Datenblatts und Einlesen in 
UART grundlegende Verständnisschwierigkeiten zum Thema UART RX Interrupt 
zu besitzen (Zur Info: Polling Betrieb funktioniert ohne Probleme; einen 
Hardwarefehler schließe ich entsprechend aus). Falls es zur weiteren 
Klarheit hilft, FIFO Betrieb wird verwendet.

Ich verwende HyperTerminal als Terminalprogramm.

Das Datenblatt (SPRUFZ5A) sagt auf Seite 21:
>If the RX/BK INT ENA bit (SCICTL2, bit 1) is set, the receiver peripheral 
>interrupt request is asserted when one of the following events occurs:
>The SCI receives a complete frame and transfers the data in the RXSHF register to 
>the SCIRXBUF register. This action sets the RXRDY flag (SCIRXST, bit 6) and 
>initiates an interrupt.

Ich habe den 8N1 Modus für den UART konfiguriert, der ein Start-Bit hat, 
8 Datenbits, kein Parity und ein Stop-Bit.

Meinem Verständnis nach wird jedes mal, wenn ein komplettes Datenpaket 
(Frame, also 8N1???) empfangen wurde und die Information ins SCIRXBUF 
Register geschrieben wurde, der Empfangsinterrupt ausgelöst.

Verstehe ich das bis hierhin richtig?

Jetzt frage ich mich, wie 8N1 von Hyperterminal an den DSP gesendet 
wird. Um konkret ein Beispiel zu nennen:
Wenn ich in Hyperterminal EINMAL die Taste 1 drücke und sonst nichts, 
entspricht das dann bereits 8N1 und der DSP müsste die ISR aufrufen?

Irgendwie scheine ich etwas grundlegend misszuverstehen :/

Hoffentlich kann mir jemand helfen.

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Alexander schrieb:
> Wenn ich in Hyperterminal EINMAL die Taste 1 drücke und sonst nichts,
> entspricht das dann bereits 8N1 und der DSP müsste die ISR aufrufen?

Ja.

Alexander schrieb:
> Uint16 bla;
> Uint16 ReceivedChar;

Schreib' da mal volatile davor, wenn Du die Variablen sowohl in der 
ISR als auch in Deinem Hauptprogramm anfasst.

von Alexander (Gast)


Lesenswert?

Hi Rufus,
Rufus Τ. F. schrieb:
> Ja.
Das ist schonmal eine erfreuliche Nachricht.

> Alexander schrieb:
> Schreib' da mal volatile davor, wenn Du die Variablen sowohl in der
> ISR als auch in Deinem Hauptprogramm anfasst.

Ich habe das Programm abgeändert bzw. alles meiner Ansicht nach Unnötige 
ausgeklammert, um erstmal die Basics am Laufen zu haben. Anbei der 
abgeänderte Code. Funktionalität: Bei Tastendruck soll die ISR 
aufgerufen werden, sonst nichts (keine Werte aus dem Buffer gelesen 
o.Ä.). Problem: Ich muss beim ersten Programmlauf (also nach 
Komplilieren) die Taste 17 mal drücken, bis die ISR zum ersten Mal 
aufgerufen wird. Meinem Verständnis nach müsste die ISR auch direkt nach 
Programmstart sofort aufgerufen werden, sobald eine Taste gedrückt wird. 
Sehe ich das richtig?
1
/*
2
 * This example sets up the UART to send data to and receive data from the laptop
3
 * When the data is received, an interrupt occurs and the data will then be taken from the buffer
4
 */
5
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
6
__interrupt void UART_isr(void);
7
8
void scia_init();
9
#define CR "\r\n"
10
Uint16 bla;
11
//Uint16 ReceivedChar;
12
//volatile Uint16 uart_str_count = 0;
13
//volatile char uart_string[10 + 1] = "";
14
15
16
17
void main(void) {
18
19
//  ReceivedChar=0;
20
//    bla=0;
21
22
  // Step 1: Setting the PLL, Watchdog, enable peripheral clocks
23
  InitSysCtrl();
24
25
  // Step 3: Initialize the PIE control registers
26
//  DINT; // Only necessary here if InitPieCtrl() does not have DINT; included
27
  InitPieCtrl();
28
29
  IER = 0x0000;
30
  IFR = 0x0000;
31
32
  // Step 4: Initialize the PIE vector table to default ISR
33
  InitPieVectTable();
34
35
  // Configure the interrupt handling
36
  // Setting up the XINT1 trigger, Table 112
37
  EALLOW;
38
  PieVectTable.SCIRXINTA = &UART_isr;
39
  EDIS;
40
41
  // Enable XINT1 in the PIE
42
//  PieCtrlRegs.PIECTRL.bit.ENPIE = 1;  // Enables the PIE interrupt table. Already done in InitPieVectTable();
43
  PieCtrlRegs.PIEIER9.bit.INTx1 = 1;  // Figure 87
44
  IER |= M_INT9;            // Sets the interrupt enable bit of group 9
45
  EINT;                // Enable global interrupts INTM
46
  // Step 5: Initialize other device peripherals
47
48
  // We need to initialize our SCI
49
  InitSciGpio();
50
51
  // Step 6: Write your code
52
  scia_init();  // Initialize Sci FIFO
53
54
  for(;;)
55
  {
56
         // Wait for inc character
57
//         while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state
58
  }
59
}
60
61
void scia_init()
62
{
63
  /*
64
   * FIFO configuration
65
   */
66
  // SCIFFTX registers
67
  SciaRegs.SCIFFTX.bit.SCIRST = 1;  // Sci reset
68
  SciaRegs.SCIFFTX.bit.SCIFFENA = 1;  // Sci enhancements enabled
69
  SciaRegs.SCIFFTX.bit.TXFIFOXRESET = 1;  // Re-enable transmit FIFO operation
70
  SciaRegs.SCIFFTX.bit.TXFFST = 0;  // Transmit FIFO is empty
71
  SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1;  // Clears TXFFINT flag
72
  SciaRegs.SCIFFTX.bit.TXFFIENA = 0;  // TX FIFO interrupt is disabled
73
74
  // SCIFFRX registers
75
  SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;  // Re-enable receive FIFO operation
76
  SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;  // Clears RXFFINT flag
77
  SciaRegs.SCIFFRX.bit.RXFFIENA = 1;  // RX FIFO interrupt is enabled
78
//  SciaRegs.SCIFFRX.bit.RXFFIL = 0x1F; // 1111
79
80
  // SCIFFCT registers
81
  SciaRegs.SCIFFCT.all = 0;      // Lets leave it as it is for now
82
83
  /*
84
   * Echoback configuration
85
   */
86
  // SCICCR registers
87
  SciaRegs.SCICCR.bit.STOPBITS = 0;  // 1 stop bit
88
  SciaRegs.SCICCR.bit.PARITY = 0;    // Odd Parity - but will be disabled anyways
89
  SciaRegs.SCICCR.bit.PARITYENA = 0;  // Parity disabled
90
  SciaRegs.SCICCR.bit.LOOPBKENA = 0;  // Loopback test mode disabled
91
  SciaRegs.SCICCR.bit.ADDRIDLE_MODE = 0;  // Idle line mode
92
  SciaRegs.SCICCR.bit.SCICHAR = 7;  // 8 char bits
93
94
  // SCICTL1 registers
95
  SciaRegs.SCICTL1.bit.RXERRINTENA = 0;  // Receive error interrupt disabled
96
  SciaRegs.SCICTL1.bit.SWRESET = 0;  // Initializing operating flags to the reset condition
97
  SciaRegs.SCICTL1.bit.TXWAKE = 0;  // Wake-up mode disabled
98
  SciaRegs.SCICTL1.bit.SLEEP = 0;    // Sleep mode disabled
99
  SciaRegs.SCICTL1.bit.TXENA = 1;    // Enable transmitter
100
  SciaRegs.SCICTL1.bit.RXENA = 1;    // Enable receiver
101
102
  // SCICTL2 registers
103
  SciaRegs.SCICTL2.bit.TXRDY = 0;    // SCITXBUF is full
104
  SciaRegs.SCICTL2.bit.TXEMPTY = 0;  // Transmitter buffer is loaded with data
105
  SciaRegs.SCICTL2.bit.RXBKINTENA = 1;  // Receiver buffer interrupt enabled
106
  SciaRegs.SCICTL2.bit.TXINTENA = 1;  // TXRDY interrupt enabled
107
108
  // SCIHBAUD registers for BAUD rate
109
    SciaRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 37.5MHz.
110
    SciaRegs.SCILBAUD    =0x00E7;
111
112
    // SCICTL1 registers again
113
    SciaRegs.SCICTL1.all = 0x0023;  // WTF?
114
}
115
116
__interrupt void UART_isr(void)
117
{
118
  /*
119
    unsigned char ReceivedChar;
120
    // Get character
121
    ReceivedChar = SciaRegs.SCIRXBUF.all;
122
123
    if( ReceivedChar != '\n' &&
124
        ReceivedChar != '\r' )
125
    {
126
      uart_string[uart_str_count] = ReceivedChar;
127
      uart_str_count++;
128
    }
129
    else {
130
      uart_string[uart_str_count] = '\0';
131
      uart_str_count = 0;
132
    }
133
//    bla = ReceivedChar-'0';
134
   */
135
136
  SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag
137
  SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;  // Clears RXFFINT flag to enable new incoming interrupts
138
  // Acknowledge this interrupt to get more from group 1
139
  PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
140
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.