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 TFOX_i2cslave by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 Serial pc(USBTX,USBRX); 00004 InterruptIn irpt_4m_mstr(D11); //I2c interrupt from CDMS 00005 DigitalOut irpt_2_mstr(D12); //I2C interrupt to CDMS 00006 I2CSlave slave (D14,D15); 00007 00008 const int addr = 0x20; //slave address 00009 char data_receive; 00010 char data_send; 00011 Thread *ptr_t_i2c; 00012 00013 Timer t; // time taken from isr to reach i2c function 00014 Timer t1; 00015 bool write_ack = 1; 00016 bool read_ack = 1; 00017 char data; 00018 char length = 1; 00019 void T_I2C_SLAVE(void const * args) 00020 { 00021 while(1) 00022 { 00023 Thread::signal_wait(0x1); 00024 wait_us(100); // can be between 38 to 15700 00025 //printf("\n\r check 1\n"); 00026 t.stop(); 00027 if( slave.receive() == 0) 00028 //slave.stop(); 00029 if( slave.receive() == 1) // slave writes to master 00030 { 00031 t1.start(); 00032 write_ack=slave.write(&data,length); 00033 t1.stop(); 00034 //slave.stop(); 00035 } 00036 if( slave.receive()==3 || slave.receive()==2) // slave read 00037 { 00038 t1.start(); 00039 read_ack=slave.read(&data,length); 00040 t1.stop(); 00041 //slave.stop(); 00042 } 00043 printf("\n \r %d %d\n",t.read_us(),t1.read_us()); 00044 t.reset(); 00045 t1.reset(); 00046 00047 if(write_ack == 0) 00048 printf("\n\rData sent to CDMS is %c\n",data); 00049 if(read_ack == 0) 00050 printf("\n\r Data received from CDMS is %c \n",data); 00051 } 00052 } 00053 00054 00055 void FCTN_ISR_I2C() 00056 { 00057 ptr_t_i2c->signal_set(0x1); 00058 t.start(); 00059 } 00060 00061 int main() 00062 { 00063 printf("\n\r SLAVE ACTIVATED\n"); 00064 slave.address(addr); 00065 //slave.frequency(100000); 00066 ptr_t_i2c = new Thread(T_I2C_SLAVE); 00067 irpt_4m_mstr.enable_irq(); 00068 //irpt_4m_mstr.mode(PullDown); 00069 irpt_4m_mstr.rise(&FCTN_ISR_I2C); 00070 00071 }
Generated on Sat Jul 16 2022 13:39:10 by
