I2C code testing

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_pl123 by Siva ram

i2c.h

Committer:
ee12b079
Date:
2016-03-30
Revision:
139:17353d6311ce
Parent:
138:71ed56f2ec50

File content as of revision 139:17353d6311ce:

#define tm_len 134
#define tc_len 135
#define tc_test_len 135

InterruptIn irpt_4m_slv(D3);                                      //I2c interrupt from CDMS
DigitalOut irpt_2_slv(D4);                                        //I2C interrupt to CDMS
//I2C master(PTC9,PTC8);
const int addr = 0x20;                                            //slave address 
const int addr_pl = 0x20<<1;                                            //PL slave address

bool write_ack = true;
bool read_ack = true;



uint8_t PL_TM_SIZE;//size of data to bev read from i2c

void FCTN_I2C_WRITE_PL(char *data2,uint8_t tc_len2)
{
    write_ack = master.write(addr_pl|0x00,data2,tc_len2);//address to be defined in payload
    if(write_ack == 1)
    {
        printf("\n\rdata not sent\n");
        }
    else
    {
        
        }
}
void FCTN_I2C_READ_PL(char *data,int length)
{   
    //t_read.start();
    read_ack = master.read(addr_pl|1,data,length);
    //t_read.stop();
    uint8_t len = 0;
  
  printf("\n\r i2c data : \n\n\r\r");
  while(len != length) printf("%c",data[len]);
  printf(" \n\n\r\r"); 
    if(read_ack == 0)
      printf("\n\rData received from PL %s \n",data);
 if (read_ack == 1)
    {
//        gLEDR = 1;
        printf("\n \r data not received from PL\n");
//        gLEDR = 0;
    }
//if(read_ack == 1)
//pc.printf("\n \r data not received \n");
    //printf("\n\r %d \n",t.read_us());
    //t.reset();
}

void FCTN_I2C_READ(char *data,int length, int addr)
{   
    irpt_2_slv = 1;
    //t_read.start();
    read_ack = master.read(addr|1,data,length);
    //t_read.stop();
  
    //if(read_ack == 0)
      //  printf("\n\rData received from BAE %s \n",data);
 if (read_ack == 1)
    {
        printf("\n \r data not received \n");
    }
//if(read_ack == 1)
//pc.printf("\n \r data not received \n");

    irpt_2_slv = 0;
    //printf("\n\r %d \n",t.read_us());
    //t.reset();
}

void FCTN_I2C_WRITE(char *data)
{
    irpt_2_slv = 1;
    //t.start();
    write_ack = master.write(addr|0x00,data,tc_len);
    //t.stop();
    //if(write_ack == 0)
        //gPC.printf("\n\r data not sent \n");
       
if (write_ack == 0)
    {
//        led2 = 1;
        //gPC.printf("\n\r data not sent \n");
//        led2 = 0;    
    }
    irpt_2_slv = 0;
    //gPC.printf("\n\r %d \n",t.read_us());
    //t.reset();
}


const int addr1 = (0x20<<1|0);
const int addr2 = (0x20<<1|1);








void isr_pyldtm()
{
    gLEDR=!gLEDR;
    read_ack = master.read(addr1,PL_I2C_DATA,134);
    rcv_isr = 1;
}