only for LPC824 chip to match hardware I2C channels(2->4)

Dependencies:   mbed

Revision:
7:46655bc3288b
Parent:
6:9368ba5f485c
Child:
9:78c43e2448d6
--- a/main.cpp	Fri Oct 24 11:08:06 2014 +0000
+++ b/main.cpp	Sun Oct 26 15:32:59 2014 +0000
@@ -1,5 +1,4 @@
 #include "mbed.h"
-#include "i2c_api.h"
 
 Serial pc(USBTX,USBRX);
 /*
@@ -18,7 +17,7 @@
 I2C dev3(A2,A3);//23,22
 I2C dev4(A4,A5);//21,20
 BusOut bus(LED1,LED2,LED3,LED4);
-DigitalOut led1(LED1);
+//DigitalOut led1(LED1);
 //DigitalOut led2(LED2);
 //DigitalOut led3(LED3);
 //DigitalOut led4(LED4);
@@ -37,18 +36,19 @@
 int main()
 {
     I2C* dev=&dev1;
-    pc.baud(9600);
+    pc.baud(19200);
     dev1.frequency(100000);//100k
     dev2.frequency(100000);//100k
     dev3.frequency(100000);//100k
     dev4.frequency(100000);//100k
 
-///** debug code
-pc.printf("assign0: %08X\n\r",LPC_SYSCON->PRESETCTRL );//??_??_??_(?|4)?
+/** debug code
+pc.printf("assign0: %08X\n\r",LPC_SYSCON->PRESETCTRL );//????_??(?|4)?
 pc.printf("enable I2C0: %08X\n\r",LPC_SWM->PINENABLE0);//????_(C|?)???
-pc.printf("assign1: %08X\n\r",LPC_SWM->PINASSIGN[9] );//23_14_06_??
-pc.printf("assign2: %08X\n\r",LPC_SWM->PINASSIGN[10] );//??_20_21_22
+pc.printf("assign1: %08X\n\r",LPC_SWM->PINASSIGN[9] );//170E_06??
+pc.printf("assign2: %08X\n\r",LPC_SWM->PINASSIGN[10] );//??_14_15_16
 pc.printf("clock: %08X\n\r",LPC_SYSCON->SYSAHBCLKCTRL );// ??_(?|E)?_??_(?|2)?
+pc.printf("LPC_I2C0: %08X, ",LPC_I2C0 );
 pc.printf("dev1: %08X\n\r",dev1 );
 pc.printf("LPC_I2C1: %08X, ",LPC_I2C1 );
 pc.printf("dev2: %08X\n\r",dev2 );
@@ -56,15 +56,42 @@
 pc.printf("dev3: %08X\n\r",dev3 );
 pc.printf("LPC_I2C3: %08X, ",LPC_I2C3 );
 pc.printf("dev4: %08X\n\r",dev4 );
+
 pc.printf("dev: %08X\n\r",*dev );
+
 dev=&dev2;
 pc.printf("dev: %08X\n\r",*dev );
+
 dev=&dev3;
 pc.printf("dev: %08X\n\r",*dev );
+
 dev=&dev4;
 pc.printf("dev: %08X\n\r",*dev );
+
+
+i2c_t *obj0;
+//i2c_t *obj1;
+//i2c_t *obj2;
+//i2c_t *obj3;
+obj0->i2c = (LPC_I2C0_Type *)(LPC_I2C0);
+//obj1->i2c = (LPC_I2C0_Type *)(LPC_I2C1);
+//obj2->i2c = (LPC_I2C0_Type *)(LPC_I2C2);
+//obj3->i2c = (LPC_I2C0_Type *)(LPC_I2C3);
+
+printf("obj0: %08X\n\r",obj0->i2c->STAT);
+//printf("obj1: %08X\n\r",obj1->i2c->STAT);
+//printf("obj2: %08X\n\r",obj2->i2c->STAT);
+//printf("obj3: %08X\n\r",obj3->i2c->STAT);
+
+
 dev=&dev1;
-//*/
+
+dev1.start();
+dev1.write(0x90);
+dev1.write(0xAA);
+dev1.write(0x55);
+dev1.stop();
+*/
 //    int data=0x50;
 //    int ack=0;
     int plength=0;
@@ -93,14 +120,14 @@
     int i=0;
     while(1) {
         while(true) {
-            led1=0;
+////            led1=0;
             read=pc.getc();
             recieve[i]=read;
 //pc.printf("%02X,",read); //debug
             i++;
             if(read == 'P') {
                 plength=i;
-                led1=1;
+////                led1=1;
 //pc.printf("P\n\r");
                 break;
             }
@@ -150,7 +177,9 @@
 //dev1.start();
 //dev1.write(address);
                     dev->start();
+//printf("start: %08X\n\r",obj0->i2c->MSTCTL);
                     dev->write(address);
+//printf("write: %08X\n\r",obj0->i2c->STAT);
                     if( (address&0x01)) {//read
 //pc.printf("read from ch%c,",channel);
                         for(int j=0; j<length; j++) {
@@ -171,6 +200,7 @@
                 case 'P':
 //dev1.stop();
                     dev->stop();
+//printf("stop: %08X\n\r",obj0->i2c->MSTCTL);
                     i=plength;
                     pc.printf("ok\n\r");
                     break;