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 CCS Technical Support

16F877A USART Problem

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



Joined: 21 Dec 2004
Posts: 45

View user's profile Send private message

16F877A USART Problem
PostPosted: Tue Nov 15, 2005 9:26 am     Reply with quote

Hi friends.

I am having troubles with mi PIC 16F877A and his USART module. I am usign MAX232.

This code donīt work.

Code:

#include <16F877A.h>
#device adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG
#FUSES BROWNOUT, NOLVP, NOCPD, NOWRT                    
#use delay(clock=20000000,RESTART_WDT)
#use rs232 (baud=57600,parity=n,[b]xmit=PIN_C6,rcv=PIN_C7[/b],bits=8,restart_wdt) // HARDWARE USART

void main() {
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

  while(1)
  {
  int i=0;
    while(i<255) {
    printf("Current CHAR: %C\n\r",i);
    i++;
    delay_ms(100);
    }

  }
}



But following code works.

Code:

#include <16F877A.h>
#device adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG
#FUSES BROWNOUT, NOLVP, NOCPD, NOWRT                    
#use delay(clock=20000000,RESTART_WDT)
#use rs232 (baud=57600,parity=n,[b]xmit=PIN_C4,rcv=PIN_C5[/b],bits=8,restart_wdt) // SOFTWARE USART

void main() {
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

  while(1)
  {
  int i=0;
    while(i<255) {
    printf("Current CHAR: %C\n\r",i);
    i++;
    delay_ms(100);
    }

  }
}



itīs seems hardware usart fail.

thank you.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Nov 15, 2005 9:42 am     Reply with quote

try using the same IO pins as the hardware UART but forcing the compiler to use software.

Code:
#use rs232 (baud=57600,parity=n,xmit=PIN_C6,rcv=PIN_C7,bits=8, force_sw) // SOFTWARE USART


For your hardware implementation you forgot to add the keyword errors but this affects the receive logic not the trnsmit logic.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
densimitre



Joined: 21 Dec 2004
Posts: 45

View user's profile Send private message

PostPosted: Tue Nov 15, 2005 12:49 pm     Reply with quote

asmallri wrote:
try using the same IO pins as the hardware UART but forcing the compiler to use software.

Code:
#use rs232 (baud=57600,parity=n,xmit=PIN_C6,rcv=PIN_C7,bits=8, force_sw) // SOFTWARE USART


For your hardware implementation you forgot to add the keyword errors but this affects the receive logic not the trnsmit logic.


HI

thankz for answer..

Well, My intention is to send information towards the PC only....i will try your suggestion.


Bye
densimitre



Joined: 21 Dec 2004
Posts: 45

View user's profile Send private message

PostPosted: Wed Nov 16, 2005 6:57 am     Reply with quote

asmallri wrote:
try using the same IO pins as the hardware UART but forcing the compiler to use software.

Code:
#use rs232 (baud=57600,parity=n,xmit=PIN_C6,rcv=PIN_C7,bits=8, force_sw) // SOFTWARE USART


For your hardware implementation you forgot to add the keyword errors but this affects the receive logic not the trnsmit logic.



Hi there

I have tested your code, and this is the result.

1.- USARTīs pins with force_sw as simple I/O, works fine for rs232 communications. TX and RX functions works very well.

2.- I did some test.
a.- TX in force_sw mode / RX in hardware mode ==> TX ok / RX not OK
b.- TX in hardware mode / RX in force_sw mode ==> TX not OK / RX OK


Code:

#use delay(clock=4000000)
#use rs232(baud=9600,bits=8,parity=n,xmit=pin_c6,rcv=pin_c7,force_sw,errors,stream=pc1)
#use rs232(baud=9600,bits=8,parity=n,xmit=pin_c6,rcv=pin_c7,errors,stream=pc2)

void main() {
char c;

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   while (1) {
    c=fgetc(pc2);  //RX in hardware mode
    fputc(c,pc1);   //TX in force_sw mode


  }

}


after

Code:

while (1) {
    c=fgetc(pc2);  //RX in hardware mode. DONT WORK
    fputc(c,pc1);   //TX in force_sw mode

    delay_ms(1000);
    fputc(c,pc2);   //As RX dont work, TX in HARD/SW mode dont work also.


  }



Im afraid USART HARDWARE ist FAULT....


A question:

- When i use usart in force_sw mode, the data to send is stored in RAM or TXSTA register????

thank you
Ttlemah
Guest







PostPosted: Wed Nov 16, 2005 10:19 am     Reply with quote

What compiler version?.
If you look back a few days, another poster was having problems with the receive, on the hardware UART, on another chip, and I suggested he simply set the TRIS bit for the RX line. This is a fault, that seems to have appeared a few compiler versions ago, with some chips, when using standard_io, where the compiler clears the TRIS bit incorrectly, setting the receive pin as an output (I have reported it to CCS). Can I suggest you try the same fix?
The software UART does everything in RAM.

Best Wishes
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