View previous topic :: View next topic |
Author |
Message |
drolleman Guest
|
serial 16f688 TXIF never sets |
Posted: Fri Apr 15, 2005 12:22 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 12:49 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 2:27 pm |
|
|
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: 1907
|
|
Posted: Fri Apr 15, 2005 2:52 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 2:55 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 3:01 pm |
|
|
the version is pcm 3.184 |
|
|
drolleman Guest
|
|
Posted: Fri Apr 15, 2005 3:04 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 3:23 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 3:59 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 4:01 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 4:13 pm |
|
|
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
|
|
Posted: Fri Apr 15, 2005 5:02 pm |
|
|
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. |
|
|
|