TDP databus is a custom developed protocol (tripping data protocol), that uses 4 data lines for a stabile communication. These lines are:
- S_DO (Data out)
- S_DI (Data in)
- S_OKO (Data ok out)
- S_OKI (Data ok in)
Note that, a master and slave are connected in the following way: (cross-over)
MASTER = SLAVE
S_DO = S_DI
S_DI = S_DO
S_OKO = S_OKI
S_OKI = S_OKO
The following image represents how a Master and a Slave are connected to a Data Bus. The purple line connecting Master and Slave is a selection line, that selects which Slave reads/writes data (in case of more than one slave).
Every communication is initiated by the Master.
The protocol is not time sensitive, since it uses S_OKO and S_OKI pin to drive data transfer. A new bit will not be sent until S_OKI data says that the previous bit was successfully received.
HERE's the code, if it can help you in any way, you are free to use it:
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************
#include <16F627A.h>
#device ADC=16
#FUSES NOWDT
#FUSES NOMCLR
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES NOCPD, NOPROTECT, NOPUT, INTRC_IO
#use delay(internal=4MHz)
#use STANDARD_IO( A,B )
#define S_OKO PIN_A0
#define S_OKI PIN_A7
#define S_DI PIN_A6
#define S_DO PIN_B7
int16 precalc_val[15] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384 };
void ___outbit(int1 val)
{
output_high(S_OKO);
if(val == 1)
output_high(S_DO);
while(!input(S_OKI));
output_low(S_OKO);
while(!input(S_OKI));
while(input(S_OKI));
output_low(S_DO);
}
int1 ___inbit()
{
int1 r = 0;
if(!input(S_OKI))
while(!input(S_OKI));
delay_us(100);
output_high(S_OKO);
while(input(S_OKI));
if(input(S_DI))
r = 1;
delay_us(100);
output_low(S_OKO);
delay_us(100);
return r;
}
void TDP_init()
{
output_low(S_OKO);
output_low(S_DO);
input(S_DI);
input(S_OKI);
}
void TDP_Write(int16 data)
{
int16 k, c;
for (c = 14; c >= 0; c--)
{
k = data >> c;
if (k & 1)
___outbit(0x01);
else
___outbit(0x00);
if (c == 0)
break;
}
}
int16 TDP_Read()
{
int16 data = 0;
int1 val = 0;
for(int i = 14; i>= 0; i--)
{
val = ___inbit();
if(val == 1)
data += precalc_val[i];
if (i == 0)
break;
}
return data;
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.