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

PIC18F27k42 UART2, PIN_A5 and PIN_A4 cannot assign error

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



Joined: 23 Mar 2020
Posts: 9

View user's profile Send private message

PIC18F27k42 UART2, PIN_A5 and PIN_A4 cannot assign error
PostPosted: Mon Mar 23, 2020 11:11 am     Reply with quote

In below code pin selection assigned is error when compiled, for pin_a5 and pin_a4, need help what might be wrong.

Code:

#include <18f27k42.h>
#fuses HS,WDT,NOPROTECT,BROWNOUT                           
#use delay(clock=20000000,RESTART_WDT)                                         

#pin_select U1RX=PIN_C5
#pin_select U1TX=PIN_C0
#USE RS232(UART1,baud=9600,xmit=pin_C0,rcv=pin_C5,bits=8,stop=1,parity=n,STREAM=MODEM)

#pin_select U2RX=PIN_A5
#pin_select U2TX=PIN_A4
#USE RS232(UART2,baud=9600,xmit=pin_A4,rcv=pin_A5,bits=8,stop=1,parity=n,STREAM=PC1)

#pin_select SCL1=PIN_C3
#pin_select SDA1=PIN_C4
#use i2c(I2C1,MASTER, sda=PIN_C4, scl=PIN_C3, stream=STREAM_1)

#pin_select SCL2=PIN_C1
#pin_select SDA2=PIN_C2
#use i2c(I2C2,master, sda=PIN_C2, scl=PIN_C1, stream=STREAM_2)

   #include<float.h>
   #include <input.c>
   #include<math.h>                                                           
   #include<stdio.h>                                                 
   #include<stddef.h>                                                                                           
   #include<stdlib.h>     
   #include<string.h>
   
void main(void)

  set_tris_b(0XFF);            // 00000011
  set_tris_c(0XF0);            // 1111 0000
  set_tris_a(0XFF);

   lcd_init();
   delay_ms(50);                                             
   
    enable_interrupts(INT_RDA); 
    enable_interrupts(INT_RDA2);
    enable_interrupts(GLOBAL);                           
   
    SETUP_WDT(WDT_ON);
    lcd_send_byte(0,1);               
 
 
 while(1)
  {
  RESTART_WDT(); 
   //Routines 
  }
}
srikala



Joined: 23 Mar 2020
Posts: 9

View user's profile Send private message

PostPosted: Mon Mar 23, 2020 11:17 am     Reply with quote

The following is error message when compiled:
Quote:

Invalid Pre-Processor directive Invalid Pin: PIN_A5 can not be assigned to U2RX.

Invalid Pre-Processor directive Invalid Pin: PIN_A4 can not be assigned to U2TX.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 23, 2020 11:20 am     Reply with quote

I downloaded a copy of the datasheet from uChip and I don't see RA4, RA5 being PPS pins, so not remappable. Table #1, page #9.
dang it's a 800+ page PRELIMIMARY datasheet !

also...
There's a lot of errors within the rest of the program...

One should never use the WDT until 100% of main() actually runs 100%.

No need for set_tris() as the compiler automatically handles that.

Never enable an Interrupt unless the 'handler' aka ISR or Interrupt Service Routine is coded.

Function call lcd_init but no LCD driver.

Loading several libs and not needing them.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Tue Mar 24, 2020 2:37 am     Reply with quote

As always you need to check data for the chip you use.
In this case Table 17-1, and 17-2. These describe what can be routed
where. UART1 receive can only connect to PortB or PortC, and the same
limitation exists for the TX line. The UART's generically cannot be
connected to PortA. Hence the error.... Sad
The PortA pins are re-map-able for some other devices, but not this.
srikala



Joined: 23 Mar 2020
Posts: 9

View user's profile Send private message

PostPosted: Thu Mar 26, 2020 1:13 am     Reply with quote

Thank you Ttelmah,

I changed my hardware to portc , pin_c5 and pin_c0 and tried the below code, reference from example files.

Could see junk data on PC termina (Tera Term) continuously, sent data from pc terminal and nothing displayed on my lcd second line, only first line displayed as written in code. the ground of pc usb and my hardware board are lopped properly.

Verified the controller port pins and MAX3232 pins with multi-meter, observed there is voltage change in transmit and receive lines.

Voltage levels at Controller Pin’s
@PIN_C0(TX1) – 1.018 to 0.952
@PIN_C5(RX1) – 0.016 to 0.184

Voltage levels at MAX3232 pin’s
@Pin 14 (T1OUT) -> -0.858 to -0.812
@Pin 13 (R1IN) -> 1.812 TO 1.800

Powered my board from PC USB also, could see only junk on pc terminal and nothing on lcd display.
Code:
 
#include <18f27k42.h>
#fuses HS,WDT,NOPROTECT,BROWNOUT                           
#use delay(clock=20000000)

#pin_select U1RX=PIN_C5
#pin_select U1TX=PIN_C0
#USE RS232(UART1,baud=9600,xmit=pin_C0,rcv=pin_C5,bits=8,stop=1,parity=n,stream=pc)

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
char string[8];

#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

#include<2X16LCD.c>        //LCD display

void main() {

   lcd_init();
   delay_ms(50);                                             

   enable_interrupts(int_rda);
   enable_interrupts(global);
   
      lcd_gotoxy(1,1);
      printf(lcd_putc,"Serial Comm");
 
  fprintf(PC,"\r\n\Running...\r\n");
 
   do {
       delay_ms(10000);
      fprintf(PC,"\r\nData From PC");
      while(bkbhit)
      putc( bgetc() );
       
      lcd_gotoxy(1,2);
      printf(lcd_putc,"Resp:%s",bgetc());
   } while (TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Mar 26, 2020 1:57 am     Reply with quote

Big problems. You are reading the character, which means it has 'gone'....
Then you are printing incorrectly:

Code:

   while(bkbhit)
      putc( bgetc() );
   //at this point the buffer has been emptied.

   lcd_gotoxy(1,2);
   printf(lcd_putc,"Resp:%s",bgetc());
   //You now try to print a single character, as a string.
   } while (TRUE);
}


A single character from the buffer, is a character, not a string. %s tries
to print a string, which means it'll print till it happens to meet a null
in memory. LCD will be garbage....

You need to read the characters into a 'string' buffer, then terminate
this with a NULL, if you want to use %s.
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