![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
vr1.1
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of CDMS_RTOS_v1_1 by
i2c.cpp@8:607ae92fa6af, 2015-07-04 (annotated)
- Committer:
- cholletisaik777
- Date:
- Sat Jul 04 08:56:34 2015 +0000
- Revision:
- 8:607ae92fa6af
- Parent:
- 3:0c3f7c3fabc9
- Child:
- 12:cb3ee1ac3638
cdms_rtos_v1_0_3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cholletisaik777 | 0:d6e3d1e21484 | 1 | #include "mbed.h" |
cholletisaik777 | 0:d6e3d1e21484 | 2 | //#include "pin_config.h" |
cholletisaik777 | 0:d6e3d1e21484 | 3 | #include "i2c.h" |
cholletisaik777 | 8:607ae92fa6af | 4 | #include "all_funcs.h" |
cholletisaik777 | 0:d6e3d1e21484 | 5 | |
cholletisaik777 | 0:d6e3d1e21484 | 6 | Serial gc(USBTX,USBRX); |
sakthipriya | 3:0c3f7c3fabc9 | 7 | InterruptIn irpt_4m_slv(D9); //I2c interrupt from CDMS |
sakthipriya | 3:0c3f7c3fabc9 | 8 | DigitalOut irpt_2_slv(D8); //I2C interrupt to CDMS |
sakthipriya | 3:0c3f7c3fabc9 | 9 | I2C master(D14,D15); |
cholletisaik777 | 0:d6e3d1e21484 | 10 | |
cholletisaik777 | 0:d6e3d1e21484 | 11 | |
cholletisaik777 | 0:d6e3d1e21484 | 12 | |
cholletisaik777 | 0:d6e3d1e21484 | 13 | const int addr = 0x20; //slave address |
cholletisaik777 | 0:d6e3d1e21484 | 14 | Timer t; |
cholletisaik777 | 0:d6e3d1e21484 | 15 | |
cholletisaik777 | 0:d6e3d1e21484 | 16 | |
cholletisaik777 | 0:d6e3d1e21484 | 17 | void FCTN_I2C_READ(char *data, int length ) |
cholletisaik777 | 0:d6e3d1e21484 | 18 | { |
cholletisaik777 | 0:d6e3d1e21484 | 19 | bool read_ack = true; |
cholletisaik777 | 0:d6e3d1e21484 | 20 | irpt_2_slv = 0; |
cholletisaik777 | 0:d6e3d1e21484 | 21 | t.start(); |
cholletisaik777 | 0:d6e3d1e21484 | 22 | read_ack=master.read(addr|1,data,length); |
cholletisaik777 | 0:d6e3d1e21484 | 23 | t.stop(); |
cholletisaik777 | 0:d6e3d1e21484 | 24 | if(read_ack == 0) |
cholletisaik777 | 0:d6e3d1e21484 | 25 | printf("\r\n\rData received from BAE is %s \r\n",data); |
cholletisaik777 | 0:d6e3d1e21484 | 26 | else |
cholletisaik777 | 0:d6e3d1e21484 | 27 | { |
cholletisaik777 | 0:d6e3d1e21484 | 28 | printf("\r\n \r data not received \r\n"); |
cholletisaik777 | 0:d6e3d1e21484 | 29 | master.stop(); |
cholletisaik777 | 0:d6e3d1e21484 | 30 | } |
cholletisaik777 | 0:d6e3d1e21484 | 31 | irpt_2_slv = 1; |
cholletisaik777 | 0:d6e3d1e21484 | 32 | printf("\r\n\r %d \r\n",t.read_us()); |
cholletisaik777 | 0:d6e3d1e21484 | 33 | t.reset(); |
cholletisaik777 | 0:d6e3d1e21484 | 34 | } |
cholletisaik777 | 0:d6e3d1e21484 | 35 | |
cholletisaik777 | 0:d6e3d1e21484 | 36 | void FCTN_I2C_WRITE(char *data,int length) |
cholletisaik777 | 0:d6e3d1e21484 | 37 | { |
cholletisaik777 | 0:d6e3d1e21484 | 38 | bool write_ack = true; |
cholletisaik777 | 0:d6e3d1e21484 | 39 | irpt_2_slv = 0; |
cholletisaik777 | 0:d6e3d1e21484 | 40 | t.start(); |
cholletisaik777 | 0:d6e3d1e21484 | 41 | write_ack=master.write(addr|0x00,data,length); |
cholletisaik777 | 0:d6e3d1e21484 | 42 | t.stop(); |
cholletisaik777 | 0:d6e3d1e21484 | 43 | if(write_ack == 0) |
cholletisaik777 | 0:d6e3d1e21484 | 44 | printf("\r\n\rData sent to BAE is %s \r\n",data); |
cholletisaik777 | 0:d6e3d1e21484 | 45 | else |
cholletisaik777 | 0:d6e3d1e21484 | 46 | { |
cholletisaik777 | 0:d6e3d1e21484 | 47 | printf("\r\n\r data not sent \r\n"); |
cholletisaik777 | 0:d6e3d1e21484 | 48 | master.stop(); |
cholletisaik777 | 0:d6e3d1e21484 | 49 | } |
cholletisaik777 | 0:d6e3d1e21484 | 50 | irpt_2_slv = 1; |
cholletisaik777 | 0:d6e3d1e21484 | 51 | printf("\r\n\r %d \r\n",t.read_us()); |
cholletisaik777 | 0:d6e3d1e21484 | 52 | t.reset(); |
cholletisaik777 | 0:d6e3d1e21484 | 53 | } |
cholletisaik777 | 0:d6e3d1e21484 | 54 | |
cholletisaik777 | 0:d6e3d1e21484 | 55 | bool check = 1; |
cholletisaik777 | 0:d6e3d1e21484 | 56 | void FCTN_MASTER_I2C(char i2c_data_type , char* i2c_data) |
cholletisaik777 | 0:d6e3d1e21484 | 57 | { |
cholletisaik777 | 0:d6e3d1e21484 | 58 | FCTN_I2C_WRITE(&i2c_data_type,1); |
cholletisaik777 | 0:d6e3d1e21484 | 59 | wait_ms(10); |
cholletisaik777 | 0:d6e3d1e21484 | 60 | switch(i2c_data_type) |
cholletisaik777 | 0:d6e3d1e21484 | 61 | { |
cholletisaik777 | 0:d6e3d1e21484 | 62 | case 's': |
cholletisaik777 | 0:d6e3d1e21484 | 63 | FCTN_I2C_WRITE(i2c_data,11); |
cholletisaik777 | 0:d6e3d1e21484 | 64 | break; |
cholletisaik777 | 0:d6e3d1e21484 | 65 | |
cholletisaik777 | 0:d6e3d1e21484 | 66 | case 'l': |
cholletisaik777 | 0:d6e3d1e21484 | 67 | FCTN_I2C_WRITE(i2c_data,135); |
cholletisaik777 | 0:d6e3d1e21484 | 68 | break; |
cholletisaik777 | 0:d6e3d1e21484 | 69 | |
cholletisaik777 | 0:d6e3d1e21484 | 70 | case 'h': |
cholletisaik777 | 0:d6e3d1e21484 | 71 | FCTN_I2C_READ(i2c_data,25); |
cholletisaik777 | 0:d6e3d1e21484 | 72 | break; |
cholletisaik777 | 0:d6e3d1e21484 | 73 | |
cholletisaik777 | 0:d6e3d1e21484 | 74 | default: |
cholletisaik777 | 0:d6e3d1e21484 | 75 | printf("\r\n\r invalid command \r\n"); |
cholletisaik777 | 0:d6e3d1e21484 | 76 | } |
cholletisaik777 | 0:d6e3d1e21484 | 77 | } |