![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
cdms stnd alone isr i2c
Fork of TV_MASTER_I2C_RTOS by
Diff: main.cpp
- Revision:
- 1:963697dc5199
- Parent:
- 0:abe5247de1be
- Child:
- 2:e9b8e19ca9c4
--- a/main.cpp Sun Nov 01 12:48:34 2015 +0000 +++ b/main.cpp Sun Nov 01 13:13:05 2015 +0000 @@ -12,20 +12,19 @@ DigitalOut led1(PIN46); DigitalOut led2(PIN95); const int addr = 0x20; //slave address -char hk_data[150]; -char telecommand[150]; -char telemetry[150]; -int length = 150; -//Timer test; -//Timer t; +char hk_data[hk_len]; +char telecommand[tc_len]; +char telemetry[tm_len]; +Timer test; +Timer t_read; bool write_ack = true; bool read_ack = true; char cmd = 'r'; Thread *ptr_t_i2c; -void FCTN_I2C_READ(char*); -void FCTN_I2C_WRITE(char*); +void FCTN_I2C_READ(char*,int); +void FCTN_I2C_WRITE(char*,int); void FCTN_ISR_I2C(); int count = 0; void FCTN_MASTER_CMD() @@ -34,14 +33,14 @@ { case 'r': pc.printf("\n \r %d CDMS READ MODE\n",count); - FCTN_I2C_READ(hk_data); + FCTN_I2C_READ(hk_data,hk_len); cmd = 'w'; count ++; break; case 'w': pc.printf("\n \r %d CDMS WRITE MODE\n",count); - FCTN_I2C_WRITE(telecommand); + FCTN_I2C_WRITE(telecommand,tc_len); //strcat(telecommand,"1"); cmd = 'r'; count++; @@ -49,7 +48,7 @@ } } -void FCTN_I2C_WRITE(char *data) +void FCTN_I2C_WRITE(char *data,int length) { irpt_2_slv = 1; //t.start(); @@ -68,12 +67,13 @@ } -void FCTN_I2C_READ(char *data) +void FCTN_I2C_READ(char *data,int length) { irpt_2_slv = 1; - //t.start(); + t_read.start(); read_ack = master.read(addr|1,data,length); - //t.stop(); + t_read.stop(); + //if(read_ack == 0) // pc.printf("\n\rData received from BAE %s \n",data); if (read_ack == 1) @@ -90,12 +90,12 @@ void FCTN_ISR_I2C() { - led2 = 1; + led1 = 1; //pc.printf("in isr"); ptr_t_i2c->signal_set(0x1); //test.start(); //wait(0.5); - led2 = 0; + led1 = 0; } void T_TM(void const * args) @@ -103,12 +103,12 @@ while(1) { Thread::signal_wait(0x1); - wait(2); + // wait(2); //test.stop(); - led1 = 1; + led2 = 1; // wait(3); - FCTN_I2C_READ(telemetry); - led1 = 0; + FCTN_I2C_READ(telemetry,tm_len); + led2 = 0; //pc.printf("\n \r %d",test.read_us()); //test.reset(); //irpt_2_slv = 1; @@ -143,8 +143,9 @@ { Thread::wait(10000); //ptr_t_i2c->signal_set(0x1); - pc.printf("\n\rTELEMETRY received from BAE is %s \n",telemetry); - pc.printf("\n\rHK Data received from BAE is %s \n",hk_data); + pc.printf("\n\rTELEMETRY received from BAE is %d %s \n",t_read.read_us(),telemetry); + pc.printf("\n\rHK Data received from BAE is %d %s \n",t_read.read_us(),hk_data); + t_read.reset(); FCTN_MASTER_CMD(); } } \ No newline at end of file