View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
Is polled slave I2C possible? |
Posted: Fri Nov 14, 2008 3:46 am |
|
|
Hi,
I am writing an I2C bootloader and I don't want the bootloader to use the interrupt vectors. I will just relocate them.
By not using interrupts, it would need to have the interrupt flag polled in the main loop. I don't know if it is fast enough to handle the I2C rate.
Have you done anything like this before? I need some sugestions.
Thank you. |
|
|
Ttelmah Guest
|
|
Posted: Fri Nov 14, 2008 4:18 am |
|
|
Done properly, this can be _faster_ than using the actual interrupt.
Basically, when the interrupt triggers, the processor 'calls' the main ISR vector. At this point, it has to save a whole 'suite' of registers, then test what interrupt flag has set, and that it has it's interrupt enable also on, to detect what interrupt has triggered. Only after doing all this, does it actually jump to the 'service routine'. Typically something like 30 instruction cycles occur from the moment the interrupt triggers to the point whre the routine is entered. If you declare the interrupt 'flag', using a bit directive, clear it, then simply sit waiting for it to go true, the response, will only be perhaps three or four instruction times after it triggers. Much faster...
Yes, this is a perfectly 'sensible' way to work, and works fine.
Best Wishes |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Fri Nov 14, 2008 8:40 am |
|
|
The program does a lot more than the i2c comm and there are routines that take a few miliseconds to complete. That will delay the i2c handling and probably overflow the ssp register, am I right? |
|
|
Ttelmah Guest
|
|
Posted: Fri Nov 14, 2008 9:43 am |
|
|
Depends.
I2C, supports 'clock stretching', where the slave device holds the clock low, till _it_ has completed. You would need to enable this, and write your master code to wait till the slave releases the bus, while the 'slow parts' take place.
Best Wishes |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Fri Nov 14, 2008 7:21 pm |
|
|
Yes, it works after the first byte is processed, but what if the master send a few bytes before the slave can process the first one? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Nov 15, 2008 2:59 am |
|
|
The discussion is somewhat bloodless without considering the actual application protocol. With a bootloader, the only time consuming action is erasing and writing to the flash. I assume that the bootloader data is buffered, then the I2C master may start programming of a block and do repeated status requests. No ACK to the request can be regarded as busy state. |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sat Nov 15, 2008 5:00 am |
|
|
FvM, you are right. I am confusing things. The loaded app will be complex... the boot loader will be a simple loop to receive bytes. |
|
|
|