UART to I2C master(s) converter, targetting to emulate SC18IM700(NXP) chip
UART to I2C master(s) converter, targetting to emulate SC18IM700(NXP) chip
Features
up to 4x I2C master
- for LPC824 implement, we can use up to 4 channels of I2C masters
- 1x Fm+ and 3x Fm I2C channels
- for LPC1768 implement, we can use up to 2 channels of I2C masters
- 2x Fm I2C channels
- for LPC11U35 implement, only one channel for I2C master,
but program uses USB CDC class for UART communication (means no external USB-Serial converter chip)
- 1x Fm+ I2C channels
1x SPI master
up to 2x 8bit GPIO
Tested Platforms
LPC824
- https://developer.mbed.org/platforms/Switch-Science-mbed-LPC824/
- https://developer.mbed.org/platforms/LPCXpresso824-MAX/
LPC1768
LPC11U35
Quote:
LPC11U35 implement requires importing USBDevice library to use USBSerial class
visit https://github.com/K4zuki/tinyI2C for more information
Diff: main.cpp
- Revision:
- 40:78e0ee75a604
- Parent:
- 39:5817c3e6ce1e
- Child:
- 41:b7c84115a2dd
diff -r 5817c3e6ce1e -r 78e0ee75a604 main.cpp --- a/main.cpp Fri Oct 17 20:48:15 2014 +0000 +++ b/main.cpp Tue Oct 21 03:55:14 2014 +0000 @@ -9,14 +9,8 @@ #endif I2C dev1(p9,p10); I2C dev2(p28,p27); -//I2C dev3(A5,A4); -//I2C dev4(A5,A4); I2C* dev=&dev1; -BusOut bus(LED1,LED2,LED3,LED4); -//DigitalOut led1(LED1); -//DigitalOut led2(LED2); -//DigitalOut led3(LED3); -//DigitalOut led4(LED4); +BusOut bus(LED1,LED2); //Table 3. ASCII commands supported by SC18IM700 //ASCII command Hex value Command function @@ -36,11 +30,8 @@ dev1.frequency(100000);//100k dev2.frequency(100000);//100k - int data=0x50; - int ack=0; int plength=0; char recieve[256]; - char send[256]; char read=0; int address=0,length=0,channel=0; enum reg { @@ -49,25 +40,16 @@ I2C2adr='2', I2C3adr='3', }; -//"C0P" -//"S(0x80)(4)(0xDEADBEAF)P" -//"C1P" -//"S(0x80)(4)(0xDEADBEAF)P" -//"C2P" -//"S(0x80)(4)(0xDEADBEAF)P" -//"C3P" -//"S(0x80)(4)(0xDEADBEAF)P" - int i=0; while(1) { while(true) { read=pc.getc(); recieve[i]=read; -// ser.printf("%02X,",read); +//pc.printf("%02X,",read); i++; if(read == 'P') { plength=i; -// ser.printf("P\n\r"); +//pc.printf("P\n\r"); break; } } @@ -79,29 +61,30 @@ switch(channel) { case I2C0adr: bus=0x01; -// pc.printf("ch0 is selected,"); +//pc.printf("ch0 is selected,"); channel='0'; dev=&dev1; break; case I2C1adr: bus=0x02; -// pc.printf("ch1 is selected,"); -// pc.printf("ch1 is not implemented,"); +//pc.printf("ch1 is selected,"); channel='1'; dev=&dev2; break; +/** LPC1768 has only two I2C channels case I2C2adr: bus=0x04; -// pc.printf("ch2 is not implemented,"); +//pc.printf("ch2 is not implemented,"); channel='0'; //dev=&dev3; break; case I2C3adr: bus=0x08; -// pc.printf("ch0 is not implemented,"); +//pc.printf("ch0 is not implemented,"); channel='0'; //dev=&dev4; break; +*/ default: channel='0'; dev=&dev1; @@ -112,22 +95,20 @@ case 'S': address=recieve[i+1]; length=recieve[i+2]; -// pc.printf("addr=%02X, length=%d,",address,length); +//pc.printf("addr=%02X, length=%d,",address,length); dev->start(); dev->write(address); if( (address&0x01)) {//read -// pc.printf("read from ch%c,",channel); +//pc.printf("read from ch%c,",channel); for(int j=0; j<length; j++) { pc.putc(dev->read(0)); -// send[j]=dev->read(0); -// pc.printf("%02X,",dev->read(0)); +//pc.printf("%02X,",dev->read(0)); } i+=(3); } else {//write -// pc.printf("write to ch%c, ",channel); +//pc.printf("write to ch%c, ",channel); for(int j=0; j<length; j++) { -// send[j]=recieve[4+j]; -// pc.printf("%02X,",recieve[3+j]); +//pc.printf("%02X,",recieve[3+j]); dev->write(recieve[3+j]); } i+=(3+length);