CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

serial 16f688 TXIF never sets

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
drolleman
Guest







serial 16f688 TXIF never sets
PostPosted: Fri Apr 15, 2005 12:22 pm     Reply with quote

I'm trying to send one byte a a time serially I was using the 648 but moved to the 688. i usually wait for the TXIF to go high and then send the next char but the 688 TXIF never goes high. According to the data sheet by setting the TXEN the TXIF will go high but it doesn't. also the flag TRMT is normally high but after i send a byte to TXREG it goes low and stays there. has anyone used this chip to do this?

#include <16f688.h>

#fuses INTRC_IO,NOWDT,NOPROTECT,NOBROWNOUT,noPUT,NOMCLR//,CPD//NOLVP,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_c4, rcv=PIN_c5, errors, enable=pin_c3) // Jumpers: 8

#bit frerror = 0x18.2
#byte TXREG1 = 0x15
#byte TXSTA1 = 0x16
#byte RCREG1 = 0x14
#byte RCSTA1 = 0x17
#bit RecieveFlag = 0x0c.5

#bit TXIF1 = 0x0c.1
#bit TRMT1 = 0x16.1
#bit TXEN1 = 0x16.5
#bit cren1 = 0x17.4
#byte spbrg = 0x13


#bit OERR1=0x17.1
#bit FERR1=0x17.2
#bit CREN1=0x17.4
#bit SPEN1=0x17.7
#bit ABDEN=0x11.0
#bit WUE=0x11.1
#bit ADDEN=0x17.3
#bit RX9=0x17.6
#bit SPEN = 0x17.1
#bit SYNC = 0x16.4


main()
{
char h;
int y;
output_high(pin_a2);// prove we are alive
delay_ms(100);
output_low(pin_a2);

SYNC = 0;
SPEN = 1;
TXEN1 = 1;
// h = getc();
// TXEN1 = 1;
// SYNC = 0;
// SPEN = 1;
// TXEN1 = 1;

if(TXIF1){output_high(pin_a2);
delay_ms(400);
output_low(pin_a2);
}


if(TRMT1)output_high(pin_a3);
else output_low(pin_a3);

printf("\r\nTXIF %u\r\n",TXIF1);
printf("ABDEN %u\r\n",ABDEN);
printf("WUE %u\r\n",WUE);
printf("ADDEN %u\r\n",ADDEN);
printf("TRMT1 %u\r\n",TRMT1);
printf("SPEN %u\r\n",SPEN);
}
results

TXIF 0
ABDEN 0
WUE 0
ADDEN 0
TRMT1 1
SPEN 0
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 15, 2005 12:49 pm     Reply with quote

Are you aware that the CCS #use rs232() statement will handle all
of this for you ?

Also, your definitions don't match the 16F688 data sheet.
I glanced at them and noticed they seemed a little odd.

You've got this one here, SPEN, set to bit 1, but it's really bit 7.
#bit SPEN = 0x17.1
So down in your code where you've got,
SPEN = 1;
you think you're turning on the UART, but you're really not.

I suggest you let CCS do it. Use the built-in functions.
Guest








PostPosted: Fri Apr 15, 2005 2:27 pm     Reply with quote

The processor must handle other tasks while the data is sent out , so i need to test if the uart is able to take the next charater. i changed the location and still no results.
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Fri Apr 15, 2005 2:52 pm     Reply with quote

You want the TBE (transmit buffer empty) interrupt. It does exactly what you need.

Try the code found in this thread:

http://www.ccsinfo.com/forum/viewtopic.php?t=22221&highlight=intrda

It's a little complex, but it does what you want. If the USART receives a buffer, then int_RDA (receive data available) is called. If you want to send something out the USART, just use
Code:
bputc("whatever you want to send here").


The code automatically handles filling the transmit buffer, and refilling it for you until the entire message has been sent. The processor can then do anything else you want.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 15, 2005 2:55 pm     Reply with quote

Can you post the version of your compiler ?
It is given at the top of the .LST file, which is produced when you
compile a program.
drolleman
Guest







PostPosted: Fri Apr 15, 2005 3:01 pm     Reply with quote

the version is pcm 3.184
drolleman
Guest







PostPosted: Fri Apr 15, 2005 3:04 pm     Reply with quote

unfortunatly i cannot use the intrupts because of time critical events. i squeeze the serial transmissions in between these events.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 15, 2005 3:23 pm     Reply with quote

PCM vs. 3.184 doesn't properly support the hardware UART on the
16F688. It generates code for a software UART. Now I can see why
you were trying to directly write to the registers.

Do you still want to try to make it work with your version, or do
you want to upgrade the compiler ?
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Fri Apr 15, 2005 3:59 pm     Reply with quote

drolleman wrote:
unfortunatly i cannot use the intrupts because of time critical events. i squeeze the serial transmissions in between these events.


Even if you don't use interrupts, you can use the code that someone just linked and poll the TBE bit instead of using the TBE interrupt. That way you're polling the TBE and transmitting in between those events.
drolleman
Guest







PostPosted: Fri Apr 15, 2005 4:01 pm     Reply with quote

when i use the printf method it works fine its when i try to use the actual bits it fails if TXEN and TXIF wold work evewrythig would be fine. or if ccs would have an equivelent of kbhit() for the transmit.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 15, 2005 4:13 pm     Reply with quote

Printf does not send characters to the hardware UART in your version
of the compiler. It toggles pins C4 and C5 with code. It never writes
to the TXREG register. So it doesn't matter what TXIF does in your
version, because printf doesn't use it.
drolleman
Guest







PostPosted: Fri Apr 15, 2005 5:02 pm     Reply with quote

thanks that explains a few problems. but for now i'll use the 648, updating for just that problem will be hard to get the money for it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group