Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware schematic! #7

Open
tusharvb19 opened this issue Jul 16, 2018 · 17 comments
Open

Hardware schematic! #7

tusharvb19 opened this issue Jul 16, 2018 · 17 comments

Comments

@tusharvb19
Copy link

Can give me the details and schematic of hardware for MDB.
Thank you.

@Bouni
Copy link
Owner

Bouni commented Jul 16, 2018

Its in German, but Google translate is your friend ;-)

https://reaktor23.org/projects/matedealer/#grundlegende-beschaltung

@tusharvb19
Copy link
Author

Thank you for the link. It comprises of only two opto-couplers and 3 resistors!
Is that enough to handle the MDB bus? This is the working circuit right?
And how about making your circuit as sniffer that will just read the mdb packets flowing between CD and VMC. I need to observe the packets at low level like you have analyzed using analyzer. Thank you for that deep diving into MDB.
I want to build a sniffer. Can you guide me?

@tusharvb19
Copy link
Author

tusharvb19 commented Jul 16, 2018

Can I build your circuit with Atmega328 to read mdb packets So their will be a parallel connection to the MDB bus.
....... VMC<----->MDB<----->CD
....................................↕
.....................(Your ckt+ Atmega328)

And the sniffer will only perform read operation!
Here is the link of work done using atmega328 which I will use to perform read operation.
https://github.com/LanguidSmartass/mdb-arduino-cashless
Thank you.

@Bouni
Copy link
Owner

Bouni commented Jul 16, 2018

Actually you don't need the resistors and optocouplers at all!
They are just to prevent either circuit damaging the other in case of a fault.

I want to build a sniffer. Can you guide me?

Unfortunately no, I don't have the time to do that

Can I build your circuit with Atmega328 to read mdb packets So their will be a parallel connection to
the MDB bus.

You could use an Arduino with 3 UARTS

  • UART0 -> Uplink to a computer for outputing data
  • UART1 RX -> Connected to the RX line of the VMC -> All data bytes are sent to the computer. Put a an indicator, RX: for example in front of each byte
  • UART2 RX ->Connected to the TX line of the VMC -> All data bytes are sent to the computer. Put a an indicator, TX: for example in front of each byte

With that you should get a stream of data to your computer that looks roughly like this:

TX 0x000
TX 0x100
RX 0x000

And so on...

A simple sniffer, easy to build and to program.

@tusharvb19
Copy link
Author

So you mean not a parallel one, where I can connect the circuit directly as the data is nothing but voltage levels! .And then using above link MDB to UART, I can view the conversation as:
VMC<---->MDB<---->CD
...............................↳<----->UART

Is your above approach is as: VMC MDB<---->UART1(Serial Monitor UART0)UART2<---->MDB CD ?

@tusharvb19
Copy link
Author

Actually you don't need the resistors and optocouplers at all!
They are just to prevent either circuit damaging the other in case of a fault.

--
So they are 3.3V and 5V tolerant?

@Bouni
Copy link
Owner

Bouni commented Jul 17, 2018

No, more like this:

+-----+              VMC-TX          +-----+
|     +-----+------------------------>     |
| VMC |     |                        | CD  |
|     <----------+-------------------+     |
+-----+     |    |   VMC-RX          +-----+
            |    |
            |    |
            |    |
       +----+----+------------------+             +---------+
       |   RX1  RX2                 |             |         |
       |                        TX0 +------------->         |
       |                            |             |   PC    |
       |        Arduino         RX0 <-------------+         |
       |                            |             |         |
       |                            |             |         |
       +----------------------------+             +---------+

All Received bytes from both, UART1 and UART2 are sent to the PC over UART0, just marked with an indicator so that you know which byte was which direction.

MDB is 5V by specification, so its no problem to connect a UART directly. I'm not sure about a 3.3V UART.

@tusharvb19
Copy link
Author

Thank you. So both RX1 and RX2 must be set up to read 9 bit mdb data!
So while reading data the approach will be :

while(uart1.available()>0)
{
uart1bits=uart1.read();
Serial.print("TX:");
Serial.print(uart1bits);
}
while(uart2.available()>0)
{
uart2bits=uart2.read();
Serial.print("RX:");
Serial.print(uart2bits);
}

right?

@Bouni
Copy link
Owner

Bouni commented Jul 17, 2018

Yes, you maybe need some fine tuning to the code, but you got the point!

@tusharvb19
Copy link
Author

Okay. Thank you. I have tested the basic code!
But the acknowledgement packet is being read is 0 for CD and not 100h, while 0h is correct for VMC, right? And I think the data CD is transmitting is not correctly read when compared with your data!

@tusharvb19
Copy link
Author

Also while reading mdb packets can I output them on Serial monitor for debugging?
As the normal mega to usb/pc interface would be 8 bit serial , so can it show 9 bit data also!

@Bouni
Copy link
Owner

Bouni commented Jul 25, 2018

Have you concidered that MDB ist 9bits!?
So when you receive 0x100, the lower 8 bits are stored in the UDR register while the 9th bit is in the UCSR1B register!
So simply uing Arduinos serial read will not bring you a nice 0x100 but a 0x00!

When you managed to read 9 bits from MDB, I recommend writing a funtion that sends the value as ASCII to the PC.
For example: 0x100 (uint16_t) wil be sent as 0 x 0 1 0 0 (ASCII 0x30 0x78 0x31 0x30 0x30), even better prepend that with RX or TX depending on which UAT you received the data.

@tusharvb19
Copy link
Author

This is my response for reset from serial monitor:

RX: 110 10
TX: 0
.
.
.

RX: 112 12
TX: 1FF
RX: 0 111 0 2 0 0 0 13
TX: FF FE 6F 1AE 1FD 19F 1FF 107
RX: 0 111 1 0 C8 0 C8 A2
TX: 0
RX: 112 12
TX: 0
RX: 114 1 15
TX: 0
RX: 112 12
TX: 0

As you can see I am receiving RX i.e. VMC packets correctly the ACK is 0 which is correct for VMC, right?
And then comes the problem, the data from TX i.e. CD is not correct!

@tusharvb19
Copy link
Author

tusharvb19 commented Aug 1, 2018

I think snippet should do the work...

int main(void) {

setup_usart(0,38400,8,'N',1);
setup_usart(1,9600,9,'N',1);
setup_usart(2,9600,9,'N',1);

sei();

send_str_p(0,PSTR("MDB sniffer is up and running\r\n"));
   
// Main Loop
while(1) 
{
	if(buffer_level(MDB_USART,RX) > 0)
	{
	  uint16_t data = recv_mdb(MDB_USART);
	  send_str(0,data);
	}
	
	if(buffer_level(MDB_USART2,RX) > 0)
	{
	  uint16_t data2 = recv_mdb(MDB_USART2);
	  send_str(0,data2);
	}
	
    //mdb_cmd_handler();
    //uplink_cmd_handler();
}

return 0;

}

@tusharvb19
Copy link
Author

Nope didn't received values as I am printing 9bit value to 8bit serial communication!
Need to try other way!

@tusharvb19
Copy link
Author

Made it!

if(buffer_level(MDB_USART,RX) > 0)
{
uint16_t data = recv_mdb(MDB_USART);
sprintf(str, "%x", data);
send_str_p(0,PSTR("RX: "));
send_str(0,str);
send_str(0,"\r\n");
}

if(buffer_level(MDB_USART2,RX) > 0)
{
  uint16_t data2 = recv_mdb(MDB_USART2);
      sprintf(str, "%x", data2);
      send_str_p(0,PSTR("TX:  "));
      send_str(0,str);
      send_str(0,"\r\n");
}

@tusharvb19
Copy link
Author

But the output is same as that of arduino code!
I think the TX i.e. CD Transmit output will need a high impedance translator to work and get the correct packets!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants