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 CCS 3.224
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tony
Guest







PROBLEMS CCS 3.224
PostPosted: Tue May 10, 2005 10:54 am     Reply with quote

#include <18f4525.h>
//#include <18f452.h>


#int_tbe
void tbe_isr()
{
disable_interrupts(INT_TBE);
TXREG=0x55;
indByte ++;
enable_interrupts(INT_TBE);
return;
}


void main()

{

while (TRUE)
{
BRG16 = LOW;
SPBRG = 207;
SYNC = HIGH;
SPEN = HIGH;
CSRC = HIGH;
TXIE = HIGH;

TXREG=0x55;
indByte = 0;

while (indByte < 5)
{
TXEN = HIGH;
}
TXEN = LOW;
}

return;
}

This code works BAD with PIC18F452 and doesn't work with PIC18F4525, that is the debugger remains in the loop (while (indByte <5)) with indbyte always = 1 and doesn't go on.
Why?
MPLAB is 7.10 and CCS, just buyed, is 3.224.

Instead with MPLAB 7.10 and CCS 3.174 the code works well with PIC18F452.

Maybe, are there the bugs in ccs 3.224 with 18f4525?

I'd like to have some answers because the Maintenance of PCWH is buyed 21 April 2005 and i didn't use for the previous problems.

Thanks a lot in advance
Tony
Guest








PostPosted: Wed May 11, 2005 8:17 am     Reply with quote

BUT CAN YOU HELP ME????
Ttelmah
Guest







PostPosted: Wed May 11, 2005 8:48 am     Reply with quote

Start by removing the disable/enable interrupt functions in the interrupt handler. These are not needed, and may cause problems.
Get rid of the returns at the end of the functions. Though these should not cause problems, they are unneccesary in C. A return should only be used where there is data to return, or you are exiting a function before it's end.
Add a trap at the end of the main function, to avoid coming off the end of this. This is a difference between writing for C on a command line inside an OS, and writing C for an embedded processor, or for internal low level processor code. In the former case, there is the operating system to 'return' to. In the latter cases, you must never return, unless you have set something up to handle this. In the CCS C, if you drop off the end, the compiler puts a sleep instruction to trap the exit. Without this, depending how it is handling the 'return' you will either generate a stack overflow, or hit the same trap.
Without seeing all your bit definitions for the registers, it is impossible to be sure that you are programming the chip correctly. Why not use the C functions, unless you are sure there is a problem with these, they make support much easier...
Do you really want the USART to be running in synchronous mode?. This will generate a seperate 'clock' line for the data, and will require suitable hardware to handle.
You are not showing any control of the TRIS registers. Since you are not using the C functions, controlling these, becomes _your_ responsibility, and the USART will not operate correctly without these setup.
The code as it stands, is full of potential problems. Don't blame the compiler for these.

Best Wishes
tony
Guest







problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Mon May 16, 2005 9:11 am     Reply with quote

I have followed yours suggests but the code doesn't work!
The index "indbyte" always = 1 and doesn't go on.

The initial configuration of registers, before to run USART (syncrhronous master mode), is:

TRISC = 0x00;
PIE1 = 0x10;
PIR1 = 0x00;
IPR1 = 0xFF;
PIE2 = 0x00;
PIR2 = 0x00;
IPR2 = 0xDF;
RCSTA = 0x80;
TXSTA = 0x92;
TXREG = 0x00;
RCREG = 0x00;
SPBRG = 0xCF;
SPBRGH = 0x00;
STATUS = 0x04;
INTCON = 0xC3;
INTCON2 = 0xF5;
INTCON3 = 0xC3;

I hope that with this value of registers you can better help me.

Thanks
Tony
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 16, 2005 9:36 am     Reply with quote

Quote:
I have followed yours suggests but the code doesn't work!
It still looks like you are not using the C-functions for setting up all the internal registers, so what other suggestions did you not implement.....?? Please post a complete example program, your first example program was missing a lot of defines.

Considering the errors in your code I guess you are relative new to the world of embedded programming. Hence again the question, do you really want the USART to be running in synchronous mode? In the last 20 years I've never come across a device using this mode, ofcourse they will exist, but are rare. In asynchronous mode you need a minimum of 3 wires (TX, RX and GND), synchronous mode uses (DT, clock and gnd).


Last edited by ckielstra on Mon May 16, 2005 9:45 am; edited 1 time in total
Guest








Re: problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Mon May 16, 2005 9:44 am     Reply with quote

tony wrote:
I have followed yours suggests but the code doesn't work!


Actually, his biggest suggestion was to recommend using the c functions that ship with CCS. One of the best things this compiler does is make USART a fairly trouble free process, instead of a pain in the butt.

Look up the docs for "#use rs232", and use it. You won't need to concern yourself with what's in all those registers, and your code will very likely to be more portable between different controllers and possible different compiler versions. Last but not least, your code will be a ton easier to debug.

You can do things this way, or you can go to the chip's datasheet, look up each one of those registers, and figure out what's wrong. Personally, I'd toggle a bit in the tbe interrupt just to make sure that it's being called every now and again.

Scott
Tony
Guest







problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Mon May 16, 2005 11:52 am     Reply with quote

I must use USART in master synchronous mode and all my code works vey well with 18f452 where the project .hex is obtained through compiler CCS 3.177 & MPLAB 6.60.

The SAME project doesn't work at all with 18f4525 even if #include "18f452.h" as been changed with #include "18f4525.h" but the project.hex is obtained through compiler CCS 3.224 & MPLAB 7.11.

I want to keep the same code by working with 18f4525, therefore i want to investigate the problem.

Maybe 18f4525 is not pin to pin compatible with 18f452????
Then I think the problem is to be find it in compiler CCS 3.224.

Could you please try the code below and let me know whether it is corrrect?

Thank you very much indeed,
Regards
Tony

#include <18f4525.h>

#FUSES HS, NOPROTECT, NOPUT, NOBROWNOUT, NOWDT
#ZERO_RAM

#byte TXREG= 0xFAD
#byte RCREG= 0xFAE
#byte SPBRG= 0xFAF
#byte SPBRGH= 0xFB0
#byte BAUDCON = 0xFB8
#byte RCSTA = 0xFAB
#byte TXSTA = 0xFAC
#byte PIE1 = 0xF9D

#bit BRG16 = BAUDCON.3
#bit BRGH = TXSTA.2
#bit SYNC = TXSTA.4
#bit TXEN = TXSTA.5
#bit CSRC = TXSTA.7
#bit SPEN = RCSTA.7
#bit TXIE = PIE1.4



#int_tbe
void tbe_isr()
{
TXREG=0x55;
indByte ++;
}


void main()
{

BRG16 = LOW;
SPBRG = 207;
SPBRGH =0;
SYNC = HIGH;
SPEN = HIGH;
CSRC = HIGH;
TXIE = HIGH;

while (TRUE)
{
TXREG=0x55;
indByte = 0;
while (indByte < 5)
{
TXEN = HIGH;
}
TXEN = LOW;
}
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 16, 2005 12:43 pm     Reply with quote

Quote:
Maybe 18f4525 is not pin to pin compatible with 18f452????
What makes you think these devices are pin compatible? For the most part they are pin compatible, but have a look at the pin diagrams in the datasheet and you'll notice some differences. The 4525 has more analog inputs than the 452, and there are several more differences. Very likely these differences will have impact on your code because you are directly writing to all registers.

Quote:
I want to keep the same code by working with 18f4525, therefore i want to investigate the problem.
This is exactly the great thing about using the CCS high level functions! Just by changing the header file you can often make your same code work on different PIC processor types. So rewrite your code for the new processor and by changing the header file you can use it on the old processor type as well.

Just another small note: When posting code please use the Code button in order to maintain the formatting of your code, this makes reading much easier.

If you are not using Low Voltage Programming then please add the NOLVP statement to your #fuses line, this has caused many spurious errors.

One obvious error in your program is that you are not enabling the global interrupt flag, so the transmit interrupt will never occur.
dyeatman



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

View user's profile Send private message

PostPosted: Mon May 16, 2005 1:06 pm     Reply with quote

Also, since he is hard coding the registers they may not be register to register compatible or the addresses may be different!
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

Re: problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Mon May 16, 2005 1:47 pm     Reply with quote

Tony wrote:

Maybe 18f4525 is not pin to pin compatible with 18f452????
Then I think the problem is to be find it in compiler CCS 3.224.


Very unlikely that this is a compiler problem. Frankly, I'm amazed the original code worked on any processor, as you didn't enable any interrupts in main. The sample won't work, at the very least, because the tbe interrupt can never be called.

Scott
tony
Guest







problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Tue May 17, 2005 1:43 am     Reply with quote

Ok i forgot to copy the routine about the enable/disable interrupts, at any rate the code doesn't work.

Moreover i checked the addresses of registers and are equals.
Ok The 4525 has more analog inputs than the 452 but i use only the usart and it is the same for both.

Could you please try the code below and thanks
Regards
Tony


#include <18f4525.h>

#FUSES HS, NOPROTECT, NOPUT, NOBROWNOUT, NOWDT, NOLVP
#ZERO_RAM

#byte TXREG= 0xFAD
#byte RCREG= 0xFAE
#byte SPBRG= 0xFAF
#byte SPBRGH= 0xFB0
#byte BAUDCON = 0xFB8
#byte RCSTA = 0xFAB
#byte TXSTA = 0xFAC
#byte PIE1 = 0xF9D

#bit BRG16 = BAUDCON.3
#bit BRGH = TXSTA.2
#bit SYNC = TXSTA.4
#bit TXEN = TXSTA.5
#bit CSRC = TXSTA.7
#bit SPEN = RCSTA.7
#bit TXIE = PIE1.4



#int_tbe
void tbe_isr()
{
TXREG=0x55;
indByte ++;
}


void main()
{

BRG16 = LOW;
SPBRG = 207;
SPBRGH =0;
SYNC = HIGH;
SPEN = HIGH;
CSRC = HIGH;
TXIE = HIGH;


while (TRUE)
{
set_tris_c(0x00);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TBE);
TXREG=0x55;
indByte = 0;
while (indByte < 5)
{
TXEN = HIGH;
}
TXEN = LOW;
disable_interrupts(INT_TBE);
}
}
tony
Guest







problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Tue May 17, 2005 2:34 am     Reply with quote

I compared the 18f452.h with 18f4525.h and i noted that in 18f4525 there are:

1. Two another pin PIN_A7 and PIN_E3
2. Another #define CCP_PWM
3. Another constants used in setup_uart()
4. Constants used in setup_comparator()
5. Constants used in setup_vref()
6. Another constants used in setup_low_voltage_detector()
7. Another constants used in setup_oscillator()
8. Another constants used in setup_adc_ports()
9. #define INT_COMP and INT_OSCF

At any rate this differences don't influence my code.

I'm waiting your feedback
Thanks
Tony
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

Re: problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Tue May 17, 2005 8:21 am     Reply with quote

tony wrote:
I compared the 18f452.h with 18f4525.h and i noted that in 18f4525 there are:



Does your current code snippet work on the 452?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Tue May 17, 2005 8:33 am     Reply with quote

sseidman wrote:
tony wrote:
I compared the 18f452.h with 18f4525.h and i noted that in 18f4525 there are:



Does your current code snippet work on the 452?
I'm sure he never tested this exact code as the declaration of indByte is missing so this code won't compile.
tony
Guest







problems CCS 3.224 OR EUSART PIC18F4525?
PostPosted: Tue May 17, 2005 9:18 am     Reply with quote

Hi Ckielstra,
i have got a large code and i have to cut and to copy code snippet.
At any rate i have compiled the below code and it works with 452 and NOT with 4525.

Sorry and could you please try the code below and thanks

Tony

#include <18f4525.h>
//#include <18f452.h>

#FUSES HS, NOPROTECT, NOPUT, NOBROWNOUT, NOWDT, NOLVP
#ZERO_RAM

#byte TXREG= 0xFAD
#byte RCREG= 0xFAE
#byte SPBRG= 0xFAF
#byte SPBRGH= 0xFB0
#byte BAUDCON = 0xFB8
#byte RCSTA = 0xFAB
#byte TXSTA = 0xFAC
#byte PIE1 = 0xF9D

#bit BRG16 = BAUDCON.3
#bit BRGH = TXSTA.2
#bit SYNC = TXSTA.4
#bit TXEN = TXSTA.5
#bit CSRC = TXSTA.7
#bit SPEN = RCSTA.7
#bit TXIE = PIE1.4

int indByte;

#int_tbe
void tbe_isr()
{
indByte ++;
TXREG=0x55;
}


void main()
{

BRG16 = 0;
SPBRG = 207;
SPBRGH =0;
SYNC = 1;
SPEN = 1;
CSRC = 1;
TXIE = 1;


while (TRUE)
{
set_tris_c(0x00);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TBE);
TXREG=0x55;
indByte = 0;
while (indByte < 5)
{
TXEN = 1;
}
TXEN = 0;
disable_interrupts(INT_TBE);
}
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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