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,601
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.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
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.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
yes i use keil, and why should i er-write the putchar function and what changes is needed?vietdung79 said:What compiler do you use?
If you use Keil, you should re-write the putchar() function.
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.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
yes, that topic in the link is exactly my problem.wek said:NEVER MIX interrupt-based reception with "main-based" transmission (and vice versa) in '51!
See **broken link removed** and link therein.
JW
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.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.
download the source from the above post.aupa said:please, can you post the source code?
may be i can help you.
thx
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.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..
if (TI) TI=0;
I tried this. in the interrupt routine i placedvietdung79 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.
if (RI)
{...}
else
TI = 0;
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.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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?