publishing to check changes in cdms code
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA_flag by
i2c.h@138:6fcbbaf19284, 2016-03-12 (annotated)
- Committer:
- Piasiv1206
- Date:
- Sat Mar 12 10:42:22 2016 +0000
- Revision:
- 138:6fcbbaf19284
- Parent:
- 132:d4a4461214ad
workin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aniruddhv | 52:0bd68655c651 | 1 | #define tm_len 134 |
aniruddhv | 52:0bd68655c651 | 2 | #define tc_len 135 |
aniruddhv | 52:0bd68655c651 | 3 | #define tc_test_len 135 |
aniruddhv | 52:0bd68655c651 | 4 | |
shreeshas95 | 105:5ce0337e7c15 | 5 | InterruptIn irpt_4m_slv(D3); //I2c interrupt from CDMS |
shreeshas95 | 105:5ce0337e7c15 | 6 | DigitalOut irpt_2_slv(D4); //I2C interrupt to CDMS |
ee12b079 | 130:d5b53088270b | 7 | //I2C master(PTC9,PTC8); |
aniruddhv | 52:0bd68655c651 | 8 | const int addr = 0x20; //slave address |
ee12b079 | 130:d5b53088270b | 9 | const int addr_pl = 0x20<<1; //PL slave address |
ee12b079 | 132:d4a4461214ad | 10 | |
aniruddhv | 52:0bd68655c651 | 11 | bool write_ack = true; |
aniruddhv | 52:0bd68655c651 | 12 | bool read_ack = true; |
aniruddhv | 52:0bd68655c651 | 13 | |
ee12b079 | 132:d4a4461214ad | 14 | |
ee12b079 | 132:d4a4461214ad | 15 | char PL_I2C_DATA[134];//Payload i2c array |
ee12b079 | 132:d4a4461214ad | 16 | uint8_t PL_TM_SIZE;//size of data to bev read from i2c |
aniruddhv | 52:0bd68655c651 | 17 | |
ee12b079 | 130:d5b53088270b | 18 | void FCTN_I2C_WRITE_PL(char *data2,uint8_t tc_len2) |
aniruddhv | 52:0bd68655c651 | 19 | { |
ee12b079 | 130:d5b53088270b | 20 | write_ack = master.write(addr_pl|0x00,data2,tc_len2);//address to be defined in payload |
ee12b079 | 132:d4a4461214ad | 21 | if(write_ack == 1) |
ee12b079 | 130:d5b53088270b | 22 | { |
ee12b079 | 132:d4a4461214ad | 23 | printf("\n\rdata not sent\n"); |
ee12b079 | 130:d5b53088270b | 24 | } |
ee12b079 | 130:d5b53088270b | 25 | else |
aniruddhv | 52:0bd68655c651 | 26 | { |
ee12b079 | 132:d4a4461214ad | 27 | |
ee12b079 | 130:d5b53088270b | 28 | } |
ee12b079 | 130:d5b53088270b | 29 | } |
ee12b079 | 130:d5b53088270b | 30 | void FCTN_I2C_READ_PL(char *data,int length) |
ee12b079 | 130:d5b53088270b | 31 | { |
ee12b079 | 130:d5b53088270b | 32 | //t_read.start(); |
ee12b079 | 130:d5b53088270b | 33 | read_ack = master.read(addr_pl|1,data,length); |
ee12b079 | 130:d5b53088270b | 34 | //t_read.stop(); |
ee12b079 | 132:d4a4461214ad | 35 | uint8_t len = 0; |
ee12b079 | 130:d5b53088270b | 36 | |
ee12b079 | 132:d4a4461214ad | 37 | printf("\n\r i2c data : \n\n\r\r"); |
ee12b079 | 132:d4a4461214ad | 38 | while(len != length) printf("%c",data[len]); |
ee12b079 | 132:d4a4461214ad | 39 | printf(" \n\n\r\r"); |
ee12b079 | 132:d4a4461214ad | 40 | if(read_ack == 0) |
ee12b079 | 132:d4a4461214ad | 41 | printf("\n\rData received from PL %s \n",data); |
ee12b079 | 132:d4a4461214ad | 42 | if (read_ack == 1) |
ee12b079 | 132:d4a4461214ad | 43 | { |
ee12b079 | 130:d5b53088270b | 44 | // gLEDR = 1; |
ee12b079 | 132:d4a4461214ad | 45 | printf("\n \r data not received from PL\n"); |
ee12b079 | 130:d5b53088270b | 46 | // gLEDR = 0; |
ee12b079 | 132:d4a4461214ad | 47 | } |
ee12b079 | 130:d5b53088270b | 48 | //if(read_ack == 1) |
ee12b079 | 130:d5b53088270b | 49 | //pc.printf("\n \r data not received \n"); |
ee12b079 | 130:d5b53088270b | 50 | //printf("\n\r %d \n",t.read_us()); |
aniruddhv | 52:0bd68655c651 | 51 | //t.reset(); |
aniruddhv | 52:0bd68655c651 | 52 | } |
aniruddhv | 52:0bd68655c651 | 53 | |
ee12b079 | 130:d5b53088270b | 54 | void FCTN_I2C_READ(char *data,int length, int addr) |
ee12b079 | 130:d5b53088270b | 55 | { |
shreeshas95 | 103:b55559925dc1 | 56 | irpt_2_slv = 1; |
shreeshas95 | 103:b55559925dc1 | 57 | //t_read.start(); |
shreeshas95 | 103:b55559925dc1 | 58 | read_ack = master.read(addr|1,data,length); |
shreeshas95 | 103:b55559925dc1 | 59 | //t_read.stop(); |
shreeshas95 | 103:b55559925dc1 | 60 | |
aniruddhv | 52:0bd68655c651 | 61 | //if(read_ack == 0) |
shreeshas95 | 103:b55559925dc1 | 62 | // printf("\n\rData received from BAE %s \n",data); |
aniruddhv | 52:0bd68655c651 | 63 | if (read_ack == 1) |
aniruddhv | 52:0bd68655c651 | 64 | { |
shreeshas95 | 103:b55559925dc1 | 65 | printf("\n \r data not received \n"); |
aniruddhv | 52:0bd68655c651 | 66 | } |
aniruddhv | 52:0bd68655c651 | 67 | //if(read_ack == 1) |
shreeshas95 | 103:b55559925dc1 | 68 | //pc.printf("\n \r data not received \n"); |
aniruddhv | 52:0bd68655c651 | 69 | |
aniruddhv | 52:0bd68655c651 | 70 | irpt_2_slv = 0; |
shreeshas95 | 103:b55559925dc1 | 71 | //printf("\n\r %d \n",t.read_us()); |
aniruddhv | 52:0bd68655c651 | 72 | //t.reset(); |
ee12b079 | 130:d5b53088270b | 73 | } |
ee12b079 | 130:d5b53088270b | 74 | |
ee12b079 | 130:d5b53088270b | 75 | void FCTN_I2C_WRITE(char *data) |
ee12b079 | 130:d5b53088270b | 76 | { |
ee12b079 | 130:d5b53088270b | 77 | irpt_2_slv = 1; |
ee12b079 | 130:d5b53088270b | 78 | //t.start(); |
ee12b079 | 130:d5b53088270b | 79 | write_ack = master.write(addr|0x00,data,tc_len); |
ee12b079 | 130:d5b53088270b | 80 | //t.stop(); |
ee12b079 | 130:d5b53088270b | 81 | //if(write_ack == 0) |
ee12b079 | 130:d5b53088270b | 82 | //gPC.printf("\n\r data not sent \n"); |
ee12b079 | 130:d5b53088270b | 83 | |
ee12b079 | 130:d5b53088270b | 84 | if (write_ack == 0) |
ee12b079 | 130:d5b53088270b | 85 | { |
ee12b079 | 130:d5b53088270b | 86 | // led2 = 1; |
ee12b079 | 130:d5b53088270b | 87 | //gPC.printf("\n\r data not sent \n"); |
ee12b079 | 130:d5b53088270b | 88 | // led2 = 0; |
ee12b079 | 130:d5b53088270b | 89 | } |
ee12b079 | 130:d5b53088270b | 90 | irpt_2_slv = 0; |
ee12b079 | 130:d5b53088270b | 91 | //gPC.printf("\n\r %d \n",t.read_us()); |
ee12b079 | 130:d5b53088270b | 92 | //t.reset(); |
ee12b079 | 132:d4a4461214ad | 93 | } |
ee12b079 | 132:d4a4461214ad | 94 | |
ee12b079 | 132:d4a4461214ad | 95 | |
ee12b079 | 132:d4a4461214ad | 96 | |
ee12b079 | 132:d4a4461214ad | 97 | |
ee12b079 | 132:d4a4461214ad | 98 | |
ee12b079 | 132:d4a4461214ad | 99 | |
ee12b079 | 132:d4a4461214ad | 100 | |
ee12b079 | 132:d4a4461214ad | 101 | |
ee12b079 | 132:d4a4461214ad | 102 | |
ee12b079 | 132:d4a4461214ad | 103 | |
ee12b079 | 132:d4a4461214ad | 104 | void isr_pyldtm() |
ee12b079 | 132:d4a4461214ad | 105 | { |
Piasiv1206 | 138:6fcbbaf19284 | 106 | |
Piasiv1206 | 138:6fcbbaf19284 | 107 | master.read(addr_pl|1,PL_I2C_DATA,13); |
ee12b079 | 132:d4a4461214ad | 108 | gLEDR=!gLEDR; |
Piasiv1206 | 138:6fcbbaf19284 | 109 | |
ee12b079 | 132:d4a4461214ad | 110 | rcv_isr = 1; |
aniruddhv | 52:0bd68655c651 | 111 | } |