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

18F66J90 UART2 problem [topic extended]

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



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

18F66J90 UART2 problem [topic extended]
PostPosted: Sun Nov 22, 2009 11:04 am     Reply with quote

Hi there,

I'm using fairly new 18F66J90 PIC for our new project. Previous version was using 18F66J10 and was working fine with UART2. Since both PIC's are pin compatible, I thought that I can easily replace it.

And it stayed as a thought, not as a reality.

Right now I'm fine with UART1 and CCS' Software UART. But UART2 is working at 1.250.000 baud which is weird. I just have done anything to make it work at 9600 baud, but no luck.

Note: The given baud rate is measured via scope.

Here is my related code.

Code:


#FUSES HS       /// Using 20 MHz Crystal to get away from IOSC related frame errors

#use delay(clock=20000000, restat_wdt)


#use rs232(stream = AUX, baud=9600, parity=N, bits=8, stop=1, restart_wdt, UART2, ERRORS)

#byte SPBRG2 = 0xF64
#bit CREN = 0xF60.5
#bit SPEN = 0xF60.7

SPBRG2 = 32;  /// See 18F66J90 datasheet page 272. (SPBRG2 Baud rate generator formula)
CREN = 0;
delay_us(10); /// See the ERRATA document of the silicon. enabling and disabling the UART needs 2 Tcy. I just added 10 us to be on the safe side.
CREN = 1;

SPEN=0;
delay_us(10); /// Same story as above
SPEN=1;

while(1)
{
fputc('U', AUX);  /// A nice character to see the baud rate via scope. (0b01010101)
delay_us(10);
}


So... Any ideas, I've run out of them Smile

Configuration:

- CCS 4.093
- 18F66J90-I/PT Rev. A1
- MPLab 8.40
- PICKit2
_________________
/// KMT
/// www.muratursavas.com


Last edited by KaraMuraT on Mon Dec 07, 2009 6:33 am; edited 1 time in total
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

Flash news
PostPosted: Sun Nov 22, 2009 11:23 am     Reply with quote

I checked the SPBRG2's actual value after changing it to 32, but I see that it's remaining as 0. Changing the sequence of the procedures didn't help at all.

I don't know whether this is a particular error of my PIC or an errata of the silicon. It does not sound sane to release a silicon without capability to change of a well known SPR.
_________________
/// KMT
/// www.muratursavas.com
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 22, 2009 12:41 pm     Reply with quote

Just switched back to 18F66J10 and it works just fine.

I hope Microchip has some sort of explanation about that. Else, the 120 pieces of 18F66J90 is just trash for me.
_________________
/// KMT
/// www.muratursavas.com
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

Re: 18F66J90 UART2 problem
PostPosted: Mon Nov 23, 2009 1:53 pm     Reply with quote

Code:


#FUSES HS       /// Using 20 MHz Crystal to get away from IOSC related frame errors

#use delay(clock=20000000, restat_wdt)


Do not know if this error was a paste error or if it will fix the problem.

#use delay(clock=20000000, restart_wdt)
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 24, 2009 4:19 am     Reply with quote

Thanks Mike, for your attention. It was not a paste error, but also not related to this UART2 error.

Fortunately you sure have saved me from a lot of headaches in the future Smile I haven't activated the Watchdog part of the software yet.
_________________
/// KMT
/// www.muratursavas.com
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 07, 2009 6:52 am     Reply with quote

I got analyzed a new PCB and 18F66J90, and seems like the problem was individual.

But this topic also revealed another CCS Bug. If you setup your code like this:

Code:
#use delay(clock=16000000, restart_wdt)

#use rs232(stream = AUX, baud=9600, parity=N, bits=8, stop=1, restart_wdt, UART2, ERRORS)


you'll expect that UART2 will work 9600 baud. Nope, you have to add this line (thanks to PCM Programmer)

Code:
setup_oscillator(OSC_4MHZ | OSC_PLL_ON);


This will make your PIC really run on 16 MHz. But does it also solve the UART2 problem? Unfortunately no.

Here is the additional code to the lines above:

Code:
#bit BRGH = 0xF61.2
#byte SPBRG2 = 0xF64

BRGH = 0;   
SPBRG2 = 25;   /// Check the formula, 18F87J90 datasheet page 272


Here is what causes the problem:

With standard #use RS232 line, somehow CCS compiler activates the BRGH bit. That causes the baud rate 4 times faster than normal.

Then you have to set the SPBRG2 register as 25. Because the CCS compiler sets it as 64. This causes an unexpected baud rate and framing errors. (4000 baud)

Hope this helps to your future implementations.

And the extended part of the question.

I need to set the FUSES as "INTRCPLL_IO". But looks like this also does not work as expected (MPLab show that this line chooses HS, instead of INTRC). I always have to set the config bits manually after every compile from the "Configuration Bits" window. I looked to PICC project wizard ot the CCS's own IDE. The project wizard does not even show an option as INTRC for 18F66J90. I think it was an false implementation of the PIC, am I right?

Is there any way to set the config bits manually in the code? (without using CCS #fuses)
_________________
/// KMT
/// www.muratursavas.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 07, 2009 2:33 pm     Reply with quote

See these posts. They have sample code which shows how to use the
#rom statement to set the Config Bits if the desired #fuses statements
are not supported, or if they have bugs:
http://www.ccsinfo.com/forum/viewtopic.php?t=32323
http://www.ccsinfo.com/forum/viewtopic.php?t=33235
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 08, 2009 3:53 am     Reply with quote

Thanks PCM Programmer, you've saved the day, again Smile
_________________
/// KMT
/// www.muratursavas.com
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 23, 2009 10:57 am     Reply with quote

Great Evil or Very Mad

It was working fine since my last post, but now somehow CCS adds another fuses line to the hex file, like that:
Code:
:06FFF800A0F001F7F0F09B
:06FFF800A0F4DFFFF2F1AE


Where is that second line coming from? It ruins the config bits and I have to set the bits again for every compile within MPLab.

P.S: Tried to reinstall CCS, but didn't help.
_________________
/// KMT
/// www.muratursavas.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 23, 2009 1:23 pm     Reply with quote

Post a very short test program that shows the problem.
It must be compilable.

Post your current compiler version.
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Thu Dec 24, 2009 2:05 am     Reply with quote

Here is the config:

- CCS 4.093
- 18F66J90-I/PT Rev. A1
- MPLab 8.43
- PICKit2


Test code:

Code:
#include <18F66J90.h>
   
#device *=16 ADC=10

#ROM int8 0xFFF8 = {0xA0, 0xF0, 0x01, 0xF7, 0xF0, 0xF0 }    /// Config Bits       

#use delay(clock=16000000, restart_wdt)

#use rs232(stream = AUX, baud=9600, parity=N, bits=8, stop=1, restart_wdt, UART2, ERRORS)


#byte SPBRG2 = 0xF64
#bit BRGH = 0xF61.2


void main(void)
{
    setup_oscillator(OSC_4MHZ | OSC_PLL_ON);

    output_high(PIN_D2);
    delay_ms(200);
    output_low(PIN_D2);
    delay_ms(200);
    output_high(PIN_D2);
   
    BRGH = 0;   
    SPBRG2 = 25;

    while(1)
    {
        fputc('U',AUX);
        delay_ms(50);
    }


}


Generated hex code:

Code:
:100000001FEF00F0EA6A060EE96EEF5011E0050EF0
:10001000016EBF0E006E0400002EFDD7012EF9D731
:100020002E0E006E002EFED700000400EF2EEFD73C
:10003000000C0400A4A8FDD7626E4BEF00F0F86A34
:10004000D09EEA6AE96A0086A00E646E010E016E17
:10005000A60E616E900E606EA86AAA6AA96AC15067
:10006000C00BC16E070EB46E056A400E9B6E600E2B
:10007000D36ED35095948C84C80E066EC3DF9594CE
:100080008C94C80E066EBEDF95948C846194190E14
:10009000646E550ECED7320E066EB4DFFAD703006B
:06FFF800A0F001F7F0F09B
:06FFF800A0F4DFFFF2F1AE
:00000001FF
;PIC18F66J90
;CRC=E506  CREATED="24-Ara-09 09:45"



Correct fuses line: A0 F0 01 F7 F0 F0

Incorrect added fuses line: A0 F4 DF FF F2 F1

As you can see, it messes up with the Oscillator Bits (underlined) and makes the program useless.

P.S: It messes up only with 18F66J90. I tried same program with different PIC and there were no problems.
_________________
/// KMT
/// www.muratursavas.com
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Thu Dec 24, 2009 4:50 am     Reply with quote

Here is another thing not related with HEX CONFIG BITS issue, but with UART2 settings.

In this post I've really struggled with UART2, and it seems CCS has more problems.

I've found that "setup_spi2();" function has a false SFR address and ruins the UART2 settings. Be careful with using it 18FXXJ90 series. I don't know whether CCS fixed or not this issue on the newer versions. [mine is CCS 4.093 as mentioned before]
_________________
/// KMT
/// www.muratursavas.com
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Dec 24, 2009 7:19 am     Reply with quote

FWIW, here are the fuses in the .LST file when your code is compiled in 4.103

Code:

   Configuration Fuses:
   Word  1: F4A0   NOXINST STVREN NOWDT NOPROTECT
   Word  2: FFDF   E4_SW WDT32768 FCMEN IESO PRIMARY HPT1OSC T1DIG
   Word  3: F102   NODEBUG CCP2C1 RTCOSC_T1
   Word  4: 0000 


And the actual hex code:
Code:

:100000001FEF00F0EA6A050EE96EEF5011E0050EF1
:10001000016EBF0E006E0400002EFDD7012EF9D731
:100020002E0E006E002EFED700000400EF2EEFD73C
:10003000000C0400A4A8FDD7626E4AEF00F0F86A35
:10004000D09EEA6AE96A7C86A00E646E010E7D6E1F
:10005000A60E616E900E606EA86AAA6AC150C00BAF
:10006000C16E070EB46E046A400E9B6E600ED36EB6
:10007000D35095948C84C80E056EC4DF95948C94EF
:10008000C80E056EBFDF95948C846194190E646E62
:0E009000550ECFD7320E056EB5DFFAD703003E
:06FFF800A0F001F7F0F09B
:08FFF800A0F4DFFF02F100009C
:00000001FF
;PIC18F66J90
;CRC=4396  CREATED="24-Dec-09 07:01"

_________________
Google and Forum Search are some of your best tools!!!!
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 25, 2009 7:17 am     Reply with quote

Then it means this bug still exists in the latest version.

Thanks dyeatman.
_________________
/// KMT
/// www.muratursavas.com
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