![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
hi
Dependencies: FreescaleIAP mbed-rtos mbed
i2c.cpp@0:bcbd76c86cde, 2015-12-16 (annotated)
- Committer:
- cholletisaik777
- Date:
- Wed Dec 16 09:06:59 2015 +0000
- Revision:
- 0:bcbd76c86cde
nnb
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" |
cholletisaik777 | 0:bcbd76c86cde | 5 | DigitalOut irpt_2_slv(PIN67); //I2C interrupt to CDMS |
cholletisaik777 | 0:bcbd76c86cde | 6 | I2C master(PIN32,PIN31); |
cholletisaik777 | 0:bcbd76c86cde | 7 | DigitalOut led1(PIN46); |
cholletisaik777 | 0:bcbd76c86cde | 8 | DigitalOut led2(PIN95); |
cholletisaik777 | 0:bcbd76c86cde | 9 | const int addr = 0x20; //slave address |
cholletisaik777 | 0:bcbd76c86cde | 10 | char telecommand[tc_len]; |
cholletisaik777 | 0:bcbd76c86cde | 11 | char telemetry[tm_len]; |
cholletisaik777 | 0:bcbd76c86cde | 12 | Timer test; |
cholletisaik777 | 0:bcbd76c86cde | 13 | Timer t_read; |
cholletisaik777 | 0:bcbd76c86cde | 14 | bool write_ack = true; |
cholletisaik777 | 0:bcbd76c86cde | 15 | bool read_ack = true; |
cholletisaik777 | 0:bcbd76c86cde | 16 | |
cholletisaik777 | 0:bcbd76c86cde | 17 | int count = 0; |
cholletisaik777 | 0:bcbd76c86cde | 18 | |
cholletisaik777 | 0:bcbd76c86cde | 19 | void FCTN_I2C_WRITE(char *data) |
cholletisaik777 | 0:bcbd76c86cde | 20 | { |
cholletisaik777 | 0:bcbd76c86cde | 21 | irpt_2_slv = 1; |
cholletisaik777 | 0:bcbd76c86cde | 22 | //t.start(); |
cholletisaik777 | 0:bcbd76c86cde | 23 | write_ack = master.write(addr|0x00,data,tc_len); |
cholletisaik777 | 0:bcbd76c86cde | 24 | //t.stop(); |
cholletisaik777 | 0:bcbd76c86cde | 25 | //if(write_ack == 0) |
cholletisaik777 | 0:bcbd76c86cde | 26 | //pc.printf("\n\r data not sent \n"); |
cholletisaik777 | 0:bcbd76c86cde | 27 | |
cholletisaik777 | 0:bcbd76c86cde | 28 | if (write_ack == 1) |
cholletisaik777 | 0:bcbd76c86cde | 29 | { |
cholletisaik777 | 0:bcbd76c86cde | 30 | led2 = 1; |
cholletisaik777 | 0:bcbd76c86cde | 31 | printf("\n\r data not sent \n"); |
cholletisaik777 | 0:bcbd76c86cde | 32 | led2 = 0; |
cholletisaik777 | 0:bcbd76c86cde | 33 | } |
cholletisaik777 | 0:bcbd76c86cde | 34 | irpt_2_slv = 0; |
cholletisaik777 | 0:bcbd76c86cde | 35 | //pc.printf("\n\r %d \n",t.read_us()); |
cholletisaik777 | 0:bcbd76c86cde | 36 | //t.reset(); |
cholletisaik777 | 0:bcbd76c86cde | 37 | } |
cholletisaik777 | 0:bcbd76c86cde | 38 | |
cholletisaik777 | 0:bcbd76c86cde | 39 | |
cholletisaik777 | 0:bcbd76c86cde | 40 | void FCTN_I2C_READ(char *data) |
cholletisaik777 | 0:bcbd76c86cde | 41 | { |
cholletisaik777 | 0:bcbd76c86cde | 42 | irpt_2_slv = 1; |
cholletisaik777 | 0:bcbd76c86cde | 43 | t_read.start(); |
cholletisaik777 | 0:bcbd76c86cde | 44 | read_ack = master.read(addr|1,data,tm_len); |
cholletisaik777 | 0:bcbd76c86cde | 45 | t_read.stop(); |
cholletisaik777 | 0:bcbd76c86cde | 46 | |
cholletisaik777 | 0:bcbd76c86cde | 47 | //if(read_ack == 0) |
cholletisaik777 | 0:bcbd76c86cde | 48 | // printf("\n\rData received from BAE %s \n",data); |
cholletisaik777 | 0:bcbd76c86cde | 49 | if (read_ack == 1) |
cholletisaik777 | 0:bcbd76c86cde | 50 | { |
cholletisaik777 | 0:bcbd76c86cde | 51 | led2 = 1; |
cholletisaik777 | 0:bcbd76c86cde | 52 | printf("\n \r data not received \n"); |
cholletisaik777 | 0:bcbd76c86cde | 53 | led2 = 0; |
cholletisaik777 | 0:bcbd76c86cde | 54 | } |
cholletisaik777 | 0:bcbd76c86cde | 55 | //if(read_ack == 1) |
cholletisaik777 | 0:bcbd76c86cde | 56 | //pc.printf("\n \r data not received \n"); |
cholletisaik777 | 0:bcbd76c86cde | 57 | |
cholletisaik777 | 0:bcbd76c86cde | 58 | irpt_2_slv = 0; |
cholletisaik777 | 0:bcbd76c86cde | 59 | //printf("\n\r %d \n",t.read_us()); |
cholletisaik777 | 0:bcbd76c86cde | 60 | //t.reset(); |
cholletisaik777 | 0:bcbd76c86cde | 61 | } |