-
Notifications
You must be signed in to change notification settings - Fork 8
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
weird data from MDB device #6
Comments
Without seeing any of your code or the hardware you're using, it will be hard for me to provide any help debugging. It's been about 2 years since I last worked on this project, so it's unlikely that I'll be able to easily find an old circuit diagram for this, but I might be able to see what's wrong with yours if you post pictures or something. Keep in mind that the example code in the samples directory was made for a Bill Accepter, not a coin changer. They may have different sets of commands available to them, or at least have different sets of responses (which might be why it seems jumbled). Other problems could be that the speed of the interface is wrong. I think I only ever tested on Arduino Uno. If you're on a different Arduino, I can't say for sure if it will work. It might, but I haven't tested it. |
Hi,
thanks for your Response.
Some other guy advised me to just connect the TX and RX of my arduino to the corresponding wires of the MDB port.
This way I can make sure there is no error in my wiring, or is this a bad Idea?
The file contains the Basic Code i am using
Greetings Tarcontar
Von: Justin T Conroy
Gesendet: Freitag, 3. Februar 2017 21:27
An: justintconroy/MdbBillValidator
Cc: Tarcontar; Author
Betreff: Re: [justintconroy/MdbBillValidator] weird data from MDB device (#6)
Without seeing any of your code or the hardware you're using, it will be hard for me to provide any help debugging. It's been about 2 years since I last worked on this project, so it's unlikely that I'll be able to easily find an old circuit diagram for this, but I might be able to see what's wrong with yours if you post pictures or something.
Keep in mind that the example code in the samples directory was made for a Bill Accepter, not a coin changer. They may have different sets of commands available to them, or at least have different sets of responses (which might be why it seems jumbled).
Other problems could be that the speed of the interface is wrong. I think I only ever tested on Arduino Uno. If you're on a different Arduino, I can't say for sure if it will work. It might, but I haven't tested it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
void mdb_uart_init()
{
UCSR1B = (1<<RXEN1)|(1<<TXEN1);
UBRR1H = 0;
UBRR1L = 103; // 9600baud
UCSR1C |= (1<<UCSZ11)|(1<<UCSZ10); //9bit mode
UCSR1B |= (1<<UCSZ12); //also for 9 bit mode
UCSR1C = UCSR1C | B00000100; //one stop bit
UCSR1C = UCSR1C | B00000000; //no parity bit
}
void send(unsigned char cmd, int mode)
{
while(!(UCSR1A & (1<<UDRE)));
UCSR1B &= ~(1<<TXB8);
if (mode)
UCSR1B |= (1<<TXB8);
UDR1 = cmd;
}
int receive(unsigned char *data, int *mode)
{
unsigned char status, resh, resl;
if(!(UCSR1A & (1<<RXC)))
{
Serial.println("NO DATA TO READ");
return 0;
}
status = UCSR1A;
resh = UCSR1B;
resl = UDR1;
if (status & ((1<<FE) | (1<<DOR) | (1<<UPE)))
{
Serial.println("STATUS ERROR");
return 0;
}
(*mode) = (resh >> 1) & 0x01;
(*data) = resl;
return 1;
}
|
Hi,
this is the Code i am using.
I connect the Arduino directly to the RX; TX; GND lines of the MDB, since I want to use it as master.
(so i dont Need optokopplers etc.), But do I need some Pull-up/Pull-down resistors?
Greetings Tarcontar
Von: Justin T Conroy
Gesendet: Freitag, 3. Februar 2017 21:27
An: justintconroy/MdbBillValidator
Cc: Tarcontar; Author
Betreff: Re: [justintconroy/MdbBillValidator] weird data from MDB device (#6)
Without seeing any of your code or the hardware you're using, it will be hard for me to provide any help debugging. It's been about 2 years since I last worked on this project, so it's unlikely that I'll be able to easily find an old circuit diagram for this, but I might be able to see what's wrong with yours if you post pictures or something.
Keep in mind that the example code in the samples directory was made for a Bill Accepter, not a coin changer. They may have different sets of commands available to them, or at least have different sets of responses (which might be why it seems jumbled).
Other problems could be that the speed of the interface is wrong. I think I only ever tested on Arduino Uno. If you're on a different Arduino, I can't say for sure if it will work. It might, but I haven't tested it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
#include <SoftwareSerial.h>
#define TXB8 0
#define UPE 2
#define DOR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define ADDRESS 1
#define DATA 0
#define DATA_MAX 36
//TIMINGS
#define TIME_OUT 5
#define CHANGER_NO_RESPONSE 2000
//ADDRESSES
#define COIN_CHANGER 0x08
#define BILL_VALIDATOR 0x30
//COMMANDS
#define ACK 0x00
#define RET 0xAA
#define NAK 0xFF
#define RESET 0x00
#define SETUP 0x01
#define STATUS 0x02
#define BILL_SECURITY 0x02
#define POLL 0x03
#define TYPE 0x04
#define COIN_DISPENSE 0x05
#define BILL_ESCROW 0x05
#define EXPANSION_CMD 0x07
int data_count = 0;
unsigned char in_buffer[40];
int out_buffer[40];
unsigned long _commandSentTime;
void setup()
{
Serial.begin(9600);
Serial.println("started VMC");
mdb_uart_init();
HardReset();
Reset(COIN_CHANGER);
delay(500);
//Enable(COIN_CHANGER);
}
void loop()
{
}
void Enable(unsigned char address)
{
Serial.println("ENABLE");
Status(address);
Type(address);
Serial.println("ENABLE_SUCCEEDED");
}
void Error(unsigned char address)
{
Poll(address);
}
void Reset(unsigned char address)
{
Serial.println("RESET");
SendCommand(address, RESET);
if ((GetResponse(&data_count) == ACK) && (data_count == 1))
{
Poll(address);
Setup(address);
//Expansion(address, 0x00); //ID
// Expansion(address, 0x01); //Feature
// Expansion(address, 0x05); //Status
Serial.println("RESET_SUCCEEDED");
return;
}
println("RESET_FAILED: ", data_count);
delay(1000);
Reset(address);
}
void Poll(unsigned char address)
{
SendCommand(address, POLL);
if (((GetResponse(&data_count) == ACK) && (data_count == 1)) || (data_count == 16))
{
SendACK();
println("POLL_SUCCEEDED: ", data_count);
return;
}
Serial.println("POLL_FAILED");
delay(1000);
Poll(address);
}
void Setup(unsigned char address)
{
SendCommand(address, STATUS);
if (GetResponse(&data_count) && data_count == 23)
{
SendACK();
Serial.println("SETUP_SUCCEEDED");
Serial.println(data_count);
return;
}
println("SETUP_FAILED: ", data_count);
delay(1000);
Setup(address);
}
void Status(unsigned char address)
{
SendCommand(address, STATUS);
if (GetResponse(&data_count) && data_count == 18)
{
SendACK();
Serial.println("STATUS_SUCCEEDED");
Serial.println(data_count);
}
println("STATUS_FAILED: ", data_count);
delay(1000);
Status(address);
}
void Type(unsigned char address)
{
out_buffer[0] = 0xff;
out_buffer[1] = 0xff;
out_buffer[2] = 0xff;
out_buffer[3] = 0xff;
SendCommand(address, TYPE, 4);
if (GetResponse(&data_count) != ACK)
{
Serial.println("TYPE_FAILED");
delay(1000);
Type(address);
}
Serial.println("TYPE_SUCCEEDED");
}
void Expansion(unsigned char address, unsigned char sub_cmd)
{
out_buffer[0] = sub_cmd;
SendCommand(address, EXPANSION_CMD, 1);
if (GetResponse(&data_count) && data_count == 33)
{
switch(sub_cmd)
{
case 0x00:
if (data_count == 33)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
case 0x01:
if (data_count == 4)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
case 0x02:
if (data_count == 0)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
case 0x03:
if (data_count == 16)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
case 0x04:
if (data_count == 1)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
case 0x05:
if (data_count == 2)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
case 0x06:
if (data_count == 16)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
case 0x07:
if (data_count == 16)
Serial.println("EXPANSION_SUCCEEDED");
return;
break;
default:
break;
}
}
println("EXPANSION_FAILED", data_count);
delay(1000);
Expansion(address, sub_cmd);
}
///BASE FUNCTIONS
void SendCommand(unsigned char address, unsigned char command)
{
SendCommand(address, command, 0);
}
void SendCommand(unsigned char address, unsigned char command, unsigned int dataByteCount)
{
unsigned char sum = 0;
send(address | command, ADDRESS);
sum += address | command;
for (unsigned int i = 0; i < dataByteCount; i++)
{
send(out_buffer[i], DATA);
sum += out_buffer[i];
}
//send checksum
send(sum, DATA);
}
void SendACK()
{
send(ACK, DATA);
}
void SendRET()
{
send(RET, DATA);
}
void SendNAK()
{
send(NAK, DATA);
}
void send(unsigned char cmd, int mode)
{
while(!(UCSR1A & (1<<UDRE)));
UCSR1B &= ~(1<<TXB8);
if (mode)
UCSR1B |= (1<<TXB8);
UDR1 = cmd;
_commandSentTime = millis();
}
int GetResponse(int *count)
{
int mode = 0;
(*count) = 0;
//wait for response
while(!available())
{
if ((millis() - _commandSentTime) > TIME_OUT)
{
Serial.println("TIMED_OUT");
return -1;
}
}
while(available() && !mode && *count < DATA_MAX)
{
if (receive(&in_buffer[*count], &mode))
{
if ((in_buffer[*count] == ACK) && (mode == 1))
return ACK;
(*count)++;
}
}
return 1;
}
int receive(unsigned char *data, int *mode)
{
unsigned char status, resh, resl;
if(!(UCSR1A & (1<<RXC)))
{
Serial.println("NO DATA TO READ");
return 0;
}
status = UCSR1A;
resh = UCSR1B;
resl = UDR1;
if (status & ((1<<FE) | (1<<DOR) | (1<<UPE)))
{
Serial.println("STATUS ERROR");
return 0;
}
(*mode) = (resh >> 1) & 0x01;
(*data) = resl;
Serial.println(*mode);
Serial.println(*data);
return 1;
}
int available()
{
return (UCSR1A & (1<<RXC));
}
void HardReset()
{
pinMode(18, OUTPUT);
digitalWrite(18, LOW);
delay(200);
digitalWrite(18, HIGH);
delay(200);
}
void mdb_uart_init()
{
UCSR1B = (1<<RXEN1)|(1<<TXEN1);
UBRR1H = 0;
UBRR1L = 103; // 9600baud
UCSR1C |= (1<<UCSZ11)|(1<<UCSZ10); //9bit mode
UCSR1B |= (1<<UCSZ12); //also for 9 bit mode
UCSR1C = UCSR1C | B00000100; //one stop bit
UCSR1C = UCSR1C | B00000000; //no parity bit
}
void println(String msg, int val)
{
Serial.print(msg);
Serial.print(val);
Serial.print("\n");
}
|
This doesn't look like you're using any of the libraries provided in this repository. Can you maybe explain what you're actually trying to do? Are you trying to write your own implementation? Did you try integrating these libraries into a project at all? I know it's not all that well documented, but I can probably help you better if you're actually using what I wrote. |
Hi,
i set up my code for the 9 bit serial communication and testet it with 2 arduinos.
But I still get weird data from the MDB device (coin changer).
Im not sure if my circuit is correct(2 optokopplers).
Do you have any example circuit for your code?
greetings Tarcontar
The text was updated successfully, but these errors were encountered: