Checking for data on the I2C bus (without Wire.h)
hi! here's little problem has had me stumped last couple of days, , think it's time throw in towel , ask 
i have have peggy2 pegboard ("peggy"), arduino duemilanove 328p , lot of leds. (http://evilmadscience.com/productsmenu/tinykitlist/75). talks board, "megaman", arduino mega2560, on i2c.
for reasons i'd rather not spend long arguing (i notice "use wire library heaven's sake" answer common here , reason i'd
), cannot use wire library on peggy. on megaman, though. peggy receiving slave , megaman transmitting master. megaman transmits peggy either header indicates animation peggy supposed display (hardcoded peggy , referred number after header), or full framebuffer, allowing peggy "stream" whatever megaman sends it, example scrolling text. works quite well.
i have 1 problem though, , whenever make peggy run built-in animation, can take several seconds complete, want interrupt animation if new data received on i2c bus. example have "busy" animation (equivalent hour glass in windows or spinning beach ball of death on mac) peggy runs when waiting data megaman under conditions.
the i2c implementation on peggy *not* interrupt driven, screen update run on timer interrupt, , spend of time on peggy sitting in while-loop waiting state change (it after purpose of peggy, there no need fancy):
when state change occurs,
there additional error handling (i ignore errors, dropped frame or animation matters little) , such, , again works well. far good.
the problem arises when try build mechanism abort animation upon data received on i2c bus. quite cannot abort. pseudo code typical animation simplified:
the abortflag set false after each completed byte read i2c bus.
i tried using isr (timer0_compa_vect) purpose update "screen", i.e. peggy's 625leds, put check new data on i2c bus , update abortflag correspondingly:
if (twdr == 0xde) abortflag = true; did not work (never triggered) - tried 0xde start of header megaman sends every time has new data
if (twcr & (1<<twint)) abortflag = true; did not work (triggers time , prevents animations running)
if ( (twcr & (1<<twint)) && (twsr == twi_srx_adr_data_ack) ) abortflag = true; did not work (never triggers)
if (twsr == twi_srx_adr_data_ack) abortflag = true; did not work (never triggers)
this of course done without interrupts - 1 substitute if (abortflag) return; 1 of checks above, didn't make difference, , i'd rather not miss happens while i'm doing animation, suppose timer interrupt better. tried using dedicated i2c interrupt, (with checks above):
i here got same result putting in timer interrupt. must admit i'm @ witt's end here. there tried & tested way of answering question: have data waiting me @ i2c bus, or better yet: data waiting me @ i2c bus 0xde?

i have have peggy2 pegboard ("peggy"), arduino duemilanove 328p , lot of leds. (http://evilmadscience.com/productsmenu/tinykitlist/75). talks board, "megaman", arduino mega2560, on i2c.
for reasons i'd rather not spend long arguing (i notice "use wire library heaven's sake" answer common here , reason i'd
), cannot use wire library on peggy. on megaman, though. peggy receiving slave , megaman transmitting master. megaman transmits peggy either header indicates animation peggy supposed display (hardcoded peggy , referred number after header), or full framebuffer, allowing peggy "stream" whatever megaman sends it, example scrolling text. works quite well.i have 1 problem though, , whenever make peggy run built-in animation, can take several seconds complete, want interrupt animation if new data received on i2c bus. example have "busy" animation (equivalent hour glass in windows or spinning beach ball of death on mac) peggy runs when waiting data megaman under conditions.
the i2c implementation on peggy *not* interrupt driven, screen update run on timer interrupt, , spend of time on peggy sitting in while-loop waiting state change (it after purpose of peggy, there no need fancy):
code: [select]
while (!(twcr & (1<<twint))) { } // wait twint setwhen state change occurs,
code: [select]
switch (twsr), , if twsr either twi_srx_adr_data_ack or twi_srx_gen_data_ack (received byte of data), read byte twdr , reset control register code: [select]
twcr = (1<<twen)|(1<<twint)|(1<<twea) stuff based on byte received was, example run "waiting" animation.there additional error handling (i ignore errors, dropped frame or animation matters little) , such, , again works well. far good.
the problem arises when try build mechanism abort animation upon data received on i2c bus. quite cannot abort. pseudo code typical animation simplified:
code: [select]
switch (animation) {
case (1) : // "busy" animation
for(iterations = 10; iterations >0; iterations--) {
if (abortflag) return; // if abort flag (a volatile boolean) set, return reading data i2c bus
drawbusyanimationfram(iterations);
}
break;
}
the abortflag set false after each completed byte read i2c bus.
i tried using isr (timer0_compa_vect) purpose update "screen", i.e. peggy's 625leds, put check new data on i2c bus , update abortflag correspondingly:
if (twdr == 0xde) abortflag = true; did not work (never triggered) - tried 0xde start of header megaman sends every time has new data
if (twcr & (1<<twint)) abortflag = true; did not work (triggers time , prevents animations running)
if ( (twcr & (1<<twint)) && (twsr == twi_srx_adr_data_ack) ) abortflag = true; did not work (never triggers)
if (twsr == twi_srx_adr_data_ack) abortflag = true; did not work (never triggers)
this of course done without interrupts - 1 substitute if (abortflag) return; 1 of checks above, didn't make difference, , i'd rather not miss happens while i'm doing animation, suppose timer interrupt better. tried using dedicated i2c interrupt, (with checks above):
code: [select]
isr (twi_vect)
{
if (twsr == twi_srx_adr_ack) {
abortflag = true;
}
}i here got same result putting in timer interrupt. must admit i'm @ witt's end here. there tried & tested way of answering question: have data waiting me @ i2c bus, or better yet: data waiting me @ i2c bus 0xde?
quote
i have have peggy2 pegboard ("peggy"), arduino duemilanove 328p ... cannot use wire library on peggy.
why not?
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Checking for data on the I2C bus (without Wire.h)
arduino
Comments
Post a Comment