Hallo zusammen,
ich habe hier einen PIC24FV32KA301 mit dem ich Text über UART übertragen
will.
Den nötigen Code habe ich mir zum größten Teil vom Code Configurator in
MPLAB X generieren lasse. Ich habe den generierten Code natürchlich auch
schon selber durch geschaut, aber habe keinen Fehler des Generators
gefunden.
In der main habe ich dann nur noch diesen einfachen Code.
1 | char buffer[50] = "Hallo-Welt123\n";
|
2 |
|
3 | SYSTEM_Initialize();
|
4 |
|
5 | __delay_ms(10);
|
6 |
|
7 | while(1)
|
8 | {
|
9 | UART1_WriteBuffer((const uint8_t*)buffer, strlen(buffer));
|
10 | __delay_ms(1000);
|
11 | }
|
12 |
|
13 | return 0;
|
auf dem PC emfange ich aber nur abwechselnd
HalloWl13<\n>
l1lHal-et2<\n>
der Initialisierungs Code des UART sieht so aus
1 | #define UART1_CONFIG_TX_BYTEQ_LENGTH 100
|
2 | #define UART1_CONFIG_RX_BYTEQ_LENGTH 100
|
3 |
|
4 | static uint8_t uart1_txByteQ[UART1_CONFIG_TX_BYTEQ_LENGTH] ;
|
5 | static uint8_t uart1_rxByteQ[UART1_CONFIG_RX_BYTEQ_LENGTH] ;
|
6 |
|
7 | void UART1_Initialize (void)
|
8 | {
|
9 | // STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; RXINV disabled; UEN TX_RX;
|
10 | U1MODE = (0x8008 & ~(1<<15)); // disabling UARTEN bit
|
11 | // UTXISEL0 TX_ONE_CHAR; UTXINV disabled; OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled;
|
12 | U1STA = 0x0000;
|
13 | // BaudRate = 9600; Frequency = 4000000 Hz; BRG 103;
|
14 | U1BRG = 0x0067;
|
15 |
|
16 | IEC0bits.U1RXIE = 1;
|
17 |
|
18 | //Make sure to set LAT bit corresponding to TxPin as high before UART initialization
|
19 | U1MODEbits.UARTEN = 1; // enabling UART ON bit
|
20 | U1STAbits.UTXEN = 1;
|
21 |
|
22 |
|
23 |
|
24 | uart1_obj.txHead = uart1_txByteQ;
|
25 | uart1_obj.txTail = uart1_txByteQ;
|
26 | uart1_obj.rxHead = uart1_rxByteQ;
|
27 | uart1_obj.rxTail = uart1_rxByteQ;
|
28 | uart1_obj.rxStatus.s.empty = true;
|
29 | uart1_obj.txStatus.s.empty = true;
|
30 | uart1_obj.txStatus.s.full = false;
|
31 | uart1_obj.rxStatus.s.full = false;
|
32 | }
|
vielleicht kann mir ja jemand weiter helfen.