Introduction
It was always interested in a device talking with another device, especially when you start seeing responses back. Talking to vending machine using MDB protocol is one of that amazing adventures.
My goal is to prototype a simple payment system using RFID tags for paying for a vend. Payment policy can be extend and customised in many ways including using the same RFID tag across many machines and limiting the vends in day basis by storing information inside the tag.
The Setup
Test board, Changegiver, MDB Machine. Beside test board can be connected to the machine directly. Currently we are connected via MDB Loom cable.
Interfacing MDB
In order to talk with vending machine, there must be interfacing part which will receive and send data via mdb bus.
1. 1x 6N137
2. 1x4N35( or PC133)
3. 1x 0.1mf capacitor
4. 1x 10k resistor
5. 1x 1k resistor
6. 1x C114 digital npn transistor
7. 1x CD74HC14 (Schmitt Trigger)
Schematic
Notes:
1. 4N35, can be replaced with PC113
2. I am using Nucleo STM32F303K8
SMT32CubeMX Layout
Cashless Device
We show ourself into MDB bus like Cashless Device with address 10H. In order to communicated with MDB master there must be implemented couple of commands. Main drama here is communication is with 9bit UART.
MDB is using parity bit like a mod bit to show if the value is address or data. I tried various approaches but one which works in my case is using STM32 UART configured on 9bit word length, without parity.
- RESET 10H
- SETUP 11H
- PULL 12H
- VEND 13H
- EXPANSION 17H
More details about them you can find in https://www.ccv.eu/wp-content/uploads/2018/05/MDB-Interface-Specification.pdf
The Tools and Libs
I am using STM32CubeIDE. Using VCP for debuting message. Currently allowing any card to have amount inside and allowing a vend. Vend policy can be changed in best suitable way, even using phone with NFC capabilities.
It is possible to code preloaded amount into card and use that amount during the vend.
For the reader MC522 is used library Library 23- Read RFID tag with MF RC522 on STM32F4 with slight changes in order to fit into the project.
The Code
Source is experimental and lot of improvements are possible. I am experimenting also with Nucleo Board to be just like a bridge(because of 9th bit UART word size) to a Raspberry PI equipped with Typescript code and NodeJS.
Moment of Truth
We have one selection(Hot Chocolate) which is paid(one with button switched of). When the RFID tag is reader, we respond back with amount of 2.0(can be any currency) credits.
User selects vend, machine request approval from us. We say 'yes' and vend is made.
Finally I can enjoy cup of Hot Chocolate.