Hi
Versuche gerade den UART auf dsPIC33 zu initialisieren, erhalte aber
folgende Fehlermeldung beim Builden. Kann mir jemand weiterhelfen?
serial.c: In function `initU2':
serial.c:23: error: `TRTS' undeclared (first use in this function)
serial.c:23: error: (Each undeclared identifier is reported only once
serial.c:23: error: for each function it appears in.)
serial.c: At top level:
serial.c:45: warning: return type defaults to `int'
Hier der Sourcecode:
//----------------------------------------------------------------------
-------
// Asinchronous Serial communication
// UART RS232 asynchronous communication demo code
//----------------------------------------------------------------------
-------
#include "p33FJ64MC508.h"
//----------------------------------------------------------------------
-------
// I/O definitions for the dsPIC30 Motor Control Dev board
//----------------------------------------------------------------------
-------
# define CTS _RG3 // Clear to Send, input, HW handshake
# define RTS _RG2 // Request to Send, output, HW
handshake
# define TRTSTRISGbits .TRISG2 // Tris control for RTS pin
# define BRATE 34 // 115200 Bd (BREGH=1)
# define U_ENABLE 0x8008 // enable UART, BREGH=1, 1 stop, no
parity
# define U_TX 0x0400
//----------------------------------------------------------------------
-------
// Initialization of UART 2 module
//----------------------------------------------------------------------
-------
void initU2(void){
U2BRG = BRATE; // initialize the baud rate generator
U2MODE = U_ENABLE; // initialize the UART module
TRTS = 0; // make RTS an output pin
RTS = 1; // set RTS default status (not ready)
} // initU2
int putU2(int c){
while(CTS); // wait for !CTS, clear to send
while(U2STAbits.UTXBF); // wait while Tx buffer full
U2TXREG = c;
return c;
} // putU2
char getU2(void){
RTS = 0; // assert Request To Send !RTS
while(!U2STAbits.URXDA); // wait for a new character to arrive
return U2RXREG; // read the character from the receive buffer
RTS = 1;
} // getU2
//----------------------------------------------------------------------
-------
// Main routine
//----------------------------------------------------------------------
-------
main()
{
char c;
initU2(); // init the UART2 serial port
putU2('>'); // prompt
while(1){
c = getU2(); // wait for character
putU2(c); // echo the character
} // while
} //main