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.
Fork of BAE_FRDM by
slave.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "slave.h" 00004 00005 void write_to_master(char); //function to write data to master 00006 00007 I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave 00008 00009 Serial pcslave(USBTX, USBRX); 00010 DigitalOut data_ready(D10); 00011 int i2c_status=0; //read/write mode for i2c 0 : write2slave, 1 : write2master 00012 int reset=0; 00013 int temp; 00014 00015 typedef struct 00016 { 00017 char data; // To avoid dynamic memory allocation 00018 int length; 00019 }i2c_data; 00020 00021 00022 00023 Mail<i2c_data,16> i2c_data_receive; 00024 Mail<i2c_data,16> i2c_data_send; 00025 00026 00027 void FUNC_I2C_WRITE2CDMS(char *data, int length=1) 00028 { 00029 int slave_status = 1; 00030 00031 while(slave_status) 00032 { 00033 slave.address(0x20); 00034 if(slave.receive()==1) 00035 { 00036 slave_status=slave.write(data,length); 00037 00038 00039 } 00040 else if(slave.receive()==3 || slave.receive()==2) 00041 { 00042 slave_status=slave.read(data,length); 00043 } 00044 00045 } 00046 printf("\ndone\n\r"); 00047 00048 } 00049 char data_send,data_receive; 00050 void T_I2C_BAE() 00051 { 00052 //char data_send,data_receive; 00053 //while(1) 00054 //{ 00055 // Thread::signal_wait(0x1); 00056 //i2c_status = temp; 00057 //wait(0.5); 00058 printf("\n entered thread\n\r"); 00059 if(i2c_status == 0 && reset !=1) 00060 { 00061 00062 FUNC_I2C_WRITE2CDMS(&data_receive); 00063 i2c_data * i2c_data_r = i2c_data_receive.alloc(); 00064 i2c_data_r->data = data_receive; 00065 i2c_data_r->length = 1; 00066 i2c_data_receive.put(i2c_data_r); 00067 printf("\n Data received from CDMS is %c\n\r",data_receive); 00068 i2c_data_receive.free(i2c_data_r); // This has to be done from a differen thread 00069 00070 } 00071 else if(i2c_status ==1 && reset !=1) 00072 { 00073 osEvent evt = i2c_data_send.get(); 00074 if (evt.status == osEventMail) 00075 { 00076 i2c_data *i2c_data_s = (i2c_data*)evt.value.p; 00077 data_send = i2c_data_s -> data; 00078 FUNC_I2C_WRITE2CDMS(&data_send); 00079 printf("\nData sent to CDMS is %c\n\r",data_send); 00080 i2c_data_send.free(i2c_data_s); 00081 i2c_status = 0; 00082 //temp = i2c_status; 00083 } 00084 } 00085 00086 //} 00087 } 00088 00089 00090 00091 void FUNC_INT() 00092 { 00093 reset = 0; 00094 00095 00096 } 00097 00098 void FUNC_RESET() 00099 { 00100 reset = 1; 00101 } 00102 00103 void ir2master() 00104 { 00105 00106 char data='a'; 00107 data_ready=0; 00108 data = pcslave.getc(); 00109 reset =0; 00110 i2c_status=1; 00111 i2c_data * i2c_data_s = i2c_data_send.alloc(); 00112 i2c_data_s->data = data; 00113 i2c_data_s->length = 1; 00114 i2c_data_send.put(i2c_data_s); 00115 data_ready=1; 00116 //temp = i2c_status; 00117 } 00118 00119 00120 00121 00122 00123
Generated on Tue Jul 12 2022 22:08:21 by
1.7.2
