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

PIC 18F45K22 running 2 serial ports

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



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PIC 18F45K22 running 2 serial ports
PostPosted: Mon Jul 24, 2017 10:15 am     Reply with quote

Hi

I am having difficulties making PIC 18F45K22 running with 2 serial ports at the same time. The Interrupts on serial 2nd serial port seems not to react.

My header:
Code:
#include <18F45K22.h>
#device ADC=10
#use delay(internal=64MHz)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#use rs232(baud=115200,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=8,stream=PORT2)

and my code:
Code:
#include <CCS_45K22_2xUART.h>
#define LED PIN_A0
#define DELAY 1000
#byte APORT=0x0F80

int timer;

#INT_TIMER1
void  TIMER1_isr(void) {
  timer += 1;
}

#INT_RDA
void  RDA_isr(void) {
  output_toggle(pin_A1);
  getc();
}

#INT_RDA2
void  RDA2_isr(void) {
  output_toggle(pin_A2);
  getc();
}

void main() {

  setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);    //32.7 ms overflow

  enable_interrupts(INT_TIMER1);
  enable_interrupts(INT_RDA);
  enable_interrupts(INT_RDA2);
  enable_interrupts(GLOBAL);
 
  output_a(0b11110000);
  output_a(0b11100001);
 
  timer = 0;
 
  delay_ms(100);
  fputc(12, PORT1);
  fputc(12, PORT2);

  while(TRUE) {
    if (timer > 5) {
      output_toggle(pin_A0);
      timer = 0;
    }
  }

}


An advice on the subject?

Many thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 10:25 am     Reply with quote

Yes....

Been covered dozens of times.
You need to use the streams:

Code:

int8 dummy1,dummy2;

#INT_RDA
void  RDA_isr(void) {
  output_toggle(pin_A1);
  dummy1=fgetc(PORT1);
}

#INT_RDA2
void  RDA2_isr(void) {
  output_toggle(pin_A2);
  dummy2=fgetc(PORT2);
}


Your getc, needs to actually put the data somewhere. It won't read unless this is done (I've just added two dummy variables). Key though is that each interrupt must read from the correct stream. Without the stream references, both getc calls will pull data from the first UART defined.
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 10:53 am     Reply with quote

Sorry to disturb again.

I have changed and I am using the streams, like this:

Code:
#include <CCS_45K22_2xUART.h>
#define LED PIN_A0
#define DELAY 1000

int timer;
int8 dummy1, dummy2;

#INT_TIMER1
void  TIMER1_isr(void) {
  timer += 1;
}

#INT_RDA
void  RDA_isr(void) {
  output_toggle(pin_A1);
  dummy1=fgetc(PORT1);
}

#INT_RDA2
void  RDA2_isr(void) {
  output_toggle(pin_A2);
  dummy2=fgetc(PORT2);
}

void main() {

  setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);    //32.7 ms overflow

  enable_interrupts(INT_TIMER1);
  enable_interrupts(INT_RDA);
  enable_interrupts(INT_RDA2);
  enable_interrupts(GLOBAL);
 
  timer = 0;
 
  delay_ms(100);
  fputc(12, PORT1);
  fputc(12, PORT2);

  while(TRUE) {
    if (timer > 5) {
      output_toggle(pin_A0);
      timer = 0;
    }
  }
}


But still having the issue, i.e. no reaction to interrupt on port 2.
I didn't change anything on my header file.

Further advice?

Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 11:28 am     Reply with quote

Honestly it s always easier to just use:

Code:

#use rs232(baud=115200,parity=N,UART1,bits=8,stream=PORT1)
#use rs232(baud=115200,parity=N,UART2,bits=8,stream=PORT2)

Which ensures the hardware UART is used.
However are you sure you are not using the DEBUG?.
The UART2 pins are used by the debugger, so cannot be used if this is enabled. If you are compiling through MPLAB, you need to explicitly select release, not debug.
If it still doesn't work, you need to triple check your connections.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 11:52 am     Reply with quote

As a comment. Are you sure?.

A2, is the DACOUT pin. It won't function as a normal output, unless the DAC is disabled. Suddenly realised you are using this to test...
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 12:41 pm     Reply with quote

I am not using any DEBUG instruction in my code.

My testing configuration is the following

PC --> ICD-U64 --> EasyPIC v7
PC --> mikroProg --> EasyPIC v7

None of these makes my application reacting to interrupt on RDA2.

Of course, beside A2 I have been testing some other pins with the same negative results.

I have also been trying the
Code:
#use rs232(baud=115200,parity=N,UART1,bits=8,stream=PORT1)
#use rs232(baud=115200,parity=N,UART2,bits=8,stream=PORT2)


I am really lost.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 1:01 pm     Reply with quote

What are you using as the development environment.
CCS compiler directly?.
CCS IDE?.
MPLAB with CCS?.

The point is that if you are using the latter, it automatically adds the debug instruction, even if you don't put it in yourself, unless you explicitly select to compile the code for 'release'.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 2:24 pm     Reply with quote

Quote:
#include <18F45K22.h>
#device ADC=10
#use delay(internal=64MHz)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#use rs232(baud=115200,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=8,stream=PORT2)

For 18F45K22, UART2 is on pins D6 and D7. You probably were looking
at the pin table for the 28-pin devices. They use B6 and B7.

Also, how are you connecting your PC to UART2 ? Here is the schematic:
https://download.mikroe.com/documents/full-featured-boards/easy/easypic-v7/easypic-v7-schematic-v104c.pdf
You have two serial interfaces. One is the Max3232 going to a DB-9.
The other is a FTDI going to a USB connector. These are selected with
dip switches SW1 and SW2, and shunts on J3 and J4. It appears that
they will not let you select the Max-3232 and the FTDI at the same time.

It looks like you could do a work-around with two jumper wires that have
pin sockets on both ends. You could setup the J3 and J4 for the Max232A
for UART on C6 and C7. Do this with shunts on the pins.
Then use the jumper wires to go from the bottom pins on J3 and J4 to
pins D6 and D7 on the CNx 10-pin headers. This would put UART2 on
the FTDI USB serial port. It looks like this would work. I don't have the
board so I've not actually done it.
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PostPosted: Mon Jul 24, 2017 2:52 pm     Reply with quote

@PCM programmer

Many many thanks for making me aware about this mistake on my side. Indeed I have been looking under the wrong micro controller, i.e. F2XK22 instead of F4XK22. Now everything's work fine with UART2 on D6/D7.

@Ttelmah

I am using normally CCS IDE directly and programming my EasyPIC v7 with ICD-U64 because of its very good programming speed.

Here is my now working code.

The header is:
Code:
#include <18F45K22.h>
#device ADC=10
#use delay(internal=64MHz)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#use rs232(baud=115200,parity=N,xmit=PIN_D6,rcv=PIN_D7,bits=8,stream=PORT2)


and the code is:
Code:
#include <CCS_45K22_2xUART.h>
#define LED PIN_A0
#define DELAY 1000

int timer;

#INT_TIMER1
void  TIMER1_isr(void) {
  timer += 1;
}

#INT_RDA
void  RDA_isr(void) {
  output_toggle(pin_A1);
  fgetc(PORT1);
}

#INT_RDA2
void  RDA2_isr(void) {
  output_toggle(pin_A2);
  fgetc(PORT2);
}

void main() {

  setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);    //32.7 ms overflow

  enable_interrupts(INT_TIMER1);
  enable_interrupts(INT_RDA);
  enable_interrupts(INT_RDA2);
  enable_interrupts(GLOBAL);
 
  timer = 0;
 
  delay_ms(100);
  fputc(12, PORT1);
  fputc(12, PORT2);
 
  while(TRUE) {
    if (timer > 5) {
      output_toggle(pin_A0);
      timer = 0;
    }
  }
}


Once again many thanks to all.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Jul 25, 2017 12:21 am     Reply with quote

Good.

I was worried about the debug, since it has been a 'curse' to me, that the debug pins can't be used on the 28pin device with UART2.

Must admit, didn't even look at your device number....
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