75 #define DEFAULT_I2C I2C0
77 #define I2C_EEPROM_BUS DEFAULT_I2C
78 #define I2C_IOX_BUS DEFAULT_I2C
80 #define SPEED_100KHZ 100000
81 #define SPEED_400KHZ 400000
84 static const char menu[] =
85 "**************** I2C Demo Menu ****************\r\n"
87 "\t1: Select I2C peripheral [\033[1;32mI2C%d\033[0;37m]\r\n"
88 "\t2: Toggle mode POLLING/INTERRUPT [\033[1;32m%s\033[0;37m]\r\n"
89 "\t3: Probe for Slave devices\r\n"
90 "\t4: Read slave data\r\n"
91 "\t5: Write slave data\r\n"
92 "\t6: Write/Read slave data\r\n";
99 #define I2C_SLAVE_EEPROM_SIZE 64
100 #define I2C_SLAVE_EEPROM_ADDR 0x5A
101 #define I2C_SLAVE_IOX_ADDR 0x5B
136 for (i = 0; i < sz; i++) {
137 if (!(i & 0xF))
DEBUGOUT(
"\r\n%02X: ", i);
152 while (!input_valid) {
161 if (x ==
EOF)
continue;
162 if (i >=
sizeof(ch) - 2)
break;
163 if ((x ==
'\r' || x ==
'\n') && i) {
178 i = strtol(ch, &ptr, 0);
181 DEBUGOUT(
"Invalid input. Retry!\r\n");
188 static int sind = -1;
190 if (sind >=
sizeof(val)) sind = -1;
191 while (sind < 0 && (
tick_cnt & 0x7F)) {}
223 for (i = 0; i < tmp; i++) {
238 NVIC_EnableIRQ(I2C0_IRQn);
241 NVIC_DisableIRQ(I2C0_IRQn);
265 DEBUGOUT(
"Probing available I2C devices...\r\n");
266 DEBUGOUT(
"\r\n 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
267 DEBUGOUT(
"\r\n====================================================");
268 for (i = 0; i <= 0x7F; i++) {
269 if (!(i & 0x0F))
DEBUGOUT(
"\r\n%02X ", i >> 4);
270 if (i <= 7 || i > 0x78) {
293 xfer->
rxSz = xfer->
txSz = sz - buff[0] + 1;
299 static int is_addr = 1;
318 if (seep_xfer.
rxSz == 1)
325 if (seep_xfer.
txSz == 1)
352 #ifndef CHIP_LPC11CXX
377 if(iox_xfer.
txSz == 1) {
388 #ifndef CHIP_LPC11CXX
447 DEBUGOUT(
"End of I2C Demo! Bye!\r\n");
471 if (xfer.
txSz == 0)
break;
479 if (!tmp && !xfer.
txSz)
break;
481 DEBUGOUT(
"Master transfer : %s\r\n",
488 DEBUGOUT(
"Input Invalid! Try Again.\r\n");