View previous topic :: View next topic |
Author |
Message |
m3ph
Joined: 24 Nov 2003 Posts: 5
|
Hardware UART 16f876A |
Posted: Mon Nov 24, 2003 5:06 am |
|
|
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: 1933 Location: Norman, OK
|
Hardware UART |
Posted: Mon Nov 24, 2003 7:18 am |
|
|
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
|
|
Posted: Mon Nov 24, 2003 7:54 am |
|
|
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
|
|
Posted: Mon Nov 24, 2003 8:35 am |
|
|
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
|
|
Posted: Mon Nov 24, 2003 8:53 am |
|
|
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
|
|
Posted: Mon Nov 24, 2003 9:12 am |
|
|
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
|
|
Posted: Wed Nov 26, 2003 5:13 pm |
|
|
thx! i'm going to test it tomorrow.
If anyone got antoher idea pls let me know! |
|
|
m3ph
Joined: 24 Nov 2003 Posts: 5
|
|
Posted: Thu Nov 27, 2003 4:15 am |
|
|
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! |
|
|
|