Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:e2acb437847f
diff -r 000000000000 -r e2acb437847f main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Jan 20 17:57:59 2015 +0000
@@ -0,0 +1,77 @@
+#include "mbed.h"
+I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave
+Serial pc (USBTX,USBRX);
+InterruptIn master_intrpt(D9);
+
+DigitalOut slave_intrpt(D10);
+
+int ack0 = 1;
+int ack1 = 1; //read/write mode for i2c 0 : write2slave, 1 : write2master
+
+
+char writedata;
+char readdata;
+
+void FUNC_I2C_WRITE2CDMS()
+{
+
+ slave.address(0x20);
+ while(ack0==1)
+ {
+ if(slave.receive()==1)
+ {
+ ack0=slave.write(&writedata,1);
+
+
+ }
+ else if(slave.receive()==3 || slave.receive()==2)
+ {
+ ack1=slave.read(&readdata,1);
+ }
+ }
+ if(!ack0 )
+ {
+ printf("slave has written %c to slave\n\r",writedata);
+ //printf("\n \r %d %d %d %d %d\n",*data_reg,*status_reg,*c1_reg,*c2_reg,*freq_reg);
+ }
+ else
+ {
+ printf("\n\r data not written to slave \n");
+ }
+ if(!ack1 )
+ {
+ printf("slave has read %c to master \n \r",writedata);
+ //printf("\n \r %d %d %d %d %d\n",*data_reg,*status_reg,*c1_reg,*c2_reg,*freq_reg);
+ }
+ else
+ {
+ printf("\n\r data not read from master \n");
+ }
+}
+
+
+void FUNC_INT()
+{
+
+ FUNC_I2C_WRITE2CDMS();
+ slave_intrpt = 0;
+}
+
+
+
+
+
+int main()
+{
+ printf("\n slave started\n\r");
+
+ master_intrpt.rise(&FUNC_INT);
+ while(1)
+ {
+ writedata = pc.getc();
+ slave_intrpt=1;
+
+ }
+
+}
+
\ No newline at end of file