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

PIC18F27J53 second UART not working [SOLVED]

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



Joined: 03 Jan 2012
Posts: 4
Location: Pamplona

View user's profile Send private message Visit poster's website AIM Address

PIC18F27J53 second UART not working [SOLVED]
PostPosted: Tue Jan 03, 2012 6:14 pm     Reply with quote

Hi everyone,
I write because I'm having some problems in a project involving two UARTs.
One of it is for bluetooth communications (already working) and the other one is to communicate with another MCU.
Here is part of the code:

Code:

#include <pruebas.h>
#int_RDA2
void  RDA_isr(void)
{
   unsigned int dato;
   dato=fgetc(IMU);       //Recogemos dato recibido.
   ang=dato;
}

#int_RDA
void  RDA2_isr(void)
{
   unsigned int dato;
   dato=fgetc(BT);       //Recogemos dato recibido.
        //do something
}

void main()
{

   //CONFIG BITS

      setup_adc_ports(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);     
   set_timer0(5535);   
   clear_interrupt(INT_TIMER1);

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);     
   set_timer1(41535);   
   clear_interrupt(INT_TIMER1);

   setup_timer_2(T2_DIV_BY_16,255,3);     
   set_timer2(0x00);   
   clear_interrupt(INT_TIMER1);

      setup_timer_3(T3_INTERNAL|T3_DIV_BY_1);
   set_timer3(41535);   
   clear_interrupt(INT_TIMER1);

      setup_timer_4(T4_DIV_BY_16,255,3);
   set_timer4(0x00);   
   clear_interrupt(INT_TIMER1);

   set_tris_a(0x00);
   set_tris_b(0x01);
   set_tris_c(0x80);   

   output_b(0x00);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_RDA2);
   enable_interrupts(GLOBAL);   

   //PROGRAMA DE INICIALIZACIÓN

    fprintf(BT,"Comunicaciones establecidas \n\r"); //Imprime en panatalla UART Conectada


   //PROGRAMA PRINCIPAL
 
      while(1)
      {
      }


}


And the header file pruebas.h:

Code:

#include <18F27J53.h>
#device ICD=TRUE
#device adc=16

#fuses NOWDT, PLL2, PLLEN, STVREN, NOXINST, DEBUG, NOCPUDIV, NOPROTECT, INTRC_PLL, NOCLOCKOUT, SOSC_LOW, NOFCMEN, NOIESO, WDT2048, NODSWDT, NOIOL1WAY, LS48MHZ
#use delay(clock=48MHz)

#USE FAST_IO (A)
#USE FAST_IO (B)
#USE FAST_IO (C)

#use rs232(UART1,baud=460800,parity=N,bits=8,ERRORS,stream=BT)
#use rs232(UART2,baud=230400,parity=N,xmit=PIN_B1,rcv=PIN_B0,bits=8,ERRORS,stream=IMU)


The second UART is not working.
As I have said, bluetooth is already working on UART1, but if I connect it to UART2 (to check if it works, changing the baud rate at #use rs232), when sending "Comunicaciones establecidas \n\r" to a terminal, only "omunicaciones establecidas \n\r" is shown and nothing is received.
I wonder if I'm really using the hardware UART. Is correctly configured? Is CCS automatically mapping pins B1 and B0?
Someone could help me?
Thanks in advance for your help,

Happy new year everyone!

P.S.: I'm using CCS 4.120
_________________
CME Ingeniería
www.cmeingenieria.es


Last edited by cmesparza on Wed Jan 04, 2012 4:16 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 03, 2012 7:13 pm     Reply with quote

This thread may help. Use #pin_select to set the pins for UART2, and
set the TX2 pin to be an output pin.
http://www.ccsinfo.com/forum/viewtopic.php?t=45883
I haven't tested this, but it sounds reasonable based on that thread.
cmesparza



Joined: 03 Jan 2012
Posts: 4
Location: Pamplona

View user's profile Send private message Visit poster's website AIM Address

SOLVED!
PostPosted: Wed Jan 04, 2012 4:16 am     Reply with quote

Thank you so much, is working now!
I didn't know anything about #pin_select directive...

just changing:
Code:

#PIN_SELECT RX2=PIN_B0
#PIN_SELECT TX2=PIN_B1

#use rs232(UART1,baud=460800,parity=N,bits=8,ERRORS,stream=BT)
#use rs232(UART2,baud=460800,parity=N,bits=8,ERRORS,stream=IMU)


and all done.

Thanks again.
_________________
CME Ingeniería
www.cmeingenieria.es
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