nikhilrajg
Member level 3
- Joined
- Mar 2, 2012
- Messages
- 63
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Manipal,Karnataka,India
- Activity points
- 1,834
/***********************************************************************************************************/
/***********************************************************************************************************/
#include<p24fj128ga010.h>
#define CTS _RF12
#define RTS _RF13
#define TRTS TRISFbits.TRISF13
#define BRATE 129
#define U_ENABLE 0X8008
#define U_TX 0X0400
#define DELAY 1
void initU2()
{
U1BRG = BRATE;
U1MODE = U_ENABLE;
U1STA = U_TX;
TRTS = 0;
T1CON = 0x8030;
TMR1=0;
while(TMR1 < DELAY);
TMR1 = 0;
RTS = 1;
}
int putU2(int c)
{
while(CTS);
while(U1STAbits.UTXBF);
U1TXREG = c;
return c;
}
char getU2(void)
{
RTS = 0;
while(!U1STAbits.URXDA);
return U1RXREG;
RTS = 1;
}
//=======================================================
int putsU2(char *s)
{
printf("%s",(*s));
while(*s)
putU2(*s++);
}
char *getsnU2(char *s,int len)
{
char *p = s;
do
{
*s = getU2();
if(*s=='\r')
break;
s++;
len--;
}while(len>1);
*s = '\0';
return p;
}
//=======================================================
void main(void)
{
initU2();
while(1)
putsU2("hello\t");
}
/**********************************************************************************************************/
/**********************************************************************************************************/
printf("%s",(*s));
UART-W0005: Uart is enabled but no output destination has been assigned. (File or Output Window)
_CONFIG1(FWDTEN_OFF)
_CONFIG2(FNOSC_PRI & POSCMOD_XT)
#define U_ENABLE 0x8000 // enable UART, BRGH=0, 1 stop, no parity
void initU2(void)
{
U2BRG = BRATE; // initialize the baud rate generator
U2MODE = U_ENABLE; // initialize the UART module
U2STA = U_TX; // enable the Transmitter
TRTS = 0; // make RTS an output pin
TMR1 = 0;
while(TMR1 < delay);
TMR1=0;
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
Thanks Tahmid,
Am referring the book "Learning to Fly the PIC24 by Lucio Di Jasio". In this book he has used UART2 to connect MC to pc via RS232, in the coding part there is no initialization for U2TXREG as you mentioned that to be included for UART-2.. initialation code is as bellow please make necessary changes if there are any.,,.
Code:void initU2(void) { U2BRG = BRATE; // initialize the baud rate generator U2MODE = U_ENABLE; // initialize the UART module U2STA = U_TX; // enable the Transmitter TRTS = 0; // make RTS an output pin TMR1 = 0; while(TMR1 < delay); TMR1=0; RTS = 1; // set RTS default status (not ready) } // initU2
Please Help.
Thanks for You consideration.
Nihkil Raj.
---------- Post added at 11:23 ---------- Previous post was at 11:22 ----------
Is there any code to set U2TXREG ??
Thanks.
Nikhil Raj
---------- Post added at 11:26 ---------- Previous post was at 11:23 ----------
values for BRATE = 25 (9600) and U_ENABLE = 0x8000 & U_TX = 0x0400
Thanks.
Nikhill Raj
---------- Post added at 12:26 ---------- Previous post was at 11:26 ----------
Hello Tahmid,
Finally I got the out put on the terminal. Thank you very much for your great help. The error was in the CTS.. When I run the program the controll will be stuck in clearing the CTS line in the putU2() function as bellow.
Code: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
So i commented the line. After commenting its working properly now. Is there any idea why is it so ?
And will it effect on MC or the program result ? Is there other solution for this problem.
Thank you very much.
Nikhil Raj.
Thanks Tahmid,
Now I am able to get the output to write to hyperterminal. But now I am trying to communicate both ways facing problems in receiving data from hyper-terminal. Is it possible to get the received data from the hyper terminal to be printed on some other editor ?
or else on the same editor in which I am debugging the code such as on UART ?
I think UART is not possible because we can see the UART window only in simulator mode... Is there any particular and easy method to fetch the data from hyper-terminal and to display somewhere on the editor ?
Thanks a ton
Nikhil Raj
---------- Post added at 16:58 ---------- Previous post was at 16:39 ----------
Hello,
How to read the data from hyper-terminal if I type something on the terminal PIM should reply for that for example...,
If I type "AT" on hyper-terminal I should get the reply on hyper-terminal itself as "OK" how to do this ? Please explain the ligic. Great appreciation for the your reply.
Thank You very Much.
Nikhil Raj.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?