Sign in

username:

password:



Not a member?

Search piclist



Search tips

Subscribe to piclist



piclist by Keywords

12F675 | 16F628 | 16F84 | 16f877 | 16F877A | 16F88 | 18F458 | ADC | AVR | Bootloader | CAN | CCS | CRC | EAGLE | EEPROM | ICD | ICSP | IDE | JDM | LED | Macros | Microchip | MPLAB | PCB-CAD | PIC10F | Pic12f675 | PIC16F84 | PIC16F84A | PIC16F877 | PIC18 | PIC18F452 | PicBasic | PICC | PICSTART | PWM | RS-485 | RS232 | SMT | SPI | UART | USART | USB | Wireless | Wisp628 | Xilinx

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | Piclist | pic16f877a uart problem

A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.

pic16f877a uart problem - siva...@gmail.com - Nov 11 3:25:06 2008

Hai to all,

Iam trying to communicate from pic 16f877a to the pc's hyperterminal at 9600 baud rate. Iam posting my code for this.
Iam able to simulate with mplab but I could not implement with hardware. I checked for max232, rs232. They seem to be working perfect. But iam not getting the data through hyperterminal comm port.

My crystal oscillator is 8mhz.
/* uart serial communication at 9600 baud rate*/
/*spbrg=(8Mhz/(9600)/16)-1*/

#include
//unsigned char data[6]="fabmax";
unsigned char i;
/*void interrupt isr(void)
{
if(TXIF==1)
{

for(i=0;i<=5;i++)
TXREG=data[i]; //transmitted data
}
if(RCIF==1)
{
for(i=0;i<=5;i++)
data[i]=RCREG; //received data
}
}*/
void main (void)
{
// unsigned char data[6]="fabmax";
unsigned char i;
TRISC6=0;
TRISC7=1;
SPBRG=0x33; // for 9600 baoud rate
// GIE=1;
// PEIE=1;
BRGH=1;
SPEN=1; //serial comm enabled
SYNC=0; //synchronous mode disabled
// TXIE=1;
// RCIE=1;
TXEN=1; //transmission enabled
// RCEN=1;
while(1)
{
TXREG='f';
TXREG='z';
}
}

------------------------------------

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions



(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )


Re: pic16f877a uart problem - Michael Harpe - Nov 11 8:11:44 2008

Triple check your settings for the baud rate. I had trouble with that. The bit rate generator has two modes and the calculation is different for each mode.
 
Mike Harpe

--- On Tue, 11/11/08, s...@gmail.com wrote:

From: s...@gmail.com
Subject: [piclist] pic16f877a uart problem
To: p...@yahoogroups.com
Date: Tuesday, November 11, 2008, 3:24 AM

Hai to all,

Iam trying to communicate from pic 16f877a to the pc's hyperterminal at
9600 baud rate. Iam posting my code for this.
Iam able to simulate with mplab but I could not implement with hardware. I
checked for max232, rs232. They seem to be working perfect. But iam not getting
the data through hyperterminal comm port.

My crystal oscillator is 8mhz.
/* uart serial communication at 9600 baud rate*/
/*spbrg=(8Mhz/(9600)/16)-1*/

#include
//unsigned char data[6]="fabmax";
unsigned char i;
/*void interrupt isr(void)
{
if(TXIF==1)
{

for(i=0;i<=5;i++)
TXREG=data[i]; //transmitted data
}
if(RCIF==1)
{
for(i=0;i<=5;i++)
data[i]=RCREG; //received data
}
}*/
void main (void)
{
// unsigned char data[6]="fabmax";
unsigned char i;
TRISC6=0;
TRISC7=1;
SPBRG=0x33; // for 9600 baoud rate
// GIE=1;
// PEIE=1;
BRGH=1;
SPEN=1; //serial comm enabled
SYNC=0; //synchronous mode disabled
// TXIE=1;
// RCIE=1;
TXEN=1; //transmission enabled
// RCEN=1;
while(1)
{
TXREG='f';
TXREG='z';
}
}

------------------------------------

to unsubscribe, go to http://www.yahoogroups.com and follow the
instructionsYahoo! Groups Links



(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: pic16f877a uart problem - demolitron - Nov 11 12:06:44 2008

Hello,

See my comments below...

--- In p...@yahoogroups.com, siva.gram@... wrote:
>
> Hai to all,
>
> Iam trying to communicate from pic 16f877a to the pc's hyperterminal
at 9600 baud rate. Iam posting my code for this.
> Iam able to simulate with mplab but I could not implement with
hardware. I checked for max232, rs232. They seem to be working
perfect. But iam not getting the data through hyperterminal comm port.
>
> My crystal oscillator is 8mhz.
> /* uart serial communication at 9600 baud rate*/
> /*spbrg=(8Mhz/(9600)/16)-1*/
>
> #include
> //unsigned char data[6]="fabmax";
> unsigned char i;
> /*void interrupt isr(void)
> {
> if(TXIF==1)
> {
>
> for(i=0;i<=5;i++)
> TXREG=data[i]; //transmitted data
> }
> if(RCIF==1)
> {
> for(i=0;i<=5;i++)
> data[i]=RCREG; //received data
> }
> }*/
> void main (void)
> {
> // unsigned char data[6]="fabmax";
> unsigned char i;
> TRISC6=0;
> TRISC7=1;
> SPBRG=0x33; // for 9600 baoud rate
> // GIE=1;
> // PEIE=1;
> BRGH=1;
> SPEN=1; //serial comm enabled
> SYNC=0; //synchronous mode disabled
> // TXIE=1;
> // RCIE=1;
> TXEN=1; //transmission enabled
> // RCEN=1;
> while(1)
> {
> TXREG='f';
> TXREG='z';
Above: You are putting data into the TXREG but there is no delay
before you put another character in. You'll need to check the TRMT
bit in the TXSTA register. IE.

while(!TRMT); //Do nothing while waiting for the TSR is still full

Your interrupt routine seems to be spot on to account for that. At
8MHz clock and 9600 Baud it takes approximately 1875 instruction
cycles to transmit one byte (8 data bits + 1 stop bit).
> }
> }
>

Good luck! I've had more than a few problems dealing with RS232, all
because of a strange mistake here and there. Also, double check your
connections to the PC's serial port. I've messed that up before as well.
------------------------------------

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions



(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: Re: pic16f877a uart problem - JCullins - Nov 11 12:11:34 2008

make sure you turn off handshaking in Hyperterminal.
Jim

----- Original Message ----
From: demolitron
To: p...@yahoogroups.com
Sent: Tuesday, November 11, 2008 11:06:14 AM
Subject: [piclist] Re: pic16f877a uart problem

Hello,

See my comments below...

--- In p...@yahoogroups.com, siva.gram@... wrote:
>
> Hai to all,
>
> Iam trying to communicate from pic 16f877a to the pc's hyperterminal
at 9600 baud rate. Iam posting my code for this.
> Iam able to simulate with mplab but I could not implement with
hardware. I checked for max232, rs232. They seem to be working
perfect. But iam not getting the data through hyperterminal comm port.
>
> My crystal oscillator is 8mhz.
> /* uart serial communication at 9600 baud rate*/
> /*spbrg=(8Mhz/(9600)/16)-1*/
>
> #include
> //unsigned char data[6]="fabmax";
> unsigned char i;
> /*void interrupt isr(void)
> {
> if(TXIF==1)
> {
>
> for(i=0;i<=5;i++)
> TXREG=data[i]; //transmitted data
> }
> if(RCIF==1)
> {
> for(i=0;i<=5;i++)
> data[i]=RCREG; //received data
> }
> }*/
> void main (void)
> {
> // unsigned char data[6]="fabmax";
> unsigned char i;
> TRISC6=0;
> TRISC7=1;
> SPBRG=0x33; // for 9600 baoud rate
> // GIE=1;
> // PEIE=1;
> BRGH=1;
> SPEN=1; //serial comm enabled
> SYNC=0; //synchronous mode disabled
> // TXIE=1;
> // RCIE=1;
> TXEN=1; //transmission enabled
> // RCEN=1;
> while(1)
> {
> TXREG='f';
> TXREG='z';
Above: You are putting data into the TXREG but there is no delay
before you put another character in. You'll need to check the TRMT
bit in the TXSTA register. IE.

while(!TRMT); //Do nothing while waiting for the TSR is still full

Your interrupt routine seems to be spot on to account for that. At
8MHz clock and 9600 Baud it takes approximately 1875 instruction
cycles to transmit one byte (8 data bits + 1 stop bit).
> }
> }
>

Good luck! I've had more than a few problems dealing with RS232, all
because of a strange mistake here and there. Also, double check your
connections to the PC's serial port. I've messed that up before as well.
------------------------------------

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions


(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: pic16f877a uart problem - siva...@gmail.com - Nov 12 4:21:29 2008

thanks for all,
I was able to transmit and also receive my data to the pc... The problem was with my board as well as with some code changes here and there.

Thanks,
siva

Hai to all,
>
>Iam trying to communicate from pic 16f877a to the pc's hyperterminal at 9600 baud rate. Iam posting my code for this.
>Iam able to simulate with mplab but I could not implement with hardware. I checked for max232, rs232. They seem to be working perfect. But iam not getting the data through hyperterminal comm port.
>
>My crystal oscillator is 8mhz.
>/* uart serial communication at 9600 baud rate*/
>/*spbrg=(8Mhz/(9600)/16)-1*/
>
>#include
>//unsigned char data[6]="fabmax";
>unsigned char i;
>/*void interrupt isr(void)
>{
>if(TXIF==1)
>{
>
>for(i=0;i

------------------------------------

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: pic16f877a uart problem - Phil Birkelbach - Dec 1 19:42:34 2008

My guess is that you are resetting the USART by constantly writing to
TXREG. The uC scan is going to be much faster than the USART shift
register. Your while loop should watch for TXIF to go high and then
load the next character that you want to send. TXIF will work
regardless of whether or not you have interrupts enabled.

Phil

On Nov 11, 2008, at 2:24 AM, s...@gmail.com wrote:

> Hai to all,
>
> Iam trying to communicate from pic 16f877a to the pc's hyperterminal
> at 9600 baud rate. Iam posting my code for this.
> Iam able to simulate with mplab but I could not implement with
> hardware. I checked for max232, rs232. They seem to be working
> perfect. But iam not getting the data through hyperterminal comm port.
>
> My crystal oscillator is 8mhz.
> /* uart serial communication at 9600 baud rate*/
> /*spbrg=(8Mhz/(9600)/16)-1*/
>
> #include
> //unsigned char data[6]="fabmax";
> unsigned char i;
> /*void interrupt isr(void)
> {
> if(TXIF==1)
> {
>
> for(i=0;i<=5;i++)
> TXREG=data[i]; //transmitted data
> }
> if(RCIF==1)
> {
> for(i=0;i<=5;i++)
> data[i]=RCREG; //received data
> }
> }*/
> void main (void)
> {
> // unsigned char data[6]="fabmax";
> unsigned char i;
> TRISC6=0;
> TRISC7=1;
> SPBRG=0x33; // for 9600 baoud rate
> // GIE=1;
> // PEIE=1;
> BRGH=1;
> SPEN=1; //serial comm enabled
> SYNC=0; //synchronous mode disabled
> // TXIE=1;
> // RCIE=1;
> TXEN=1; //transmission enabled
> // RCEN=1;
> while(1)
> {
> TXREG='f';
> TXREG='z';
> }
> }
>
> ------------------------------------
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions



(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: pic16f877a uart problem - kmansfie - Dec 1 19:42:36 2008

One thing I noticed is you aren't waiting for the character to be sent
before sending the next one. You need to create a loop something like
this so that the character has a chance to be sent.
while (TRMT == 0)
;
TXREG='f';
while (TRMT == 0)
;
TXREG='z';

The while loop will stop the processor till the character is sent or
as long as the Transmit Shift Register is full (equal to zero). And,
as has already been mentioned triple check your baud rate.

kmansfie

--- In p...@yahoogroups.com, siva.gram@... wrote:
>
> Hai to all,
>
> Iam trying to communicate from pic 16f877a to the pc's hyperterminal
at 9600 baud rate. Iam posting my code for this.
> Iam able to simulate with mplab but I could not implement with
hardware. I checked for max232, rs232. They seem to be working
perfect. But iam not getting the data through hyperterminal comm port.
>
> My crystal oscillator is 8mhz.
> /* uart serial communication at 9600 baud rate*/
> /*spbrg=(8Mhz/(9600)/16)-1*/
>
> #include
> //unsigned char data[6]="fabmax";
> unsigned char i;
> /*void interrupt isr(void)
> {
> if(TXIF==1)
> {
>
> for(i=0;i<=5;i++)
> TXREG=data[i]; //transmitted data
> }
> if(RCIF==1)
> {
> for(i=0;i<=5;i++)
> data[i]=RCREG; //received data
> }
> }*/
> void main (void)
> {
> // unsigned char data[6]="fabmax";
> unsigned char i;
> TRISC6=0;
> TRISC7=1;
> SPBRG=0x33; // for 9600 baoud rate
> // GIE=1;
> // PEIE=1;
> BRGH=1;
> SPEN=1; //serial comm enabled
> SYNC=0; //synchronous mode disabled
> // TXIE=1;
> // RCIE=1;
> TXEN=1; //transmission enabled
> // RCEN=1;
> while(1)
> {
> TXREG='f';
> TXREG='z';
> }
> }
>

------------------------------------

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions



(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )