Reproduce https://mbed.org/forum/bugs-suggestions/topic/4128/ bug in med-NXP
main.cpp@0:308c98db9173, 2013-05-19 (annotated)
- Committer:
- humlet
- Date:
- Sun May 19 07:15:51 2013 +0000
- Revision:
- 0:308c98db9173
reproduce ; https://mbed.org/forum/bugs-suggestions/topic/4128/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
humlet | 0:308c98db9173 | 1 | #include "mbed.h" |
humlet | 0:308c98db9173 | 2 | #include "I2C.h" |
humlet | 0:308c98db9173 | 3 | |
humlet | 0:308c98db9173 | 4 | int main() |
humlet | 0:308c98db9173 | 5 | { |
humlet | 0:308c98db9173 | 6 | const int len = 128; |
humlet | 0:308c98db9173 | 7 | char strs[2][len]; |
humlet | 0:308c98db9173 | 8 | |
humlet | 0:308c98db9173 | 9 | I2C i2c(p28, p27); |
humlet | 0:308c98db9173 | 10 | const uint32_t adr = 0x70<<1; |
humlet | 0:308c98db9173 | 11 | char rData[5]; |
humlet | 0:308c98db9173 | 12 | char wData[5]; |
humlet | 0:308c98db9173 | 13 | |
humlet | 0:308c98db9173 | 14 | for(int i=0; i<2; i++) { |
humlet | 0:308c98db9173 | 15 | // read SW rev from register 0x00 from a srf08 ultra sonic ranger at i2c address 0x70/0xe0 |
humlet | 0:308c98db9173 | 16 | wData[0] = 0x00; // register address |
humlet | 0:308c98db9173 | 17 | int wStat = i2c.write(adr,wData,1,1); // write register address and keep bus open, i.e. don't finish write sequence with an instnt stop condition |
humlet | 0:308c98db9173 | 18 | if(i)wait_us(23); // grant some time to the i2c HW to start the unintentional additional write |
humlet | 0:308c98db9173 | 19 | rData[0]=0xff; |
humlet | 0:308c98db9173 | 20 | int rStat = i2c.read(adr,rData,1); // read srf08's SW rev from register 0x00. If in time, the start condition at the beginning of the sequence would abort the unitended write |
humlet | 0:308c98db9173 | 21 | snprintf(strs[i],len,"wStat=0x%02X rStat=0x%02X rData=0x%02X %s\n",wStat,rStat,rData[0], ((wStat|rStat)?"OUCH!":"OK!")); |
humlet | 0:308c98db9173 | 22 | } |
humlet | 0:308c98db9173 | 23 | printf(strs[0]); |
humlet | 0:308c98db9173 | 24 | printf(strs[1]); |
humlet | 0:308c98db9173 | 25 | return 0; |
humlet | 0:308c98db9173 | 26 | } |