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

18f23k22 Dual UART not working

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



Joined: 30 Jun 2007
Posts: 12

View user's profile Send private message

18f23k22 Dual UART not working
PostPosted: Tue Jun 06, 2017 12:55 am     Reply with quote

Greetings. Can anyone tell me why below code does not work? I can echo the first referenced port but the second one does not echo. I have the same problem when I do an interrupt implementation. I have also implemented the buffer in example ex_sisr.c, same result.

Each works when they are separately implemented.

Compiler version: 5.044

Code:

#include <18F23K22.h>
#device ADC=10
#use delay(internal=2000000)
#define LED1   PIN_B0
#define LED2   PIN_B1
#define LED3   PIN_B2
#define LED4   PIN_B3

#use rs232(UART1,baud=19200,parity=N,bits=8,stream=VANTAGE,errors)//max232
//To VantageVue max232 chip
#use rs232(UART2,baud=19200,parity=N,bits=8,stream=ROCKBLOCK,errors)//ttl
//To RockBlock ttl or USB/UART Sparkfun Board for computer

void main()
{
   while(TRUE)
   {
      fprintf(VANTAGE,"start");
      fprintf(ROCKBLOCK,"start");
      while(TRUE)

         fputc((fgetc(VANTAGE)+1),VANTAGE);
         fputc((fgetc(ROCKBLOCK)+1),ROCKBLOCK);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Tue Jun 06, 2017 1:52 am     Reply with quote

It won't echo, because of a basic syntax error.....

Code:

#include <18F23K22.h>
#device ADC=10
#use delay(internal=2000000)
#define LED1   PIN_B0
#define LED2   PIN_B1
#define LED3   PIN_B2
#define LED4   PIN_B3

#use rs232(UART1,baud=19200,parity=N,bits=8,stream=VANTAGE,errors)//max232
//To VantageVue max232 chip
#use rs232(UART2,baud=19200,parity=N,bits=8,stream=ROCKBLOCK,errors)//ttl
//To RockBlock ttl or USB/UART Sparkfun Board for computer

void main()
{
   while(TRUE)
   {
      fprintf(VANTAGE,"start");
      fprintf(ROCKBLOCK,"start");
      while(TRUE)
      {// note the extra bracket
         fputc((fgetc(VANTAGE)+1),VANTAGE);
         fputc((fgetc(ROCKBLOCK)+1),ROCKBLOCK);
      }
   }
}


Without the extra brackets, the line after the second 'while' is all that gets executed.....
cogen



Joined: 30 Jun 2007
Posts: 12

View user's profile Send private message

PostPosted: Tue Jun 06, 2017 7:43 am     Reply with quote

Wow, apparently it was getting late...I managed to break my interrupt code and I had reverted to simplified code to fix it. Thanks for pointing out the rookie mistake! Now to figure out the other problem, (I am sure something equally stupid).
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Wed Jun 07, 2017 12:44 am     Reply with quote

We have all 'been there'....

Try to do a basic version of the interrupt code.
You'll either find the problem, or it'll become something small enough to post. Smile
cogen



Joined: 30 Jun 2007
Posts: 12

View user's profile Send private message

Follow up
PostPosted: Wed Jun 07, 2017 5:53 am     Reply with quote

Ttelmah,
Yes, I reduced the code to where it started functioning again, then started adding pieces back until it broke. It was the initialization of my first, (of many), arrays that caused my UART port to stop functioning. This made no sense but I had noticed that my MPLABx IDE had begun to behave differently after an update. I removed my text source files and created a new project in MPLABx, and Wala! It magically all started working again. I may have inadvertently changed a make file or who knows!!! No time to track it down right now.
Thanks again for your help.
Mike
temtronic



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

View user's profile Send private message

PostPosted: Wed Jun 07, 2017 6:40 am     Reply with quote

One way to save time debugging, is to have 'incremental' versions of your program.

First, get a 'base' program running.
Then make a copy, call it programv2.c, make a project called programv2 as well.
Compile/test/save.
NOW make SOME changes to V2 and test. IF OK, copy V2 into V3.
Yes, I know you can end up with 10, 20, 65+ versions of the program/project BUT you can always go back to a version that DID work. Also you can compare the current vs the old and SEE what silly mistake you've made.
When the project/program is good THEN delete all but say the last 3 or 4 versions. That way you can 'go back' if needed.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Wed Jun 07, 2017 7:30 am     Reply with quote

A complete set of code now, is tiny, when compared to the cost of storage.
I just copy the whole project directory, with a date and time.

This also illustrates why changing tools can be dangerous. I've posted here in the past that I always include in my comments at the head of the code, what compiler version I'm using, and keep separate copies of the compiler.

Anyway at least you have found your problem. Smile
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