![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
things are working
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of CDMS_DEC_2016_jan by
i2c.cpp@3:23cdab96a05d, 2016-01-23 (annotated)
- Committer:
- cholletisaik777
- Date:
- Sat Jan 23 09:26:14 2016 +0000
- Revision:
- 3:23cdab96a05d
- Parent:
- 1:ad3b8a8032e2
cdms_testing_2016
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cholletisaik777 | 0:bcbd76c86cde | 1 | #include "mbed.h" |
cholletisaik777 | 0:bcbd76c86cde | 2 | #include "pinconfig.h" |
cholletisaik777 | 0:bcbd76c86cde | 3 | #include "rtos.h" |
cholletisaik777 | 0:bcbd76c86cde | 4 | #include "i2c.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 5 | |
cholletisaik777 | 0:bcbd76c86cde | 6 | DigitalOut irpt_2_slv(PIN67); //I2C interrupt to CDMS |
cholletisaik777 | 0:bcbd76c86cde | 7 | I2C master(PIN32,PIN31); |
cholletisaik777 | 0:bcbd76c86cde | 8 | DigitalOut led1(PIN46); |
cholletisaik777 | 0:bcbd76c86cde | 9 | DigitalOut led2(PIN95); |
cholletisaik777 | 0:bcbd76c86cde | 10 | const int addr = 0x20; //slave address |
cholletisaik777 | 0:bcbd76c86cde | 11 | char telecommand[tc_len]; |
cholletisaik777 | 0:bcbd76c86cde | 12 | char telemetry[tm_len]; |
cholletisaik777 | 0:bcbd76c86cde | 13 | Timer test; |
cholletisaik777 | 0:bcbd76c86cde | 14 | Timer t_read; |
cholletisaik777 | 0:bcbd76c86cde | 15 | bool write_ack = true; |
cholletisaik777 | 0:bcbd76c86cde | 16 | bool read_ack = true; |
cholletisaik777 | 0:bcbd76c86cde | 17 | |
cholletisaik777 | 0:bcbd76c86cde | 18 | int count = 0; |
cholletisaik777 | 0:bcbd76c86cde | 19 | |
cholletisaik777 | 0:bcbd76c86cde | 20 | void FCTN_I2C_WRITE(char *data) |
cholletisaik777 | 0:bcbd76c86cde | 21 | { |
cholletisaik777 | 0:bcbd76c86cde | 22 | irpt_2_slv = 1; |
cholletisaik777 | 0:bcbd76c86cde | 23 | //t.start(); |
cholletisaik777 | 0:bcbd76c86cde | 24 | write_ack = master.write(addr|0x00,data,tc_len); |
cholletisaik777 | 0:bcbd76c86cde | 25 | //t.stop(); |
cholletisaik777 | 0:bcbd76c86cde | 26 | //if(write_ack == 0) |
cholletisaik777 | 0:bcbd76c86cde | 27 | //pc.printf("\n\r data not sent \n"); |
cholletisaik777 | 0:bcbd76c86cde | 28 | |
cholletisaik777 | 0:bcbd76c86cde | 29 | if (write_ack == 1) |
cholletisaik777 | 0:bcbd76c86cde | 30 | { |
cholletisaik777 | 0:bcbd76c86cde | 31 | led2 = 1; |
cholletisaik777 | 0:bcbd76c86cde | 32 | printf("\n\r data not sent \n"); |
cholletisaik777 | 0:bcbd76c86cde | 33 | led2 = 0; |
cholletisaik777 | 0:bcbd76c86cde | 34 | } |
cholletisaik777 | 0:bcbd76c86cde | 35 | irpt_2_slv = 0; |
cholletisaik777 | 0:bcbd76c86cde | 36 | //pc.printf("\n\r %d \n",t.read_us()); |
cholletisaik777 | 0:bcbd76c86cde | 37 | //t.reset(); |
cholletisaik777 | 0:bcbd76c86cde | 38 | } |
cholletisaik777 | 0:bcbd76c86cde | 39 | |
cholletisaik777 | 0:bcbd76c86cde | 40 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 41 | void FCTN_I2C_READ(char *data,int length) |
cholletisaik777 | 0:bcbd76c86cde | 42 | { |
cholletisaik777 | 0:bcbd76c86cde | 43 | irpt_2_slv = 1; |
cholletisaik777 | 0:bcbd76c86cde | 44 | t_read.start(); |
pradeepvk2208 | 1:ad3b8a8032e2 | 45 | read_ack = master.read(addr|1,data,length); |
cholletisaik777 | 0:bcbd76c86cde | 46 | t_read.stop(); |
cholletisaik777 | 0:bcbd76c86cde | 47 | |
cholletisaik777 | 0:bcbd76c86cde | 48 | //if(read_ack == 0) |
cholletisaik777 | 0:bcbd76c86cde | 49 | // printf("\n\rData received from BAE %s \n",data); |
cholletisaik777 | 3:23cdab96a05d | 50 | if (read_ack == 1) |
cholletisaik777 | 0:bcbd76c86cde | 51 | { |
cholletisaik777 | 0:bcbd76c86cde | 52 | led2 = 1; |
cholletisaik777 | 0:bcbd76c86cde | 53 | printf("\n \r data not received \n"); |
cholletisaik777 | 0:bcbd76c86cde | 54 | led2 = 0; |
cholletisaik777 | 0:bcbd76c86cde | 55 | } |
cholletisaik777 | 0:bcbd76c86cde | 56 | //if(read_ack == 1) |
cholletisaik777 | 0:bcbd76c86cde | 57 | //pc.printf("\n \r data not received \n"); |
cholletisaik777 | 0:bcbd76c86cde | 58 | |
cholletisaik777 | 0:bcbd76c86cde | 59 | irpt_2_slv = 0; |
cholletisaik777 | 0:bcbd76c86cde | 60 | //printf("\n\r %d \n",t.read_us()); |
cholletisaik777 | 0:bcbd76c86cde | 61 | //t.reset(); |
cholletisaik777 | 0:bcbd76c86cde | 62 | } |