reagle 7 Posted September 16, 2016 Share Posted September 16, 2016 Stumbled on this strange behavior when using Energia with 430G2553 Launchpad and also Fraunchpad. Any time I try to do a long write to I2C device, only 17 bytes get put on the actual wire. What am I missing here? Code typically looks like this- I start transmission, sit in the loop sending data and then end transmission. Here is an example with a bunch of debug : { byte temp=0; Serial.println("Transmitting display data"); Wire.beginTransmission(SSD_ADDR); Serial.print("\t"); Serial.print(SSD_DUMMY_BYTE_C,HEX); Serial.print("\t"); Serial.println(Wire.write(SSD_DUMMY_BYTE_C)); Serial.print("\t"); Serial.print(0xA2,HEX); Serial.print("\t"); Serial.println(Wire.write(0xA2)); Serial.print("\t"); Serial.print(SSD_DUMMY_BYTE_D,HEX); Serial.print("\t"); Serial.println(Wire.write(SSD_DUMMY_BYTE_D)); while(len--) { Serial.print("\t"); Serial.print(len); Serial.print("\t"); temp=*databuf++; Serial.print(temp,HEX); Serial.print("\t"); Serial.println(Wire.write(temp)); } Serial.println(Wire.endTransmission()); } Len is usually 30-60 bytes, and databuffer is sized appropriately. I see the code iterate through it correct number of times, but less bytes are sent out. This is in Energia 14 at the moment, though I tried newer version as well. Typical output is below. You can see how write status goes from 1 to 0 after 17 bytes. The last value is return status from Wire.endTransmission, and it is 0, so it appears the system thinks all is happy Transmitting display data 80 1 A2 1 0 1 67 40 1 66 55 1 65 55 1 64 1 1 63 0 1 62 0 1 61 0 1 60 54 1 59 55 1 58 15 1 57 0 1 56 0 1 55 0 1 54 40 0 53 55 0 52 55 0 51 1 0 50 0 0 49 0 0 48 0 0 47 0 0 46 55 0 45 50 0 44 55 0 43 0 0 42 0 0 41 0 0 40 A0 0 39 A0 0 38 AA 0 37 A 0 36 0 0 35 0 0 34 0 0 33 0 0 32 54 0 31 55 0 30 15 0 29 0 0 28 0 0 27 0 0 26 80 0 25 AA 0 24 AA 0 23 2 0 22 0 0 21 0 0 20 0 0 19 50 0 18 55 0 17 1 0 16 54 0 15 0 0 14 0 0 13 0 0 12 A0 0 11 A0 0 10 AA 0 9 A 0 8 0 0 7 0 0 6 0 0 5 40 0 4 55 0 3 55 0 2 5 0 1 0 0 0 2 0 0 Quote Link to post Share on other sites
reagle 7 Posted September 16, 2016 Author Share Posted September 16, 2016 Also tried using Serial.println(Wire.write(databuf,len)); Status comes back with the right number of bytes sent, but once again I only see 17 of them on the bus before the Stop condition is issued Quote Link to post Share on other sites
Rei Vilo 695 Posted September 16, 2016 Share Posted September 16, 2016 Check the size of the buffer for I2C on the Wire library. It may be limited to 16 bytes. Fmilburn 1 Quote Link to post Share on other sites
solipso 8 Posted September 16, 2016 Share Posted September 16, 2016 Even Pete Scargill got bitten by this. See http://tech.scargill.net/i2c-the-easy-way/ Quote Link to post Share on other sites
reagle 7 Posted September 16, 2016 Author Share Posted September 16, 2016 Oh, that makes sense! Buffer is indeed 16 bytes, but it appears to "work" if I issue repeated start after the first command bytes go out. Basically if I add Serial.println(Wire.endTransmission(false)); before the big loop, then it does send the right number of bytes. Now the bytes themselves are not what they should be so I am probably just crawling some random memory location Will fiddle with buffer size instead. Thanks! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.