We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am having a problem with my I2C. I am using a 89C664 philips microcontroller. I have two of these chips talking to each other. I have my I2C implemented in such a way that if the state (S1STA) doesn't match the correct value, my program will just keep waiting. Since this only happen very rarely, I want to implement a timer so it will automatically be forced out of the subrountine after one or two second. The question can I implement this within an interrupt, because my I2C is called based on interrupt. Also, how would I implement this timer. I am new to this, so any help would be greatly appreciated. The whole point of this is so my chip can resend the data or receive the data again if I2C failed. thanks Tommy
I think that you can use an interrupt in an ohter interrupt sub-routine without any trouble! In general each time your program get to interrupt sub-routine, programs disable all the interrupt requests. In your case, don't disable all interrupts. Just stay activated your timer interrupt. You just need to configure your Timer during the init of your program. And when your program jump to your interrupt sub-routine, launch the timer for 1 or 2 sec as you say. Stop it when your program left the sub-routine. If the program branch to timer sub-routine during the I2C interrupt sub-routine, do what is needed to left your I2C sub-routine
So if I want my timer to count for 1 second, what do I need to do. If I am using a 13.5MHz clock, what are the registers that I need to configured? I am very new to this timer thing, so any help is appreciated. Is there equations that I can look at? Also, how do I start and end the timer? thanks Tommy
The first thing that you can do: Find the datasheet of your µC. Read it and you will find how to configure all registers of your 8051 unit. for exemple: If you would like to use the Timer 1 of your µC, you must find some notes about TCON, TMOD, TH1, TL1 registers. The @B/B@nterrupt Enable register is IE