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

Problems with the UART in PIC24FJ32GA004

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







Problems with the UART in PIC24FJ32GA004
PostPosted: Thu Jan 22, 2009 1:22 pm     Reply with quote

Hi all,
i'm new with PIC's and I'm having some problems with the UART.
This is the code that i'm working on:

main.c:

Code:
#include "C:\users\rcfr\ProjetoSerial\main.h"
unsigned int8 dado = 'a';
void init()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(false);
   setup_psp(PAR_DISABLE,PAR_DISABLE);
   setup_spi(SPI_SS_DISABLED);
   setup_timer1(TMR_INTERNAL);
   setup_timer2(TMR_DISABLED);
   setup_timer3(TMR_DISABLED);
   setup_timer4(TMR_DISABLED);
   setup_timer5(TMR_DISABLED);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_low_volt_detect(FALSE);
   output_high(PIN_B12);
   //enable_interrupts(INTR_GLOBAL);
   //enable_interrupts(INT_RDA);   
}
/*#INT_RDA
void serial()
{
   output_high(PIN_C8);
   dado = getc();
}*/
void main()

   init();   
   output_high(PIN_C7);
   delay_ms(1000);
   output_low(PIN_C7);
   delay_ms(1000);

   while(true)
   {
      dado = getc();
      putc(dado);     
   }
}


main.h:
Code:

#include <24FJ32GA004.h>
//#device ICD=TRUE
#device adc=8
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
//#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES ICS3                     //ICD communication channel 3
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS1                  //Watch Dog Timer PostScalar 1:1
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES FRC                      //Internal Fast RC Oscillator
#FUSES NOSKSFSM                 //Clock Switching Mode is disabled
#FUSES NOOSCIO                  //OSC2 is general purpose output
#FUSES HS                       
#FUSES I2C1SELD             
#use delay(clock=8000000)
#use rs232(baud=9600, parity=N, xmit=PIN_B11, rcv=PIN_B10)

The problem that I'm suffering is that I can't read any string that is passed to the PIC. I'm using the COMTEST(in the PC) program to pass some strings to the PIC, for example the string: 1234567890 is passed, and the string that the PIC receive is 13579. You can see that I've tried to use the interrupt, but it didn't work, the interrupt didn't occur. I've read a lot of topics in the forum, and i think it didn't occur because I'm using the SW UART. But i don't know why I'm using the SW UART and how i can use the HW UART. When i pass character by character the PIC don't have any problems to receive the data, even when i put the COMTEST to send repeatedly. Anyone can help me please?
Thanks.
Ttelmah
Guest







PostPosted: Thu Jan 22, 2009 4:12 pm     Reply with quote

Don't know how well this is working yet, but the key is a #pin_select line.

Basically, the hardware UART is only implemented, if the #USE RS233 line has it's pin numbers matching those of the hardware UART. On the PIC24 chips, you can change what pins the hardware UART connects to, so what you have to do, is setup pin select lines, saying that the UART is connected to the pins you are using, and _then_ implement your #USE RS232 line. The compiler then switches to using the hardware UART.

When I last looked at this (quite a few compilers ago), it still had problems, but it should work now.

Look in the manual for the pin_select syntax.

Best Wishes
RCFR
Guest







Problems with the UART in PIC24FJ32GA004
PostPosted: Fri Jan 23, 2009 12:12 pm     Reply with quote

Thanks for the reply Ttelmah, i'll try this now!
RCFR
Guest







Problems with the UART in PIC24FJ32GA004
PostPosted: Fri Jan 23, 2009 1:38 pm     Reply with quote

Thanks for the help Ttelmah, this really worked. After some tries and test the #pin_select worked. I coudn't find this directive in the C Compiler
Reference Manual but it work!!! THANKS
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