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

Hardware UART 16f876A

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



Joined: 24 Nov 2003
Posts: 5

View user's profile Send private message

Hardware UART 16f876A
PostPosted: Mon Nov 24, 2003 5:06 am     Reply with quote

I'm currently working on a Hardware UART RS232 on 16f876A.

I can send with printf, but i can't receive any characters.

I tried several code snippets found in this forum, but i can't get it to work.

I want to use a #int_RDA driven version, but it just enters the ISR once and doesn't receive any characters.

The UART is connected to a max233a so i doesn't need INVERT?!
I also used the "Errors" in #use_rs232

Anyone got a working code for me?
Excuse my bad english
dyeatman



Joined: 06 Sep 2003
Posts: 1912
Location: Norman, OK

View user's profile Send private message

Hardware UART
PostPosted: Mon Nov 24, 2003 7:18 am     Reply with quote

It is hard to comment on something we cannot see. How about posting the code you are using that enters the RDA routine once so we can see what you have and comment on where you may have problems..
m3ph



Joined: 24 Nov 2003
Posts: 5

View user's profile Send private message

PostPosted: Mon Nov 24, 2003 7:54 am     Reply with quote

I checked RCSTA after sending a character and it seems like i'm getting a frame error(RCSTA=94).
it still doesn't enter the isr more than once ( next_in stays 1)
do i have to clear a flag?
How are stopbits handled in ccs?
what's the default stop bit value?

here's my code:
#include <16f876a.h>
#include <stdlib.h>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(CLOCK = 20000000)
#use rs232 (BAUD = 9600, XMIT = PIN_C6, RCV = PIN_C7, PARITY=N, BITS=8/*,errors*/) //commented out for debug

#define BUFFER_SIZE 2
char RS_buffer[BUFFER_SIZE];
int next_in=0;
int received=0;
#byte RCSTA=0x18

#int_rda
rda_isr()
{
//if( kbhit() ){
RS_buffer[next_in] = getc();
next_in++;
/*if(next_in >= BUFFER_SIZE) // Buffer is full !!!
{
next_in = 0; //keep your pointer ready for next int_rda
received=1;*/
//} // in the main
//}
}

void main() {

setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
enable_interrupts( INT_RDA );
enable_interrupts( GLOBAL );

printf("TEST");
while (1)
{

printf("Received %s \n", RS_buffer[0]);
printf("Received %u \n", RS_buffer[0]);
delay_ms(1000);
printf("Status: %x\n",RCSTA);
printf("int: %U",next_in);
output_high(PIN_C1);
delay_ms(2000);
output_low(PIN_C1);
}
}
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Nov 24, 2003 8:35 am     Reply with quote

Try something simple first. Just catch a byte in the interupt and toggle a pin from main when you flag is set. If you follow this aproach you will see where your problem is.
m3ph



Joined: 24 Nov 2003
Posts: 5

View user's profile Send private message

PostPosted: Mon Nov 24, 2003 8:53 am     Reply with quote

I'm new to pics
I'm getting Status 90, Buffer 1 until I hit a key.
then it switches to status 94, Buffer 0

if i put the errors in use rs232
I'm getting status 90 buffer 1 and when i hit a key
then it switches to status 94 buffer stays at 1

Is there an error in the code?
so here it is:
#include <16f876a.h>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(CLOCK = 20000000)
#use rs232 (BAUD = 9600, XMIT = PIN_C6, RCV = PIN_C7, PARITY=N, BITS=8/*,errors*/)

#define BUFFER_SIZE 2
char RS_buffer[BUFFER_SIZE];
int next_in=0;
int bufferfree=1;
int received=0;
#byte RCSTA=0x18

#int_rda
rda_isr()
{
if( bufferfree ){
RS_buffer[0] = getc();
bufferfree=0;
}
}

void main() {

enable_interrupts( INT_RDA );
enable_interrupts( GLOBAL );
printf("TEST");
while (1)
{
printf("Buffer %u\n", bufferfree);
printf("Status: %x\n",RCSTA);
delay_ms(1000);
}
}
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Nov 24, 2003 9:12 am     Reply with quote

Try going with something simpler.

Code:

#int_rda
rda_isr()
{
  RS_buffer[0] = getc();
  bufferfree=!bufferfree;
}


Now in main assign a pin to be equal to the bit bufferfree.

You have a problem in that you are ignoring imcomming bytes while your buffer is not free. You must always use getc(); from the recieve interupt.
m3ph



Joined: 24 Nov 2003
Posts: 5

View user's profile Send private message

PostPosted: Wed Nov 26, 2003 5:13 pm     Reply with quote

thx! Very Happy i'm going to test it tomorrow.

If anyone got antoher idea pls let me know!
m3ph



Joined: 24 Nov 2003
Posts: 5

View user's profile Send private message

PostPosted: Thu Nov 27, 2003 4:15 am     Reply with quote

Hi!

After i build a USB/rs232 circuit (FTDI Chip) i found out, that there's a problem with my RS232 circui (Max233a)

The program works now!
THX a lot!
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