Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with TI flag in 89c5x microcontrollers

Status
Not open for further replies.

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
hi everybody.
I'm writing a program in C language for 89c52. it's collects data from an isa ported device and sends the data with rs232 to the PC. and beside this, the uc recieves commands through rs232 and must respond to this commands immediately. I use serial interrupt to get data from PC. As known, the serial interrupt vector is common for RI & TI flags, and for sending data from uc to pc, TI falg needs to be set and in this case uc always goes to serial interrupt vector and this makes uc to work very slowly. so i decided to keep the TI flag cleared and just set it when i want to send data to PC. But this time, the data are missing or completely lost in the PC side. and another thing is that the TI flag gets set without sending any data to PC that seems wrong to me, because the TI flag just set when a data transfer from uc has finished. can anyone help me with this communication problem? thanks in advance.
 

Medtronic

Full Member level 5
Joined
May 19, 2005
Messages
243
Helped
29
Reputation
58
Reaction score
16
Trophy points
1,318
Location
Egypt
Activity points
2,681
Hi my friend

you can control TI flag by forcing (Set) it but it is not recomended ...
TI flag will set by hardware if your code i.e
mov sbuf,a
that will happen after the data is tranmitted (the last bit out)

Regards
MedTronic
 

    faraj

    Points: 2
    Helpful Answer Positive Rating

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
Medtronic said:
Hi my friend

you can control TI flag by forcing (Set) it but it is not recomended ...
TI flag will set by hardware if your code i.e
mov sbuf,a
that will happen after the data is tranmitted (the last bit out)

Regards
MedTronic
yes that is write that the TI flag is set by hardware, but in my code is set without sending any data and that makes me confused. is there another source that sets the TI flag? i don't know another source to set the TI flag. and even when i simulate the code in keil the TI flag gets set after a while eithout transmitting any data through serial buffer.
 

laktronics

Banned
Joined
Jan 6, 2007
Messages
943
Helped
176
Reputation
352
Reaction score
18
Trophy points
1,298
Activity points
0
Hi,
Have you taken care of the extra TX interrupt generated at the end of sending the character, since you are initiating transmission with a forced TI bit set? I suppose you clear the intrrupt flag at the entry of interrupt routine. There is no other source to set TI interrupt flag, somewhere you are not clearing it.
Regards,
Laktronics
 

    faraj

    Points: 2
    Helpful Answer Positive Rating

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
laktronics said:
Hi,
Have you taken care of the extra TX interrupt generated at the end of sending the character, since you are initiating transmission with a forced TI bit set? I suppose you clear the intrrupt flag at the entry of interrupt routine. There is no other source to set TI interrupt flag, somewhere you are not clearing it.
Regards,
Laktronics
I use "printf ();" in my programe and it is automaticlly clears the TI flag, but after a while the TI flag gets set without sending any character through serial. I was wonder, is there another source that makes TI set except the serial and you say no. this is more confusing me. if you want i can put my code here for your test.

Added after 47 minutes:

and I must add that the TI flag gets set every 2.523 seconds no matter i do send anything through serial (printf) or not.
 

vietdung79

Junior Member level 3
Joined
Aug 1, 2007
Messages
31
Helped
5
Reputation
10
Reaction score
0
Trophy points
1,286
Location
Hanoi City, Vietnam
Activity points
1,404
What compiler do you use?

If you use Keil, you should re-write the putchar() function.
 

    faraj

    Points: 2
    Helpful Answer Positive Rating

laktronics

Banned
Joined
Jan 6, 2007
Messages
943
Helped
176
Reputation
352
Reaction score
18
Trophy points
1,298
Activity points
0
Hi,
While I am not sure as to why you are observing this problem, please clarify why you are setting the TI flag at all, if you initiate a transfer with printf?, and does printf really clear TI bit set by sending the last byte from the buffer, assuming you have a buffer. Your magic number of 2.523sec is really confusing, is it send buffer length x Tbyte@(4800baud) by any chance?
Regards,
Laktronics
 

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
vietdung79 said:
What compiler do you use?

If you use Keil, you should re-write the putchar() function.
yes i use keil, and why should i er-write the putchar function and what changes is needed?
thanks for your help.

Added after 11 minutes:

laktronics said:
Hi,
While I am not sure as to why you are observing this problem, please clarify why you are setting the TI flag at all, if you initiate a transfer with printf?, and does printf really clear TI bit set by sending the last byte from the buffer, assuming you have a buffer. Your magic number of 2.523sec is really confusing, is it send buffer length x Tbyte@(4800baud) by any chance?
Regards,
Laktronics
i just set the TI flag at the beginning of the program, because it is needed for sending the first character. but after that the printf() instruction automatically send characters and clears the TI flag. and my in my code until here everything is normal but sometime and somewhere the TI flag gets set and this is the confusing point. and i must add that I use 9600 bud.
now as vietdung79 says maybe there is something wrong with putchar() function.
thanks to all of you. now i should go and check the function to find the problem.
 

vietdung79

Junior Member level 3
Joined
Aug 1, 2007
Messages
31
Helped
5
Reputation
10
Reaction score
0
Trophy points
1,286
Location
Hanoi City, Vietnam
Activity points
1,404
The printf() function use the putchar() function to interface with peripheral device. You can find the putchar() function in somewhere in the Keil folder (Maybe the Lib folder). Choose version which is suitable with you and copy it to your code. Now you have to set TI flag only one time in your program.
BTW maybe you can post your code here and I may correct it for you.
Regards.
 

    faraj

    Points: 2
    Helpful Answer Positive Rating

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
wek said:
NEVER MIX interrupt-based reception with "main-based" transmission (and vice versa) in '51!

See https://www.8052.com/faqs.phtml?FAQ=138108 and link therein.

JW
yes, that topic in the link is exactly my problem.

Added after 10 minutes:

vietdung79 said:
The printf() function use the putchar() function to interface with peripheral device. You can find the putchar() function in somewhere in the Keil folder (Maybe the Lib folder). Choose version which is suitable with you and copy it to your code. Now you have to set TI flag only one time in your program.
BTW maybe you can post your code here and I may correct it for you.
Regards.
ok, i put my code here consisting of a C file and a H file. I don't know how to thank you, beacause this problem was confusing me for 2 weeks.
 

aupa

Member level 3
Joined
Feb 22, 2007
Messages
60
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,526
please, can you post the source code?
may be i can help you.
thx
 

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
Hi faraj,

Which MCU do you use it? AT89c52? AT89C52 don't have external ram. So, you have to use internal ram.

Hope can help you.

Good Luck..
 

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
Help said:
Hi faraj,

Which MCU do you use it? AT89c52? AT89C52 don't have external ram. So, you have to use internal ram.

Hope can help you.

Good Luck..
hi. yes i have used AT89c52. but i don't have any problem with ram. the pointer used for reading external data in my code is not for reading external ram. it is for reading isa ported device. thanks for your interest.
 

vietdung79

Junior Member level 3
Joined
Aug 1, 2007
Messages
31
Helped
5
Reputation
10
Reaction score
0
Trophy points
1,286
Location
Hanoi City, Vietnam
Activity points
1,404
Maybe a error in the interupt function.
You have to add:

Code:
if (TI) TI=0;

in this.

and I think you don't have to add the #ifndef in the init function if you don't need it.

Regards.
 

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
vietdung79 said:
Maybe a error in the interupt function.
You have to add:

Code:
if (TI) TI=0;

in this.

and I think you don't have to add the #ifndef in the init function if you don't need it.

Regards.
I tried this. in the interrupt routine i placed

Code:
if (RI)
    {...}
else 
    TI = 0;
but in this case I have to set TI before each printf function manually and that cause the loss of transmitted data to the PC.
 

vietdung79

Junior Member level 3
Joined
Aug 1, 2007
Messages
31
Helped
5
Reputation
10
Reaction score
0
Trophy points
1,286
Location
Hanoi City, Vietnam
Activity points
1,404
Did you try this yet?

I think you are wrong fundamentally in your theory. In sending data, TI is set by hardware and need clear by software for next time when finish sending data. So you have to clear TI in the init function.

Regards.
 

    faraj

    Points: 2
    Helpful Answer Positive Rating

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
vietdung79 said:
Did you try this yet?

I think you are wrong fundamentally in your theory. In sending data, TI is set by hardware and need clear by software for next time when finish sending data. So you have to clear TI in the init function.

Regards.
yes I have tried this and it is not sending data. I have read from Mazidi's 8051 book that you must set the TI flag for sending the first character. and that is right. when you start with cleared TI flag sending data could not begin.
but I think about your suggession on rewriting the putchar() function. may be it could solve my problem, but I am not so proffessinal to do this.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top