Hallo,
ich habe ein kleines Problem mit meinem dsPIC33FJ16GS404.
Ich möchte mit meinem PIC über ein Terminalprogramm mit meinem PC
kommunizieren.
Zuerst möchte ich mich auf das senden konzentieren... nur leider schickt
mein PIC nichts raus. D.h. ich kann mit meinem Oszi nichts am TX-Pin
messen.
RTS soll mein RP0 bzw. RB0 sein
CTS soll mein RP9 bzw. RB9 sein
TX soll mein RP25 bzw. RC9 sein
RX soll mein RP10 bzw. RB10 sein
Folgendes habe ich im Code gemacht:
Definieren der Baudrate:
1 | #define FP 4000000
|
2 | #define BAUDRATE 9600
|
3 | #define BRGVAL ((FP/BAUDRATE)/16)-1
|
Configuration Bits
1 | #pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
|
2 | #pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment)
|
3 |
|
4 | // FGS
|
5 | #pragma config GWRP = OFF // General Code Segment Write Protect (General Segment may be written)
|
6 | #pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)
|
7 |
|
8 | // FOSCSEL
|
9 | #pragma config FNOSC = FRC // Oscillator Source Selection (Internal Fast RC (FRC))
|
10 | #pragma config IESO = ON // Internal External Switch Over Mode (Start up device with FRC, then automatically switch to user-selected oscillator source)
|
11 |
|
12 | // FOSC
|
13 | #pragma config POSCMD = NONE // Primary Oscillator Source (Primary oscillator disabled)
|
14 | #pragma config OSCIOFNC = ON // OSC2 Pin Function (OSC2 is not clock output)
|
15 | #pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration)
|
16 | #pragma config FCKSM = CSECMD // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled, Mon Disabled)
|
17 |
|
18 | // FWDT
|
19 | #pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768)
|
20 | #pragma config WDTPRE = PR128 // WDT Prescaler (1:128)
|
21 | #pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
|
22 | #pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)
|
23 |
|
24 | // FPOR
|
25 | #pragma config FPWRT = PWR128 // POR Timer Value (128ms)
|
26 |
|
27 | // FICD
|
28 | #pragma config ICS = PGD2 // Comm Channel Select (Communicate on PGC2/EMUC2 and PGD2/EMUD2)
|
29 | #pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is disabled)
|
Und hier meine Main
1 | int main(void) {
|
2 |
|
3 | /* Configure PLL prescaler, PLL postscaler, PLL divisor */
|
4 | PLLFBD=41; /* M = PLLFBD + 2 */
|
5 | CLKDIVbits.PLLPOST=0; /* N1 = 2 */
|
6 | CLKDIVbits.PLLPRE=0; /* N2 = 2 */
|
7 |
|
8 | __builtin_write_OSCCONH(0x01); /* New Oscillator FRC w/ PLL */
|
9 | __builtin_write_OSCCONL(0x01); /* Enable Switch */
|
10 |
|
11 | while(OSCCONbits.COSC != 0b001); /* Wait for new Oscillator to become FRC w/ PLL */
|
12 | while(OSCCONbits.LOCK != 1); /* Wait for Pll to Lock */
|
13 |
|
14 | //Ports Initialisieren
|
15 | ADPCFG = 0xFFFF; //Alle Ports auf Digital
|
16 |
|
17 | TRISA = 0x00; //Ein- und Ausgänge festlegen
|
18 | LATA = 0x0024; //Alles auf 0 Setzen, bis auf PWM PINS
|
19 |
|
20 | TRISB = 0x7C10; //Ein- und Ausgänge festlegen
|
21 | LATB = 0x0000; //Alles auf 0 Setzen
|
22 |
|
23 | TRISC = 0x2208; //Ein- und Ausgänge festlegen
|
24 | LATC = 0x0000; //Alles auf 0 Setzen
|
25 |
|
26 |
|
27 |
|
28 | //Initialisieren UART
|
29 | RPINR18 = 0x90A; //CTS und RX Pins festlegen
|
30 | RPOR0 = 0x4; //RTS Pin festlegen
|
31 | RPOR12 = 0x3; //TX Pin festlegen
|
32 |
|
33 | U1MODEbits.STSEL = 0; // 1-Stop bit
|
34 | U1MODEbits.PDSEL = 0; // No Parity, 8-Data bits
|
35 | U1MODEbits.ABAUD = 0; // Auto-Baud disabled
|
36 | U1MODEbits.BRGH = 0; // Standard-Speed mode
|
37 | U1MODEbits.RTSMD = 0; // Flow Control mode
|
38 | U1MODEbits.UEN1 = 0; // UxTX and UxRX pins are enabled and used; UxCTS, UxRTS and BCLKx pins are controlled by port latches
|
39 |
|
40 | U1MODEbits.UEN0 = 0; // UxTX and UxRX pins are enabled and used; UxCTS, UxRTS and BCLKx pins are controlled by port latches
|
41 |
|
42 | U1BRG = BRGVAL; // Baud Rate setting for 9600
|
43 |
|
44 | U1MODEbits.UARTEN = 1; // Enable UART
|
45 | U1STAbits.UTXEN = 1; // Enable UART TX
|
46 | __delay_ms(10); // Delay von 10ms
|
47 |
|
48 | int Data=65;
|
49 | //LATBbits.LATB0 = 1;
|
50 |
|
51 | while(1)
|
52 | { if(!IFS0bits.U1TXIF)
|
53 | U1TXREG = Data;
|
54 | else
|
55 | {
|
56 | IFS0bits.U1TXIF = 0;
|
57 | }
|
58 | }
|
59 |
|
60 | return 0;
|
61 | }
|
Ich wollte hier nur mal zum Test ständig meine 65 schicken und am
Terminal empfangen. Mein µC gibt aber gar nichts raus. Es sieht so aus,
als würde er die Daten in den Buffer schreiben und einfach nicht los
schicken.
Hab ich im Code was falsch gemacht? Vllt was vergessen?
Über eure Hilfe wäre ich sehr dankbar!!