I’m new on MDB communication and I’m working on a cashless payment device that communicate with the MDB protocol. I’m using, for know, an Arduino MEGA to communicate with this type of devices.
The problem that’s when I send a COMMAND like (RESET or Vend_Request) the device interact correctly (I mean with lights outputs) and with the application it’s all good and the request always has been approved on the application.
The problem that I can’t receive any thing on the serial like the POLL response form the device (like the ACK or something else) and I couldn’t find the problem to fix it.
There’s below a part form the code with the main functions in this problem:
void MDB_Setup() {
// Set baud rate with setbaud.h
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
// Disable USART rate doubler (arduino bootloader leaves it enabled...)
UCSR0A &= ~(1 << U2X0);
// Set 9600-9-N-1 UART mode
UCSR0C = (0<<UMSEL01)|(0<<UMSEL00)|(0<<UPM01)|(0<<UPM00)|(0<<USBS0)|(1<<UCSZ01)|(1<<UCSZ00);
UCSR0B |= (1<<UCSZ02); // 9bit
// Enable rx/tx
UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
}
//Poll FUNCTION:
void PollDevice(byte devaddrbyte){
struct MDB_Byte addrbyte;
coin_read_value=true;
rcvcomplete = 0;
int addrtx = 0;
addrbyte.data = devaddrbyte;
addrbyte.mode = 0x01;
memcpy(&addrtx, &addrbyte, 2);
MDB_write(addrtx);
MDB_write(addrbyte.data);
processresponse(addrbyte.data & ADDRESS_MASK);
coin_read_value=false;
}
// Process response
void processresponse(int addr){
mdboverflow = 0;
rcvcomplete = 0;
while (!rcvcomplete){
MDB_read();
}
if ((rcvcomplete) && (!mdboverflow)){
if (MDB_BUFFER_COUNT > 1){
MDB_write(0x00); // Enviar ACK al dispositivo MDB si la respuesta periférica no es solo un *ACK*, de lo contrario, el periférico intentará enviar datos no confirmados con los próximos comandos de "poll"
Serial.print("ACK Sent");
} else {
if (MDB_BUFFER_COUNT == 1){
// Solo se recibió un *ACK* del dispositivo periférico, no se necesita confirmación
Serial.print("ACK");
}
}
}
for(uint8_t i = 0; i < MDB_BUFFER_COUNT; i++) // Corrección aquí
{
Serial.print("Response Data: ");
Serial.println(MDB_BUFFER[i].data, HEX);
}
Serial.println();
}
// MDB Send function
void MDB_Send(byte UART_BUFFER[37],int UART_BUFFER_COUNT){
//command seems valid, let's try to send it to peripheral
struct MDB_Byte AddressByte;
int addrtx = 0;
AddressByte.data = UART_BUFFER[0];
AddressByte.mode = 0x01;
memcpy(&addrtx, &AddressByte, 2);
MDB_write(addrtx);
for (int i = 1; i < UART_BUFFER_COUNT; i++){
MDB_write(UART_BUFFER[i]);
}
processresponse(UART_BUFFER[0] & ADDRESS_MASK);
}
void MDB_write(int data) {
struct MDB_Byte b;
memcpy(&b, &data, 2);
write_9bit(b);
}
int MDB_Receive() {
unsigned char resh, resl;
char tmpstr[64];
int rtr = 0;
// Wait for data to be received
while ((!(UCSR0A & (1<<RXC0))) and rtr < 50) {
delay(1);
rtr++;
}
if (rtr == 50){
mdboverflow = 1;
rcvcomplete = 1;
}
// Get 9th bit, then data from buffer
resh = UCSR0B;
resl = UDR0;
// Filter the 9th bit, then return only data wo mode bit
resh = (resh >> 1) & 0x01;
return ((resh << 8) | resl);
}
void MDB_getByte(struct MDB_Byte* mdbb) {
int b;
b = 0;
b = MDB_Receive();
memcpy (mdbb, &b, 2);
}
byte MDB_ChecksumValidate() {
int sum = 0;
for (int i=0; i < (MDB_BUFFER_COUNT-1); i++)
sum += MDB_BUFFER[i].data;
if (MDB_BUFFER[MDB_BUFFER_COUNT-1].data == (sum & 0xFF))
return 1;
else
return 0;
}
// Cashless loop
void Cashless_Device()
{
if (millis() - temp_poll > 150)
{
temp_poll = millis();
PollDevice(0x12);
MDBFlush();
}
}
And thank you in advence.
I’m tring to get the poll request or the poll response but nothing
Abdelhak El Alaoui is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.