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 UART 18F45k22

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



Joined: 27 Oct 2010
Posts: 28

View user's profile Send private message

Problems with UART 18F45k22
PostPosted: Thu Nov 04, 2010 5:47 am     Reply with quote

Hi.

I have a problem with the hardware uart on the PIC18F45K22.

I use the pre processor directive #use rs233(uart1, baud=1200, errors).

If I send a character (char r='a') with putc(r), PUTTY prints it. If I try to send information with the printf function, it won't work. I looked at the forum and I'm using this as a template from here http://www.ccsinfo.com/forum/viewtopic.php?t=43829&highlight=pic18f45k22
Code:
#use rs232 ( uart1, baud=300, errors )

The Tx works until I try to use a getc() or printf().... strange since in a 16F887 works great.

Will try later, right now is 4:47 AM and I need some sleep, but it looks like (for me) that the configuration in assembler is not correct for the RX register. Laughing
PCM programmer



Joined: 06 Sep 2003
Posts: 21370

View user's profile Send private message

PostPosted: Thu Nov 04, 2010 12:09 pm     Reply with quote

Post your compiler version. With a new PIC, the compiler may have
some bugs depending upon the compiler version.
bdeb



Joined: 05 Nov 2010
Posts: 15
Location: Sweden

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

PostPosted: Fri Nov 05, 2010 5:18 pm     Reply with quote

Hi mcr1981,

A little confused - are you using 1.200 baud or 300 baud?
(Hope you don´t have two different "#use rs232" statements.)

What´s your clock speed?
Have never tried to run UART so slow, can this cause problems?

Do you have a lot of code in your receive ISR?
Try to add "ERRORS" to the "#use rs232" statement, will clear read errors.


/BdeB
mcr1981



Joined: 27 Oct 2010
Posts: 28

View user's profile Send private message

PostPosted: Sat Nov 06, 2010 3:08 am     Reply with quote

bdeb wrote:
Hi mcr1981,

A little confused - are you using 1.200 baud or 300 baud?
(Hope you don´t have two different "#use rs232" statements.)

What´s your clock speed?
Have never tried to run UART so slow, can this cause problems?

Do you have a lot of code in your receive ISR?
Try to add "ERRORS" to the "#use rs232" statement, will clear read errors.


/BdeB


Hi.

I'm using 300 baud since I use the internal oscilator (4Mhz) and never had any problems with testing an UART at that rate.

I already have "errors" in the preprocessor options for #use rs232.

I don't use an ISR, what I want is for the micro to do a loopback. I can send information to the Terminal, the problem is with the RX module. Will post info later. Apparently the RX is set to an output instead of an input (with CCS pre-processor). Still working on a solution.

I already sent info to CCS regarding the Timer2 module on this PIC. The SFR has the correct address, but when you compile, the addresses of TIMER2 and T2CON are just like a PIC18F45k20, and any other for that matter (they even asigned a number to this issue).
mcr1981



Joined: 27 Oct 2010
Posts: 28

View user's profile Send private message

PostPosted: Sat Nov 06, 2010 11:23 am     Reply with quote

PCM programmer wrote:
Post your compiler version. With a new PIC, the compiler may have
some bugs depending upon the compiler version.


I'm using the 4.112 version.

Looks like you're using this PIC also, since you had the same problem for the PWM (Timer2 and T2CON not set by SETUP_TIMER2()). I already tested this issue with three PIC18F45k22 and nothing, not even changing the UART1 to UART2. I can send but can't receive; not only that, the micro won't even blink an LED (heartbeat LED).

Apparently the the interrupt flag won't activate and the input for the RX pin won't change. Will post a little more info later.
Sergeant82d



Joined: 01 Nov 2009
Posts: 55
Location: Central Oklahoma

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 2:12 am     Reply with quote

I use ver 4.110 w/ 45K22's and have had no problems with the UART... one of the few things I can say that about while using this great chip... the ECCP module/Timer setup was a nightmare that PCM Programmer solved for me...

I really like the peripherals packaged into the 'K22 chips; sure will be nice when the compiler is straightened out enough to use them all!
PCM programmer



Joined: 06 Sep 2003
Posts: 21370

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 2:25 pm     Reply with quote

I was able to make it work. But vs. 4.112 does have a bug, compared to
vs. 4.114. In the 18F45K22, all the i/o pins come up in Analog mode after
a power-on reset. In vs. 4.114, CCS loads all the ANSEL registers with 0
in their start-up code. This sets all the i/o pins to be in digital mode.
But in your version (4.112) CCS doesn't do this.

So to fix it, I added a short routine that emulates the behavior of 4.114.
It sets all ports to be Digital i/o. Just call this routine at the beginning of
of main() as shown in the program below. Then it should work. I did this
and it worked at both 300 baud and at 9600 baud.

The program below just echoes a character that you type in a terminal
window, such as TeraTerm. Whatever you type, will be received by the
PIC and sent back to the PC where you can see it on the screen.
Code:

#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use rs232(baud=300, UART1, ERRORS)

void make_all_pins_digital(void)
{
#byte ANSELA = 0xF38
#byte ANSELB = 0xF39
#byte ANSELC = 0xF3A
#byte ANSELD = 0xF3B
#byte ANSELE = 0xF3C

ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
ANSELD = 0;
ANSELE = 0;
}


#int_rda
void rda_isr(void)
{
int8 c;

c = getc();
putc(c);
}

//======================================
void main(void)
{
make_all_pins_digital();

printf("Start:  ");

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1);
}
mcr1981



Joined: 27 Oct 2010
Posts: 28

View user's profile Send private message

Thanks for this info
PostPosted: Wed Nov 17, 2010 3:51 am     Reply with quote

Maybe I was lost in all this bit-byte madness and did not see that configuration.

Will try your suggestion tomorrow and will keep you posted.

Should one go back to 4.110? I need to renew my licence but will like it to be more stable with this new PICs.

Thanks.


PS: I did not get a notification for your response, had to search the forum again for it.
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